#!/bin/bash # disable errors regarding androot.source as # it is created and loaded at runtime # shellcheck disable=SC1091 ### TOBECHANGED # disables unreachable code warnings # shellcheck disable=SC2317 ### TOBECHANGED_END # check for root user if [ ! "${UID}" == "0" ]; then echo ":: Error: Not running as root user" exit 1 fi # determine $TMPDIR if [ ! -d "${TMPDIR}" ]; then if [ -d "/tmp" ]; then export "TMPDIR=/tmp/androot" elif [ -d "/data/tmp" ]; then export "TMPDIR=/data/tmp/androot" else echo ":: Error: \$TMPDIR could not be determined" exit 1 fi fi # ... and create it mkdir -p "${TMPDIR}" # write source file cat << EOF > "${TMPDIR}/androot.source" # Functions ## Indicate failure function indicate_fail() { echo -e "\r\e[0m[\e[0;31mFAIL\e[0m]" } ## Indicate success function indicate_ok() { echo -e "\r\e[0m[\e[0;32m OK \e[0m]" } ## Indicate running execution function indicate_exec() { echo -ne "\e[0m[\e[0;34m....\e[0m] \${*}" } ## Log diagnostic message to term function log_diag() { if [ "\$DIAG" == "true" ]; then echo -e "\e[0m[\e[0;35mDIAG\e[0m] \${*}" fi } ## Log informational message to term function log_info() { echo -e "\r\e[0m[\e[0;32mINFO\e[0m] \${*}" } ## Log warning message to term function log_warn() { echo -e "\r\e[0m[\e[0;33mWARN\e[0m] \${*}" } ## Log error message to term function log_error() { echo -e "\r\e[0m[\e[0;31mERR!\e[0m] \${*}" } ## Log message to log file 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} } ## Ask a question function log_ask() { echo -ne "\e[0m[\e[0;36mASKQ\e[0m] \${*}" read -r ANSWER } ## Ask for password function log_askpasswd() { echo -ne "\e[0m[\e[0;36mASKP\e[0m] \${*}" read -rs ANSWER echo "" } ## Ask for yes or no (agreement) 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 } # 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 export "BRANCH=develop" ## unsafe commits list url export "UNSAFE_COMMITS_LIST=https://fs.staropensource.de/vinf/unsafe/androot-\${BRANCH}" # Download URLs ## rootfs archives export "DOWNLOADSERVER_ROOTFS=https://fs.staropensource.de/rootfs/" ## qemu-static archives export "DOWNLOADSERVER_QEMUSTATIC=https://fs.staropensource.de/qemu-static/" ## bootscripts repository export "DOWNLOADSERVER_BOOTSCRIPTS=https://git.staropensource.de/StarOpenSource/androot.git" ## installer scripts url export "DOWNLOADSERVER_RAW=https://git.staropensource.de/StarOpenSource/androot/raw/branch/\${BRANCH}/" # Function variables ## get architecture case "$(uname -m)" in # 64-bit architectures (supported) x86_64|amd64) export "ARCH=x86_64" ;; aarch64|aarch64_be|armv8b|armv8l) export "ARCH=arm64" ;; ppc64|ppc64le) export "ARCH=powerpc64" ;; mips64) export "ARCH=mips64" ;; # 32-bit architectures (unsupported) x86|i386|i686) export "ARCH=x86" ;; arm) export "ARCH=arm" ;; powerpc|ppc|ppcle) export "ARCH=powerpc" ;; mips) export "ARCH=mips" ;; *) export "ARCH=unknown" ;; esac ## check if androot is running on android if [ -d "/system" ] && [ -d "/data" ] && [ -d "/data/data" ] && [ ! -d "/home" ] && [ ! -d "/root" ]; then export "IS_ANDROID=true" else export "IS_ANDROID=false" fi EOF # display banner 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 \\/_/\\/_/\\/_/\\/_/\\/___/ \\/_/\\/ /\\/_____/\\/_____/ \\/_/" # load source file source "${TMPDIR}/androot.source" # 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}" log_write "download_server_rootfs ${DOWNLOADSERVER_ROOTFS}" log_write "download_server_qemustatic ${DOWNLOADSERVER_QEMUSTATIC}" log_write "download_server_bootscripts ${DOWNLOADSERVER_BOOTSCRIPTS}" log_write "args ${*}" log_write "diag ${DIAG}" log_write "#### System information" # print diagnostic messages log_diag "Diagnostic mode enabled" log_diag "Arguments: ${*}" # check for supported architecture 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 # run a androot script and exit if failed function run_script() { # $@ is used intentionally here, so ignore error # shellcheck disable=SC2068 if ! $@; then exit 1 fi } case "${1}" in "--local") # use scripts from cwd 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 exit 0 run_script ./installsystem.sh --configure run_script ./installsystem.sh --update run_script ./patch.sh run_script ./mount.sh --unmount run_script ./finish.sh ;; "--download") # download scripts from the interwebz and execute them log_diag "Using download mode" indicate_exec "Downloading files" indicate_fail log_error "Unimplemented." exit 1 ;; "--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:" log_info "DIAG [displays diagnostic messages, true/false] ALLOW_SHM [allows using /dev/shm as a location, true/false]" ;; *) log_diag "i thought putting a little \"advertisement parody\" in here would be funny" 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!" ;; esac