androot/prepare.sh

156 lines
5.6 KiB
Bash
Raw Normal View History

2023-11-07 17:23:39 +01:00
#!/bin/bash
# shellcheck disable=SC2181 disable=SC1091 disable=SC2236
source "${TMPDIR}/androot.source"
log_diag "prepare is now executing, with arguments \"${*}\""
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"
}
function arch_executors() {
2023-11-07 17:23:39 +01:00
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
2023-11-07 17:23:39 +01:00
return;;
esac
### MISIMPLEMENTED
echo "ARCH_EXECUTORS=${ANSWER}" >> "${TMPDIR}/androot.env"
2023-11-07 17:23:39 +01:00
}
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"
}
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_ask "Location: "
case "${ANSWER}" in
"")
log_error "Please enter something >.<"
location
return;;
/tmp*)
log_error "Using /tmp is unsupported as you may run into disk space issues very quickly, please retry."
2023-11-07 17:23:39 +01:00
location
return;;
/dev/shm/*)
if [ ! "${DIAG}" == "true" ]; then
log_error "Using /dev/shm is unsupported as you may run into disk space issues very quickly, please retry."
location
return
fi;;
2023-11-07 17:23:39 +01:00
/dev|/proc|/run|/sys|/dev/*|/proc/*|/run/*|/sys/*)
log_error "Are you really trying that?"
location
return;;
2023-11-07 17:23:39 +01:00
/)
log_error "you're making a recipe for desaster."
location
return;;
"uwu")
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."
location
return;;
2023-11-07 17:23:39 +01:00
esac
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
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;
exit 1
fi
2023-11-07 17:23:39 +01:00
fi
echo "LOCATION=${ANSWER}" >> "${TMPDIR}/androot.env"
}
arch_target
arch_executors
2023-11-07 17:23:39 +01:00
distribution
location
log_diag "androot.env:\n$(cat "${TMPDIR}/androot.env")"
{
echo "#### rootfs configuration"
cat "${TMPDIR}/androot.env"
echo "#### rootfs configuration"
}&>> "${TMPDIR}/androot.log"