androot/androot.sh
JeremyStarTM 8e0e3f63a1 Update files
- [androot.sh] Fix $DOWNLOADSERVER_BOOTSCRIPTS
- [androot.sh] Add $BRANCH variable
- [androot.sh] Introduce run_script() function
- [androot.sh] Use case instead of if
- [prepare.sh] Fix typo (executer -> executor)
- [rootfsinstall.sh] Remove "bsdtar failed" log line
- [bootscriptdl.sh] Trim download mode
- [bootscriptdl.sh] Implement install-qemu mode
- [README.md] Changed wording and added links
- [README.md] Add /dev/shm recommendation
- [Makefile,README.md] Add Makefile
2023-11-07 20:54:57 +01:00

213 lines
6.4 KiB
Bash
Executable file

#!/bin/bash
# shellcheck disable=SC2181 disable=SC1091 disable=SC2236
# shellcheck disable=SC2068
### TOBECHANGED
# shellcheck disable=SC2317
### TOBECHANGED_END
# Check if root
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
mkdir -p "${TMPDIR}"
# Write source file
cat << EOF > "${TMPDIR}/androot.source"
# Functions
## Indicate failure
function log_fail() {
echo -e "\r\e[0m[\e[0;31mFAIL\e[0m]"
}
## Indicate success
function log_ok() {
echo -e "\r\e[0m[\e[0;32m OK \e[0m]"
}
## Indicate running execution
function log_exec() {
echo -ne "\e[0m[\e[0;34m....\e[0m] \${*}"
}
## Diagnostic logging
function log_diag() {
if [ "\$DIAG" == "true" ]; then echo -e "\e[0m[\e[0;35mDIAG\e[0m] \${*}"; fi
}
## Informational logging
function log_info() {
echo -e "\r\e[0m[\e[0;32mINFO\e[0m] \${*}"
}
## Warning logging
function log_warn() {
echo -e "\r\e[0m[\e[0;33mWARN\e[0m] \${*}"
}
## Error logging
function log_error() {
echo -e "\r\e[0m[\e[0;31mERR!\e[0m] \${*}"
}
## 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
}
# Global variables
## $BRANCH
export "BRANCH=develop"
## $DOWNLOADSERVER_ROOTFS
export "DOWNLOADSERVER_ROOTFS=https://fs.staropensource.de/rootfs/"
## $DOWNLOADSERVER_QEMUSTATIC
export "DOWNLOADSERVER_QEMUSTATIC=https://fs.staropensource.de/qemu-static/"
## $DOWNLOADSERVER_BOOTSCRIPTS
export "DOWNLOADSERVER_BOOTSCRIPTS=https://git.staropensource.de/StarOpenSource/androot.git"
## $ARCH
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
## $IS_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
## 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"
# Diagnostic mode
log_diag "Diagnostic mode enabled"
log_diag "Arguments: ${*}"
# Check 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
function run_script() {
env "TMPDIR=${TMPDIR}" $@
if [ ! "${?}" == "0" ]; then
exit 1
fi
}
case "${1}" in
"--local")
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")
log_diag "Using download mode"
### UNIMPLEMENTED
log_exec Downloading files
log_fail
exit 1;;
### UNIMPLEMENTED_END
"--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