202 lines
6.3 KiB
Bash
Executable file
202 lines
6.3 KiB
Bash
Executable file
#!/bin/bash
|
|
# shellcheck disable=SC2181 disable=SC1091 disable=SC2236
|
|
### 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
|
|
## $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/raw/branch/develop/"
|
|
## $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
|
|
|
|
if [ "${1}" == "--local" ]; then
|
|
log_diag "Using local mode"
|
|
env "TMPDIR=${TMPDIR}" ./prepare.sh
|
|
env "TMPDIR=${TMPDIR}" ./rootfsinstall.sh --download
|
|
env "TMPDIR=${TMPDIR}" ./rootfsinstall.sh --decompress
|
|
env "TMPDIR=${TMPDIR}" ./mount.sh --mount
|
|
env "TMPDIR=${TMPDIR}" ./bootscriptdl.sh --download
|
|
exit 0
|
|
env "TMPDIR=${TMPDIR}" ./bootscriptdl.sh --configure
|
|
env "TMPDIR=${TMPDIR}" ./bootscriptdl.sh --download-qemu
|
|
env "TMPDIR=${TMPDIR}" ./installsystem.sh --configure
|
|
env "TMPDIR=${TMPDIR}" ./installsystem.sh --update
|
|
env "TMPDIR=${TMPDIR}" ./patch.sh
|
|
env "TMPDIR=${TMPDIR}" ./mount.sh --unmount
|
|
env "TMPDIR=${TMPDIR}" ./finish.sh
|
|
elif [ "${1}" == "--download" ]; then
|
|
log_diag "Using download mode"
|
|
### UNIMPLEMENTED
|
|
log_exec Downloading files
|
|
log_fail
|
|
exit 1
|
|
### UNIMPLEMENTED_END
|
|
elif [ "${1}" == "--help" ]; then
|
|
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 or hides diagnostic messages, true/false]"
|
|
else
|
|
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!"
|
|
fi
|