androot/prepare.sh

177 lines
No EOL
6.3 KiB
Bash
Executable file

#!/bin/bash
# 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"
log_info "Note: The target architecture may be different from the current"
log_info " architecture as it will be emulated with qemu-static (with"
log_info " a slight performance penality)."
log_info "Available target architectures: x86_64, arm64"
log_ask "Target architecture: "
case "${ANSWER,,}" in
"x86_64") ;;
"arm64") ;;
*)
log_error "Invalid target architecture \"${ANSWER,,}\", please retry."
arch_target
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)"
log_info "Note: A qemu-static binary is downloaded for each execution"
log_info " architecture. If you intend on running the rootfs on this"
log_info " machine only, leave this field empty. Multiple architectures"
log_info " can be specified, if you want."
log_info "Available execution architectures: x86_64, arm64, powerpc64, mips64"
log_ask "Execution architecture(s): "
### MISIMPLEMENTED
case "${ANSWER}" in
"x86_64") ;;
"arm64") ;;
"powerpc64") ;;
"mips64") ;;
"")
export "ANSWER=${ARCH}"
;;
*)
log_error "Invalid execution architecture \"${ANSWER,,}\", please retry."
arch_executors
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"
log_info "Note: Each distribution you select here will be compatible"
log_info " with every target architecture, unless noted."
log_info "Available distributions: archlinux"
log_ask "Target distribution: "
case "${ANSWER,,}" in
"archlinux") ;;
*)
log_error "Invalid distribution \"${ANSWER,,}\", please retry."
distribution
return
;;
esac
echo "DISTRIBUTION=${ANSWER,,}" >> "${TMPDIR}/androot.env"
}
# ask for install location
function location() {
log_info ""
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*) # 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/*) # 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/*) # disallow THESE directories
log_error "Are you really trying that?"
location
return
;;
/) # just do "rm -rf --no-preserve-root /" instead
log_error "you're making a recipe for desaster."
location
return
;;
"uwu"|"owo"|"~nya"|"~ nya"|"~ahh"|"~ ahh") # reference
log_error "eww!"
location
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
;;
"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 [ -n "$(ls -A "${ANSWER}")" ]; then
log_error "The location directory is not empty."
location
return
fi
else
# create directory
indicate_exec "Creating location directory"
if ! mkdir -p "${ANSWER}/rootfs"; then
indicate_fail;
exit 1
fi
fi
echo "LOCATION=${ANSWER}" >> "${TMPDIR}/androot.env"
}
arch_target
arch_executors
distribution
location
log_write "#### rootfs configuration\n$(cat "${TMPDIR}/androot.env")\n#### rootfs configuration"