diff --git a/Makefile b/Makefile index 7667836..2eed20c 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,6 @@ ensureexec: run: ensureexec check sudo ./androot.sh --local test: ensureexec check - sudo env DIAG=true ./androot.sh --local + sudo env ALLOW_SHM=true DIAG=true ./androot.sh --local log: @PS4='';if [ -d "/tmp/androot" ]; then set -x; tail -f /tmp/androot/androot.log; elif [ -d "/data/tmp/androot" ]; then set -x; tail -f /data/tmp/androot/androot.log; else echo ":: Error: androot's log directory could not be determined (start androot first)"; exit 1; fi diff --git a/README.md b/README.md index b2dbee5..74357fc 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,5 @@ use */dev/shm* instead of */tmp* as your install location (*/tmp* uses your disk # Annotations ```plain ### TOBECHANGED - this should be changed in the future -### UNIMPLEMENTED - not yet finished -### EXPERIMENTAL - experimental code, probably not safe yet ### MISIMPLEMENTED - implemented, but wrong ``` \ No newline at end of file diff --git a/androot.sh b/androot.sh index a499cf4..85a5178 100755 --- a/androot.sh +++ b/androot.sh @@ -1,60 +1,76 @@ #!/bin/bash -# shellcheck disable=SC2181 disable=SC1091 disable=SC2236 -# shellcheck disable=SC2068 +# 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 if root +# check for root user if [ ! "${UID}" == "0" ]; then echo ":: Error: Not running as root user" exit 1 fi -# Determine $TMPDIR +# determine $TMPDIR if [ ! -d "${TMPDIR}" ]; then if [ -d "/tmp" ]; then - export "TMPDIR=/tmp/androot/" + export "TMPDIR=/tmp/androot" elif [ -d "/data/tmp" ]; then - export "TMPDIR=/data/tmp/androot/" + 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 +# write source file cat << EOF > "${TMPDIR}/androot.source" # Functions ## Indicate failure -function log_fail() { +function indicate_fail() { echo -e "\r\e[0m[\e[0;31mFAIL\e[0m]" } ## Indicate success -function log_ok() { +function indicate_ok() { echo -e "\r\e[0m[\e[0;32m OK \e[0m]" } ## Indicate running execution -function log_exec() { +function indicate_exec() { echo -ne "\e[0m[\e[0;34m....\e[0m] \${*}" } -## Diagnostic logging +## Log diagnostic message to term function log_diag() { - if [ "\$DIAG" == "true" ]; then echo -e "\e[0m[\e[0;35mDIAG\e[0m] \${*}"; fi + if [ "\$DIAG" == "true" ]; then + echo -e "\e[0m[\e[0;35mDIAG\e[0m] \${*}" + fi } -## Informational logging +## Log informational message to term function log_info() { echo -e "\r\e[0m[\e[0;32mINFO\e[0m] \${*}" } -## Warning logging +## Log warning message to term function log_warn() { echo -e "\r\e[0m[\e[0;33mWARN\e[0m] \${*}" } -## Error logging +## 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] \${*}" @@ -85,40 +101,72 @@ function log_askyn() { fi } -# Global variables -## $BRANCH +# 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" -## $DOWNLOADSERVER_ROOTFS +## 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/" -## $DOWNLOADSERVER_QEMUSTATIC +## qemu-static archives export "DOWNLOADSERVER_QEMUSTATIC=https://fs.staropensource.de/qemu-static/" -## $DOWNLOADSERVER_BOOTSCRIPTS +## bootscripts repository export "DOWNLOADSERVER_BOOTSCRIPTS=https://git.staropensource.de/StarOpenSource/androot.git" -## $ARCH +## 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";; + export "ARCH=x86_64" ;; aarch64|aarch64_be|armv8b|armv8l) - export "ARCH=arm64";; + export "ARCH=arm64" ;; ppc64|ppc64le) - export "ARCH=powerpc64";; + export "ARCH=powerpc64" ;; mips64) - export "ARCH=mips64";; + export "ARCH=mips64" ;; # 32-bit architectures (unsupported) x86|i386|i686) - export "ARCH=x86";; + export "ARCH=x86" ;; arm) - export "ARCH=arm";; + export "ARCH=arm" ;; powerpc|ppc|ppcle) - export "ARCH=powerpc";; + export "ARCH=powerpc" ;; mips) - export "ARCH=mips";; + export "ARCH=mips" ;; *) - export "ARCH=unknown";; + export "ARCH=unknown" ;; esac -## $IS_ANDROID +## 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 @@ -126,7 +174,7 @@ else fi EOF -# Display banner +# display banner echo -e "\e[0;33m ______ __ __ ____ ____ _____ _____ ______" echo -e "\e[0;33m/\\ _ \\/\\ \\/\\ \\/\\ _\`\\ /\\ _\`\\ /\\ __\`\\/\\ __\`\\/\\__ _\\" echo -e "\e[0;33m\\ \\ \\L\\ \\ \\ \`\\\\ \\ \\ \\/\\ \\ \\ \\L\\ \\ \\ \\/\\ \\ \\ \\/\\ \\/_/\\ \\/" @@ -135,31 +183,29 @@ echo -e "\e[0;33m \\ \\ \\/\\ \\ \\ \\\`\\ \\ \\ \\_\\ \\ \\ \\\\ \\\\ \\ \\_\\ echo -e "\e[0;33m \\ \\_\\ \\_\\ \\_\\ \\_\\ \\____/\\ \\_\\ \\_\\ \\_____\\ \\_____\\ \\ \\_\\" echo -e "\e[0;33m \\/_/\\/_/\\/_/\\/_/\\/___/ \\/_/\\/ /\\/_____/\\/_____/ \\/_/" -# Load source file +# load source file source "${TMPDIR}/androot.source" -# Clear/create log file -{ - # if in diagnostic mode, print newlines - ## reading the log output using tail during - ## development with this is so much better, believe me - if [ "${DIAG}" == "true" ]; then echo -e "\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 - echo "#### System information" - echo "architecture ${ARCH}" - echo "is_android ${IS_ANDROID}" - echo "download_server_rootfs ${DOWNLOADSERVER_ROOTFS}" - echo "download_server_qemustatic ${DOWNLOADSERVER_QEMUSTATIC}" - echo "download_server_bootscripts ${DOWNLOADSERVER_BOOTSCRIPTS}" - echo "args ${*}" - echo "diag ${DIAG}" - echo "#### System information" -} &> "${TMPDIR}/androot.log" +# 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" -# Diagnostic mode +# print diagnostic messages log_diag "Diagnostic mode enabled" log_diag "Arguments: ${*}" -# Check architecture +# 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\"." @@ -171,15 +217,18 @@ case "${ARCH}" in ;; esac +# run a androot script and exit if failed function run_script() { - env "TMPDIR=${TMPDIR}" $@ - if [ ! "${?}" == "0" ]; then + # $@ 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 @@ -193,21 +242,25 @@ case "${1}" in run_script ./installsystem.sh --update run_script ./patch.sh run_script ./mount.sh --unmount - run_script ./finish.sh;; + run_script ./finish.sh + ;; "--download") + # download scripts from the interwebz and execute them log_diag "Using download mode" - ### UNIMPLEMENTED - log_exec Downloading files - log_fail - exit 1;; - ### UNIMPLEMENTED_END + 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_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!";; + 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 diff --git a/bootscriptdl.sh b/bootscriptdl.sh index 395310f..7894420 100755 --- a/bootscriptdl.sh +++ b/bootscriptdl.sh @@ -1,5 +1,7 @@ #!/bin/bash -# shellcheck disable=SC2181 disable=SC1091 disable=SC2236 +# disable errors regarding androot.source as +# it is created and loaded at runtime +# shellcheck disable=SC1091 source "${TMPDIR}/androot.source" source "${TMPDIR}/androot.env" @@ -8,49 +10,50 @@ log_diag "rootfsinstall is now executing, with arguments \"${*}\"" case "${1}" in "--download") log_diag "Using download mode" - log_exec "Downloading bootscripts" - echo "#### download bootscripts repository" &>> "${TMPDIR}/androot.log" - git clone --quiet --verbose -b "${BRANCH}-bootscripts" "${DOWNLOADSERVER_BOOTSCRIPTS}" "${LOCATION}/bootscripts" &>> "${TMPDIR}/androot.log" - if [ ! "${?}" == "0" ]; then - log_fail + indicate_exec "Downloading bootscripts" + log_write "#### download bootscripts repository" + if ! log_execute git clone --quiet --verbose -b "${BRANCH}-bootscripts" "${DOWNLOADSERVER_BOOTSCRIPTS}" "${LOCATION}/bootscripts"; then + indicate_fail exit 1 fi - log_ok;; + indicate_ok + ;; "--configure") log_diag "Using configure mode" - log_exec "Configuring bootscript scripts" - cd "${LOCATION}/bootscripts/"||{ log_error "cd failed";exit 1; } - echo "#### writing bootscripts config.env" &>> "${TMPDIR}/androot.log" + indicate_exec "Configuring bootscript scripts" + log_execute cd "${LOCATION}/bootscripts/" ||{ indicate_fail; exit 1; } + log_write "#### writing bootscripts config.env" cat << EOF >> "${LOCATION}/bootscripts/config.env" COMMIT=$(git rev-parse HEAD) LOCATION=${LOCATION} +ARCHITECTURE=${ARCH_TARGET} IS_ANDROID=${IS_ANDROID} EOF - log_ok;; + indicate_ok + ;; "--install-qemu") log_diag "Using install-qemu mode" for ARCH_DOWNLOAD in ${ARCH_EXECUTORS}; do - log_exec "Installing qemu-static for ${ARCH_DOWNLOAD}" - echo "#### download qemu-static for ${ARCH_DOWNLOAD}" &>> "${TMPDIR}/androot.log" - wget "${DOWNLOADSERVER_QEMUSTATIC}${ARCH_DOWNLOAD}.tar.gz" -qqq -O "${TMPDIR}/${ARCH_DOWNLOAD}.tar.gz" &>> "${TMPDIR}/androot.log" - if [ ! "${?}" == "0" ]; then - log_fail; + indicate_exec "Installing qemu-static for ${ARCH_DOWNLOAD}" + log_write "#### download qemu-static for ${ARCH_DOWNLOAD}" + if ! log_execute wget "${DOWNLOADSERVER_QEMUSTATIC}${ARCH_DOWNLOAD}.tar.gz" --no-verbose -O "${TMPDIR}/${ARCH_DOWNLOAD}.tar.gz"; then + indicate_fail; exit 1 fi - echo "#### extract qemu-static for ${ARCH_DOWNLOAD}" &>> "${TMPDIR}/androot.log" - mkdir -p "${LOCATION}/bootscripts/qemu-static/${ARCH_DOWNLOAD}" - if [ ! "${?}" == "0" ]; then - log_fail; + log_write "#### extract qemu-static for ${ARCH_DOWNLOAD}" + if ! log_execute mkdir -p "${LOCATION}/bootscripts/qemu-static/${ARCH_DOWNLOAD}"; then + indicate_fail; exit 1 fi - bsdtar -xf "${TMPDIR}/${ARCH_DOWNLOAD}.tar.gz" -C "${LOCATION}/bootscripts/qemu-static/${ARCH_DOWNLOAD}/" &>> "${TMPDIR}/andronix.log" - if [ ! "${?}" == "0" ]; then - log_fail; + if ! log_execute bsdtar -xf "${TMPDIR}/${ARCH_DOWNLOAD}.tar.gz" -C "${LOCATION}/bootscripts/qemu-static/${ARCH_DOWNLOAD}/"; then + indicate_fail; exit 1 fi - log_ok - done;; + indicate_ok + done + ;; *) log_error "--download or --decompress required" - exit 1;; + exit 1 + ;; esac \ No newline at end of file diff --git a/mount.sh b/mount.sh index e156872..d9bdb9d 100755 --- a/mount.sh +++ b/mount.sh @@ -1,26 +1,27 @@ #!/bin/bash -# shellcheck disable=SC2181 disable=SC1091 disable=SC2236 -# shellcheck disable=SC2068 +# disable errors regarding androot.source as +# it is created and loaded at runtime +# shellcheck disable=SC1091 source "${TMPDIR}/androot.source" source "${TMPDIR}/androot.env" log_diag "mount is now executing, with arguments \"${*}\"" -function mount_fail() { - echo "#### mount ${1}" &>> "${TMPDIR}/androot.log" - shift - mount ${@} &>> "${TMPDIR}/androot.log" - if [ ! "${?}" == "0" ]; then - log_fail +# to avoid repetition +function mountf() { + # $@ is used intentionally here, so ignore error + # shellcheck disable=SC2068 + if ! log_execute mount ${@}; then + indicate_fail exit 1 fi } -function unmount_fail() { - echo "#### unmount ${1}" &>> "${TMPDIR}/androot.log" - shift - umount ${@} &>> "${TMPDIR}/androot.log" - if [ ! "${?}" == "0" ]; then - log_fail +# to avoid repetition +function umountf() { + # $@ is used intentionally here, so ignore error + # shellcheck disable=SC2068 + if ! log_execute umount ${@}; then + indicate_fail exit 1 fi } @@ -29,32 +30,39 @@ case "${1}" in "--mount") log_diag "Using mount mode" mkdir -p "${LOCATION}/mountdir" + # remount /data on android to enable + # suid and exec flags if [ "${IS_ANDROID}" == "true" ]; then - log_exec "Remounting /data" + indicate_exec "Remounting /data" mount_fail "/data (remount)" "/data" -o remount,suid,exec - log_ok + indicate_ok fi - log_exec "Mounting rootfs" - mount_fail "rootfs" --bind "${LOCATION}/rootfs" "${LOCATION}/mountdir" -o rw,suid,dev,exec,auto,nouser,async - log_ok - log_exec "Binding directories" - mount_fail "/dev" --bind "/dev" "${LOCATION}/mountdir/dev" - mount_fail "/dev/pts" --bind "/dev/pts" "${LOCATION}/mountdir/dev/pts" - mount_fail "/sys" --bind "/sys" "${LOCATION}/mountdir/sys" - mount_fail "/proc" --bind "/proc" "${LOCATION}/mountdir/proc" - log_ok;; + indicate_exec "Mounting rootfs" + mountf --bind "${LOCATION}/rootfs" "${LOCATION}/mountdir" -o rw,suid,dev,exec,auto,nouser,async + indicate_ok + indicate_exec "Binding directories" + # mount /dev BEFORE /dev/pts + mountf --bind "/dev" "${LOCATION}/mountdir/dev" + mountf --bind "/dev/pts" "${LOCATION}/mountdir/dev/pts" + mountf --bind "/sys" "${LOCATION}/mountdir/sys" + mountf --bind "/proc" "${LOCATION}/mountdir/proc" + indicate_ok + ;; "--unmount") log_diag "Using unmount mode" - log_exec "Unmounting binds" - unmount_fail "/dev/pts" "${LOCATION}/mountdir/dev/pts" - unmount_fail "/dev" "${LOCATION}/mountdir/dev" - unmount_fail "/sys" "${LOCATION}/mountdir/sys" - unmount_fail "/proc" "${LOCATION}/mountdir/proc" - log_ok - log_exec "Unmounting rootfs" - unmount_fail "rootfs" "${LOCATION}/mountdir" - log_ok;; + indicate_exec "Unmounting binds" + # unmount /dev AFTER /dev/pts + umountf "${LOCATION}/mountdir/dev/pts" + umountf "${LOCATION}/mountdir/dev" + umountf "${LOCATION}/mountdir/sys" + umountf "${LOCATION}/mountdir/proc" + indicate_ok + indicate_exec "Unmounting rootfs" + umountf "${LOCATION}/mountdir" + indicate_ok + ;; *) log_error "--mount or --unmount required" - exit 1;; + exit 1 + ;; esac \ No newline at end of file diff --git a/prepare.sh b/prepare.sh index 40a289a..e881055 100755 --- a/prepare.sh +++ b/prepare.sh @@ -1,9 +1,12 @@ #!/bin/bash -# shellcheck disable=SC2181 disable=SC1091 disable=SC2236 +# disable errors regarding androot.source as +# it is created and loaded at runtime +# shellcheck disable=SC1091 source "${TMPDIR}/androot.source" log_diag "prepare is now executing, with arguments \"${*}\"" +# ask for target architecture function arch_target() { log_info "" log_info "Please select your target architecture" @@ -18,10 +21,13 @@ function arch_target() { *) log_error "Invalid target architecture \"${ANSWER,,}\", please retry." arch_target - return;; + return + ;; esac echo "ARCH_TARGET=${ANSWER,,}" > "${TMPDIR}/androot.env" } + +# ask for execution architecture(s) function arch_executors() { log_info "" log_info "Please specify the execution architecture(s)" @@ -43,11 +49,14 @@ function arch_executors() { *) log_error "Invalid execution architecture \"${ANSWER,,}\", please retry." arch_executors - return;; + return + ;; esac ### MISIMPLEMENTED echo "ARCH_EXECUTORS=${ANSWER}" >> "${TMPDIR}/androot.env" } + +# ask for target distribution function distribution() { log_info "" log_info "Please select the target distribution" @@ -60,83 +69,100 @@ function distribution() { *) log_error "Invalid distribution \"${ANSWER,,}\", please retry." distribution - return;; + return + ;; esac echo "DISTRIBUTION=${ANSWER,,}" >> "${TMPDIR}/androot.env" } + +# ask for install location function location() { log_info "" - log_info "Please enter the rootfs location" - ### TOBECHANGED - log_info "Note: This location is permanent and cannot be" - log_info " changed as of now." - ### TOBECHANGED_END + log_info "Please enter the install location" + log_info "Note: The installation location is not" + log_info " permanent and you can freely move" + log_info " the rootfs directory around as much" + log_info " as you want." log_ask "Location: " + # check against invalid paths case "${ANSWER}" in - "") + "") # doing nothing is illegal log_error "Please enter something >.<" location - return;; - /tmp*) + return + ;; + /tmp*) # disallow /tmp as disk space issues might haunt us log_error "Using /tmp is unsupported as you may run into disk space issues very quickly, please retry." location - return;; - /dev/shm/*) - if [ ! "${DIAG}" == "true" ]; then + return + ;; + /dev/shm/*) # disallow /dev/shm too, except if ALLOW_SHM is true + if [ ! "${ALLOW_SHM}" == "true" ]; then log_error "Using /dev/shm is unsupported as you may run into disk space issues very quickly, please retry." location return - fi;; - /dev|/proc|/run|/sys|/dev/*|/proc/*|/run/*|/sys/*) + fi + ;; + /dev|/proc|/run|/sys|/dev/*|/proc/*|/run/*|/sys/*) # disallow THESE directories log_error "Are you really trying that?" location - return;; - /) + return + ;; + /) # just do "rm -rf --no-preserve-root /" instead log_error "you're making a recipe for desaster." location - return;; - "uwu") + return + ;; + "uwu"|"owo"|"~nya"|"~ nya"|"~ahh"|"~ ahh") # reference log_error "eww!" location - return;; - "I'd like to interject for a moment") - echo "#### $(whoami) wants to interject for a moment" &>> "${TMPDIR}/androot.log" - log_info "I'd just like to interject for a moment. What you're referring to as Linux," - log_info "is in fact, GNU/Linux, or as I've recently taken to calling it, GNU plus Linux." - log_info "Linux is not an operating system unto itself, but rather another free component" - log_info "of a fully functioning GNU system made useful by the GNU corelibs, shell" - log_info "utilities and vital system components comprising a full OS as defined by POSIX." - log_info "Many computer users run a modified version of the GNU system every day," - log_info "without realizing it. Through a peculiar turn of events, the version of GNU" - log_info "which is widely used today is often called \"Linux\", and many of its users are" - log_info "not aware that it is basically the GNU system, developed by the GNU Project." - log_info "There really is a Linux, and these people are using it, but it is just a" - log_info "part of the system they use. Linux is the kernel: the program in the system" - log_info "that allocates the machine's resources to the other programs that you run." - log_info "The kernel is an essential part of an operating system, but useless by itself;" - log_info "it can only function in the context of a complete operating system. Linux is" - log_info "normally used in combination with the GNU operating system: the whole system" - log_info "is basically GNU with Linux added, or GNU/Linux. All the so-called \"Linux\"" - log_info "distributions are really distributions of GNU/Linux." + return + ;; + "I'd like to interject for a moment") # reference + log_write "#### $(whoami) wants to interject for a moment" + log_error "I'd just like to interject for a moment. What you're referring to as Linux," + log_error "is in fact, GNU/Linux, or as I've recently taken to calling it, GNU plus Linux." + log_error "Linux is not an operating system unto itself, but rather another free component" + log_error "of a fully functioning GNU system made useful by the GNU corelibs, shell" + log_error "utilities and vital system components comprising a full OS as defined by POSIX." + log_error "Many computer users run a modified version of the GNU system every day," + log_error "without realizing it. Through a peculiar turn of events, the version of GNU" + log_error "which is widely used today is often called \"Linux\", and many of its users are" + log_error "not aware that it is basically the GNU system, developed by the GNU Project." + log_error "There really is a Linux, and these people are using it, but it is just a" + log_error "part of the system they use. Linux is the kernel: the program in the system" + log_error "that allocates the machine's resources to the other programs that you run." + log_error "The kernel is an essential part of an operating system, but useless by itself;" + log_error "it can only function in the context of a complete operating system. Linux is" + log_error "normally used in combination with the GNU operating system: the whole system" + log_error "is basically GNU with Linux added, or GNU/Linux. All the so-called \"Linux\"" + log_error "distributions are really distributions of GNU/Linux." location - return;; + return + ;; + "UP UP DOWN DOWN LEFT RIGHT LEFT RIGHT B A START") # reference + log_error "This is a installer script, not a game." + location + return + ;; esac + # checks if [ -a "${ANSWER}" ] && [ ! -d "${ANSWER}" ]; then log_error "The location exists but is not a directory." location return fi if [ -d "${ANSWER}" ]; then - if [ ! -z "$(ls -A "${ANSWER}")" ]; then + if [ -n "$(ls -A "${ANSWER}")" ]; then log_error "The location directory is not empty." location return fi else - log_info "Creating location directory" - mkdir -p "${ANSWER}/rootfs" - if [ ! "${?}" == "0" ]; then - log_fail; + # create directory + indicate_exec "Creating location directory" + if ! mkdir -p "${ANSWER}/rootfs"; then + indicate_fail; exit 1 fi fi @@ -148,9 +174,4 @@ arch_executors distribution location -log_diag "androot.env:\n$(cat "${TMPDIR}/androot.env")" -{ - echo "#### rootfs configuration" - cat "${TMPDIR}/androot.env" - echo "#### rootfs configuration" -}&>> "${TMPDIR}/androot.log" \ No newline at end of file +log_write "#### rootfs configuration\n$(cat "${TMPDIR}/androot.env")\n#### rootfs configuration" \ No newline at end of file diff --git a/rootfsinstall.sh b/rootfsinstall.sh index ede4d62..be12d2f 100755 --- a/rootfsinstall.sh +++ b/rootfsinstall.sh @@ -1,5 +1,7 @@ #!/bin/bash -# shellcheck disable=SC2181 disable=SC1091 disable=SC2236 +# disable errors regarding androot.source as +# it is created and loaded at runtime +# shellcheck disable=SC1091 source "${TMPDIR}/androot.source" source "${TMPDIR}/androot.env" @@ -8,61 +10,81 @@ log_diag "rootfsinstall is now executing, with arguments \"${*}\"" case "${1}" in "--download") log_diag "Using download mode" - if [ -f "${TMPDIR}/rootfs.env" ]; then + # check if rootfs has been downloaded already + if [ -f "${TMPDIR}/rootfs.tar.gz" ] && [ -f "${TMPDIR}/rootfs.env" ]; then + # load rootfs info source "${TMPDIR}/rootfs.env" + # check if downloaded rootfs and rootfs configuration match if [ "${ARCH_TARGET_WRITTEN}" == "${ARCH_TARGET}" ] && [ "${DISTRIBUTION_WRITTEN}" == "${DISTRIBUTION}" ]; then - echo "#### found existing rootfs archive" &>> "${TMPDIR}/androot.log" + # ask if downloaded rootfs should be reused + log_write "#### found existing rootfs archive" log_askyn "true" "androot found a existing rootfs archive matching your configuration, do you want to use it? " if [ "${ANSWER}" == "true" ]; then - echo "#### skipping download" &>> "${TMPDIR}/androot.log" + # yes, skip download + log_write "#### skipping download" exit 0 else - echo "#### removing existing rootfs archive" &>> "${TMPDIR}/androot.log" + # no, remove rootfs and continue + log_write "#### removing existing rootfs archive" rm -rf "${TMPDIR}/rootfs.tar.gz" fi else - echo "#### removing existing rootfs archive" &>> "${TMPDIR}/androot.log" + # downloaded rootfs and rootfs configuration + # do not matchremove and continue + log_write "#### removing existing rootfs archive" log_diag "Removing existing rootfs archive (not matching)" rm -rf "${TMPDIR}/rootfs.tar.gz" fi fi - log_exec "Downloading rootfs" + indicate_exec "Downloading rootfs" + # check for internal inconsistencies or + # external modifications to androot.env case "${ARCH_TARGET}" in "x86_64") ;; "arm64") ;; *) - echo "#### invalid architecture \"${ARCH_TARGET}\"" &>> "${TMPDIR}/androot.log" - log_fail + log_write "#### invalid architecture \"${ARCH_TARGET}\"" + indicate_fail log_error "Internal inconsistency detected: Invalid target architecture \"${ARCH_TARGET}\"" - exit 1;; + exit 1 + ;; esac case "${DISTRIBUTION}" in "archlinux") ;; *) - echo "#### invalid distribution \"${DISTRIBUTION}\"" &>> "${TMPDIR}/androot.log" - log_fail + log_write "#### invalid distribution \"${DISTRIBUTION}\"" + indicate_fail log_error "Internal inconsistency detected: Invalid distribution \"${DISTRIBUTION}\"" - exit 1;; + exit 1 + ;; esac - echo "#### download rootfs (${DOWNLOADSERVER_ROOTFS}${DISTRIBUTION}-${ARCH_TARGET}.tar.gz)" &>> "${TMPDIR}/androot.log" - wget "${DOWNLOADSERVER_ROOTFS}${DISTRIBUTION}-${ARCH_TARGET}.tar.gz" -qqq -O "${TMPDIR}/rootfs.tar.gz" &>> "${TMPDIR}/androot.log" - if [ ! -f "${TMPDIR}/rootfs.tar.gz" ]; then - echo "#### rootfs not present" &>> "${TMPDIR}/androot.log" - log_fail - fi - echo -e "ARCH_TARGET_WRITTEN=${ARCH_TARGET}\nDISTRIBUTION_WRITTEN=${DISTRIBUTION}" > "${TMPDIR}/rootfs.env" - log_ok;; - "--decompress") - log_diag "Using decompress mode" - log_exec "Decompressing archive" - echo "#### decompress rootfs" &>> "${TMPDIR}/androot.log" - bsdtar -xpf "${TMPDIR}/rootfs.tar.gz" -C "${LOCATION}/rootfs" &>> "${TMPDIR}/androot.log" - if [ ! "${?}" == "0" ]; then - log_fail + # download rootfs from download server + log_write "#### download rootfs (${DOWNLOADSERVER_ROOTFS}${DISTRIBUTION}-${ARCH_TARGET}.tar.gz)" + if ! log_execute wget "${DOWNLOADSERVER_ROOTFS}${DISTRIBUTION}-${ARCH_TARGET}.tar.gz" --no-verbose -O "${TMPDIR}/rootfs.tar.gz"; then + indicate_fail exit 1 fi - log_ok;; + if [ ! -f "${TMPDIR}/rootfs.tar.gz" ]; then + # rootfs is missing (somehow) + log_write "#### rootfs not present" + indicate_fail + fi + # write rootfs configuration into file if the same rootfs config is used again + echo -e "ARCH_TARGET_WRITTEN=${ARCH_TARGET}\nDISTRIBUTION_WRITTEN=${DISTRIBUTION}" > "${TMPDIR}/rootfs.env" + indicate_ok + ;; + "--decompress") + log_diag "Using decompress mode" + indicate_exec "Decompressing archive" + log_write "#### decompress rootfs" + if ! log_execute bsdtar -xpf "${TMPDIR}/rootfs.tar.gz" -C "${LOCATION}/rootfs"; then + indicate_fail + exit 1 + fi + indicate_ok + ;; *) log_error "--download or --decompress required" - exit 1;; + exit 1 + ;; esac \ No newline at end of file