2023-11-07 17:23:39 +01:00
#!/bin/bash
2023-11-08 19:47:37 +01:00
# disable errors regarding androot.source as
# it is created and loaded at runtime
# shellcheck disable=SC1091
2023-11-07 17:23:39 +01:00
### TOBECHANGED
2023-11-08 19:47:37 +01:00
# disables unreachable code warnings
2023-11-07 17:23:39 +01:00
# shellcheck disable=SC2317
### TOBECHANGED_END
2023-11-08 19:47:37 +01:00
# check for root user
2023-11-07 17:23:39 +01:00
if [ ! " ${ UID } " = = "0" ] ; then
echo ":: Error: Not running as root user"
exit 1
fi
2023-11-08 19:47:37 +01:00
# determine $TMPDIR
2023-11-07 17:23:39 +01:00
if [ ! -d " ${ TMPDIR } " ] ; then
if [ -d "/tmp" ] ; then
2023-11-08 19:47:37 +01:00
export "TMPDIR=/tmp/androot"
2023-11-07 17:23:39 +01:00
elif [ -d "/data/tmp" ] ; then
2023-11-08 19:47:37 +01:00
export "TMPDIR=/data/tmp/androot"
2023-11-07 17:23:39 +01:00
else
echo ":: Error: \$TMPDIR could not be determined"
exit 1
fi
fi
2023-11-08 19:47:37 +01:00
# ... and create it
2023-11-07 17:23:39 +01:00
mkdir -p " ${ TMPDIR } "
2023-11-08 19:47:37 +01:00
# write source file
2023-11-07 17:23:39 +01:00
cat << EOF > " ${ TMPDIR } /androot.source "
# Functions
2023-11-10 15:08:35 +01:00
## indicate failure
2023-11-08 19:47:37 +01:00
function indicate_fail( ) {
2023-11-07 17:23:39 +01:00
echo -e "\r\e[0m[\e[0;31mFAIL\e[0m]"
}
2023-11-10 15:08:35 +01:00
## indicate success
2023-11-08 19:47:37 +01:00
function indicate_ok( ) {
2023-11-07 17:23:39 +01:00
echo -e "\r\e[0m[\e[0;32m OK \e[0m]"
}
2023-11-10 15:08:35 +01:00
## indicate running execution
2023-11-08 19:47:37 +01:00
function indicate_exec( ) {
2023-11-07 17:23:39 +01:00
echo -ne "\e[0m[\e[0;34m....\e[0m] \${*}"
}
2023-11-10 15:08:35 +01:00
## log diagnostic message to term
2023-11-07 17:23:39 +01:00
function log_diag( ) {
2023-11-08 19:47:37 +01:00
if [ "\$DIAG" = = "true" ] ; then
echo -e "\e[0m[\e[0;35mDIAG\e[0m] \${*}"
fi
2023-11-07 17:23:39 +01:00
}
2023-11-10 15:08:35 +01:00
## log informational message to term
2023-11-07 17:23:39 +01:00
function log_info( ) {
echo -e "\r\e[0m[\e[0;32mINFO\e[0m] \${*}"
}
2023-11-10 15:08:35 +01:00
## log warning message to term
2023-11-07 17:23:39 +01:00
function log_warn( ) {
echo -e "\r\e[0m[\e[0;33mWARN\e[0m] \${*}"
}
2023-11-10 15:08:35 +01:00
## log error message to term
2023-11-07 17:23:39 +01:00
function log_error( ) {
echo -e "\r\e[0m[\e[0;31mERR!\e[0m] \${*}"
}
2023-11-10 15:08:35 +01:00
## log message to log file
2023-11-08 19:47:37 +01:00
function log_write( ) {
echo -e "\${*}" & >> "\${TMPDIR}/androot.log"
}
function log_execute( ) {
log_write ">>>> \${*}"
\$ { *} & >> "\${TMPDIR}/androot.log"
EXITCODE = \$ { ?}
log_write "Exited with code \${EXITCODE}"
return \$ { EXITCODE}
}
2023-11-10 15:08:35 +01:00
## ask a question
2023-11-07 17:23:39 +01:00
function log_ask( ) {
echo -ne "\e[0m[\e[0;36mASKQ\e[0m] \${*}"
read -r ANSWER
}
2023-11-10 15:08:35 +01:00
## ask for password
2023-11-07 17:23:39 +01:00
function log_askpasswd( ) {
echo -ne "\e[0m[\e[0;36mASKP\e[0m] \${*}"
read -rs ANSWER
echo ""
}
2023-11-10 15:08:35 +01:00
## ask for yes or no (agreement)
2023-11-07 17:23:39 +01:00
function log_askyn( ) {
if [ -z "\${2}" ] ; then
log_error "log_askyn requires at least two arguments"
exit 1
fi
export "ANSWER_FALLBACK=\${1}"
shift
echo -ne "\e[0m[\e[0;36mASKA\e[0m] \${*}"
read -r ANSWER
if [ "\${ANSWER,,}" = = "y" ] || [ "\${ANSWER,,}" = = "yes" ] || [ "\${ANSWER,,}" = = "true" ] || [ "\${ANSWER}" = = "" ] ; then
export "ANSWER=true"
elif [ "\${ANSWER,,}" = = "n" ] || [ "\${ANSWER,,}" = = "no" ] || [ "\${ANSWER,,}" = = "false" ] ; then
export "ANSWER=false"
else
export "ANSWER=\$ANSWER_FALLBACK"
fi
}
2023-11-10 15:08:35 +01:00
## chroot into rootfs
function chroot_env( ) {
CHROOTDIR = \$ { 1}
shift
log_execute env LD_PRELOAD = chroot "\${CHROOTDIR}" env TMPDIR = /tmp PATH = /usr/sbin:/usr/sbin/vendor_perl:/usr/local/sbin:/usr/local/sbin/vendor_perl:/usr/bin:/usr/bin/vendor_perl:/usr/local/bin:/usr/local/bin/vendor_perl:/usr/local/games ANDROID_ROOT = ANDROID_DATA = PREFIX = \$ { @}
return ${ ? }
}
2023-11-07 17:23:39 +01:00
2023-11-08 19:47:37 +01:00
# Language
## set language to C, useful for bug reports
export "LANG=C.UTF-8"
export "LANGUAGE=\${LANG}"
export "LC_ALL=\${LANG}"
export "LC_CTYPE=\${LANG}"
export "LC_NUMERIC=\${LANG}"
export "LC_TIME=\${LANG}"
export "LC_COLLATE=\${LANG}"
export "LC_MONETARY=\${LANG}"
export "LC_MESSAGES=\${LANG}"
export "LC_PAPER=\${LANG}"
export "LC_NAME=\${LANG}"
export "LC_ADDRESS=\${LANG}"
export "LC_TELEPHONE=\${LANG}"
export "LC_MEASUREMENT=\${LANG}"
export "LC_IDENTIFICATION=\${LANG}"
# Variables
## diagnostic mode
export " DIAG= ${ DIAG } "
## allow /dev/shm setting
export " ALLOW_SHM= ${ ALLOW_SHM } "
## temporary directory
export " TMPDIR= ${ TMPDIR } "
## androot installer branch
2023-11-07 20:54:57 +01:00
export "BRANCH=develop"
2023-11-08 19:47:37 +01:00
## unsafe commits list url
export "UNSAFE_COMMITS_LIST=https://fs.staropensource.de/vinf/unsafe/androot-\${BRANCH}"
# Download URLs
## rootfs archives
2023-11-10 15:08:35 +01:00
export "DOWNLOADSERVER=https://fs.staropensource.de/androot"
2023-11-08 19:47:37 +01:00
## bootscripts repository
2023-11-07 20:54:57 +01:00
export "DOWNLOADSERVER_BOOTSCRIPTS=https://git.staropensource.de/StarOpenSource/androot.git"
2023-11-08 19:47:37 +01:00
## installer scripts url
2023-11-10 15:08:35 +01:00
export "DOWNLOADSERVER_RAW=https://git.staropensource.de/StarOpenSource/androot/raw/branch/\${BRANCH}"
2023-11-08 19:47:37 +01:00
# Function variables
## get architecture
2023-11-07 17:23:39 +01:00
case " $( uname -m) " in
# 64-bit architectures (supported)
x86_64| amd64)
2023-11-08 19:47:37 +01:00
export "ARCH=x86_64" ; ;
2023-11-07 17:23:39 +01:00
aarch64| aarch64_be| armv8b| armv8l)
2023-11-08 19:47:37 +01:00
export "ARCH=arm64" ; ;
2023-11-07 17:23:39 +01:00
ppc64| ppc64le)
2023-11-08 19:47:37 +01:00
export "ARCH=powerpc64" ; ;
2023-11-07 17:23:39 +01:00
mips64)
2023-11-08 19:47:37 +01:00
export "ARCH=mips64" ; ;
2023-11-07 17:23:39 +01:00
# 32-bit architectures (unsupported)
x86| i386| i686)
2023-11-08 19:47:37 +01:00
export "ARCH=x86" ; ;
2023-11-07 17:23:39 +01:00
arm)
2023-11-08 19:47:37 +01:00
export "ARCH=arm" ; ;
2023-11-07 17:23:39 +01:00
powerpc| ppc| ppcle)
2023-11-08 19:47:37 +01:00
export "ARCH=powerpc" ; ;
2023-11-07 17:23:39 +01:00
mips)
2023-11-08 19:47:37 +01:00
export "ARCH=mips" ; ;
2023-11-07 17:23:39 +01:00
*)
2023-11-08 19:47:37 +01:00
export "ARCH=unknown" ; ;
2023-11-07 17:23:39 +01:00
esac
2023-11-08 19:47:37 +01:00
## check if androot is running on android
2023-11-07 17:23:39 +01:00
if [ -d "/system" ] && [ -d "/data" ] && [ -d "/data/data" ] && [ ! -d "/home" ] && [ ! -d "/root" ] ; then
export "IS_ANDROID=true"
else
export "IS_ANDROID=false"
fi
EOF
2023-11-08 19:47:37 +01:00
# display banner
2023-11-07 17:23:39 +01:00
echo -e "\e[0;33m ______ __ __ ____ ____ _____ _____ ______"
echo -e "\e[0;33m/\\ _ \\/\\ \\/\\ \\/\\ _\`\\ /\\ _\`\\ /\\ __\`\\/\\ __\`\\/\\__ _\\"
echo -e "\e[0;33m\\ \\ \\L\\ \\ \\ \`\\\\ \\ \\ \\/\\ \\ \\ \\L\\ \\ \\ \\/\\ \\ \\ \\/\\ \\/_/\\ \\/"
echo -e "\e[0;33m \\ \\ __ \\ \\ , \` \\ \\ \\ \\ \\ \\ , /\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\"
echo -e "\e[0;33m \\ \\ \\/\\ \\ \\ \\\`\\ \\ \\ \\_\\ \\ \\ \\\\ \\\\ \\ \\_\\ \\ \\ \\_\\ \\ \\ \\ \\"
echo -e "\e[0;33m \\ \\_\\ \\_\\ \\_\\ \\_\\ \\____/\\ \\_\\ \\_\\ \\_____\\ \\_____\\ \\ \\_\\"
echo -e "\e[0;33m \\/_/\\/_/\\/_/\\/_/\\/___/ \\/_/\\/ /\\/_____/\\/_____/ \\/_/"
2023-11-08 19:47:37 +01:00
# load source file
2023-11-07 17:23:39 +01:00
source " ${ TMPDIR } /androot.source "
2023-11-08 19:47:37 +01:00
# clear/create log file
## if in diagnostic mode, print newlines
## makes reading the log file much
## easier while using "make log"
if [ " ${ DIAG } " = = "true" ] ; then log_write "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ; fi
log_write "#### System information"
log_write " architecture ${ ARCH } "
log_write " is_android ${ IS_ANDROID } "
2023-11-10 15:08:35 +01:00
log_write " download_server ${ DOWNLOADSERVER } "
2023-11-08 19:47:37 +01:00
log_write " download_server_bootscripts ${ DOWNLOADSERVER_BOOTSCRIPTS } "
2023-11-10 15:08:35 +01:00
log_write " download_server_raw ${ DOWNLOADSERVER_RAW } "
2023-11-08 19:47:37 +01:00
log_write " args ${ * } "
log_write " diag ${ DIAG } "
log_write "#### System information"
2023-11-07 17:23:39 +01:00
2023-11-08 19:47:37 +01:00
# print diagnostic messages
2023-11-07 17:23:39 +01:00
log_diag "Diagnostic mode enabled"
log_diag " Arguments: ${ * } "
2023-11-08 19:47:37 +01:00
# check for supported architecture
2023-11-07 17:23:39 +01:00
case " ${ ARCH } " in
"unknown" )
log_error "androot failed to detect your architecture. If you believe this is a bug, create a issue at \"https://git.staropensource.de/StarOpenSource/androot\"."
exit 1
; ;
"x86" | "arm" | "powerpc" | "mips" )
log_error "androot does not support legacy 32-bit systems, please use a 64-bit system instead."
exit 1
; ;
esac
2023-11-08 19:47:37 +01:00
# run a androot script and exit if failed
2023-11-07 20:54:57 +01:00
function run_script( ) {
2023-11-08 19:47:37 +01:00
# $@ is used intentionally here, so ignore error
# shellcheck disable=SC2068
if ! $@ ; then
2023-11-07 20:54:57 +01:00
exit 1
fi
}
case " ${ 1 } " in
"--local" )
2023-11-08 19:47:37 +01:00
# use scripts from cwd
2023-11-07 20:54:57 +01:00
log_diag "Using local mode"
run_script ./prepare.sh
run_script ./rootfsinstall.sh --download
run_script ./rootfsinstall.sh --decompress
run_script ./mount.sh --mount
run_script ./bootscriptdl.sh --download
run_script ./bootscriptdl.sh --configure
run_script ./bootscriptdl.sh --install-qemu
2023-11-10 15:08:35 +01:00
run_script ./systeminstall.sh --configure
run_script ./systeminstall.sh --update
2023-11-07 20:54:57 +01:00
run_script ./patch.sh
2023-11-10 15:08:35 +01:00
exit 0
2023-11-07 20:54:57 +01:00
run_script ./mount.sh --unmount
2023-11-08 19:47:37 +01:00
run_script ./finish.sh
; ;
2023-11-07 20:54:57 +01:00
"--download" )
2023-11-08 19:47:37 +01:00
# download scripts from the interwebz and execute them
2023-11-07 20:54:57 +01:00
log_diag "Using download mode"
2023-11-08 19:47:37 +01:00
indicate_exec "Downloading files"
indicate_fail
log_error "Unimplemented."
exit 1
; ;
2023-11-07 20:54:57 +01:00
"--help" | "-h" )
log_diag "Displaying help"
log_info "Available arguments:"
log_info "--local [execute androot from cwd] --download [download androot scripts and execute] --help [display args and vars]"
log_info "Available environment variables:"
2023-11-08 19:47:37 +01:00
log_info "DIAG [displays diagnostic messages, true/false] ALLOW_SHM [allows using /dev/shm as a location, true/false]"
; ;
2023-11-07 20:54:57 +01:00
*)
log_diag "i thought putting a little \"advertisement parody\" in here would be funny"
2023-11-08 19:47:37 +01:00
log_error "StarOpenSource is happy to present the latest and greatest version of --help! --help now uses cutting edge technology to display the most useful help to you, and that for only zero dollars!"
; ;
2023-11-07 20:54:57 +01:00
esac