2023-11-07 17:23:39 +01:00
|
|
|
#!/bin/bash
|
2023-11-08 19:47:37 +01:00
|
|
|
# disable errors regarding androot.source as
|
|
|
|
# it is created and loaded at runtime
|
|
|
|
# shellcheck disable=SC1091
|
2023-11-07 17:23:39 +01:00
|
|
|
|
|
|
|
source "${TMPDIR}/androot.source"
|
|
|
|
log_diag "prepare is now executing, with arguments \"${*}\""
|
|
|
|
|
2023-11-08 19:47:37 +01:00
|
|
|
# ask for target architecture
|
2023-11-07 17:23:39 +01:00
|
|
|
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: "
|
2023-11-10 15:08:35 +01:00
|
|
|
case "${ANSWER}" in
|
2023-11-07 17:23:39 +01:00
|
|
|
"x86_64") ;;
|
|
|
|
"arm64") ;;
|
|
|
|
*)
|
2023-11-10 15:08:35 +01:00
|
|
|
log_error "Invalid target architecture \"${ANSWER}\", please retry."
|
2023-11-07 17:23:39 +01:00
|
|
|
arch_target
|
2023-11-08 19:47:37 +01:00
|
|
|
return
|
|
|
|
;;
|
2023-11-07 17:23:39 +01:00
|
|
|
esac
|
2023-11-10 15:08:35 +01:00
|
|
|
echo "ARCH_TARGET=\"${ANSWER}\"" > "${TMPDIR}/androot.env"
|
2023-11-07 17:23:39 +01:00
|
|
|
}
|
2023-11-08 19:47:37 +01:00
|
|
|
|
|
|
|
# ask for execution architecture(s)
|
2023-11-07 20:54:57 +01:00
|
|
|
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): "
|
2023-11-08 20:13:11 +01:00
|
|
|
if [ "${ANSWER}" == "" ]; then
|
|
|
|
echo "ARCH_EXECUTORS=${ARCH}" >> "${TMPDIR}/androot.env"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
for ARCHITECTURE in ${ANSWER}; do
|
|
|
|
case "${ARCHITECTURE}" in
|
|
|
|
"x86_64") ;;
|
|
|
|
"arm64") ;;
|
|
|
|
"powerpc64") ;;
|
|
|
|
"mips64") ;;
|
|
|
|
*)
|
|
|
|
log_error "Invalid execution architecture \"${ARCHITECTURE}\", please retry."
|
|
|
|
arch_executors
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2023-11-08 21:13:49 +01:00
|
|
|
if [[ "${ANSWER}" == *"${ARCH_TARGET}"* ]]; then
|
|
|
|
export "ANSWER=x86_64 ${ANSWER}"
|
|
|
|
fi
|
2023-11-10 15:08:35 +01:00
|
|
|
echo "ARCH_EXECUTORS=\"${ANSWER}\"" >> "${TMPDIR}/androot.env"
|
2023-11-07 17:23:39 +01:00
|
|
|
}
|
2023-11-08 19:47:37 +01:00
|
|
|
|
|
|
|
# ask for target distribution
|
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: "
|
2023-11-10 15:08:35 +01:00
|
|
|
case "${ANSWER}" in
|
2023-11-07 17:23:39 +01:00
|
|
|
"archlinux") ;;
|
|
|
|
*)
|
2023-11-10 15:08:35 +01:00
|
|
|
log_error "Invalid distribution \"${ANSWER}\", please retry."
|
2023-11-07 17:23:39 +01:00
|
|
|
distribution
|
2023-11-08 19:47:37 +01:00
|
|
|
return
|
|
|
|
;;
|
2023-11-07 17:23:39 +01:00
|
|
|
esac
|
2023-11-10 15:08:35 +01:00
|
|
|
echo "DISTRIBUTION=\"${ANSWER}\"" >> "${TMPDIR}/androot.env"
|
2023-11-07 17:23:39 +01:00
|
|
|
}
|
2023-11-08 19:47:37 +01:00
|
|
|
|
|
|
|
# ask for install location
|
2023-11-07 17:23:39 +01:00
|
|
|
function location() {
|
|
|
|
log_info ""
|
2023-11-08 19:47:37 +01:00
|
|
|
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."
|
2023-11-07 17:23:39 +01:00
|
|
|
log_ask "Location: "
|
2023-11-08 19:47:37 +01:00
|
|
|
# check against invalid paths
|
2023-11-07 17:23:39 +01:00
|
|
|
case "${ANSWER}" in
|
2023-11-08 19:47:37 +01:00
|
|
|
"") # doing nothing is illegal
|
2023-11-07 20:54:57 +01:00
|
|
|
log_error "Please enter something >.<"
|
|
|
|
location
|
2023-11-08 19:47:37 +01:00
|
|
|
return
|
|
|
|
;;
|
|
|
|
/tmp*) # disallow /tmp as disk space issues might haunt us
|
2023-11-07 20:54:57 +01:00
|
|
|
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
|
2023-11-08 19:47:37 +01:00
|
|
|
return
|
|
|
|
;;
|
|
|
|
/dev/shm/*) # disallow /dev/shm too, except if ALLOW_SHM is true
|
|
|
|
if [ ! "${ALLOW_SHM}" == "true" ]; then
|
2023-11-07 20:54:57 +01:00
|
|
|
log_error "Using /dev/shm is unsupported as you may run into disk space issues very quickly, please retry."
|
|
|
|
location
|
|
|
|
return
|
2023-11-08 19:47:37 +01:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
/dev|/proc|/run|/sys|/dev/*|/proc/*|/run/*|/sys/*) # disallow THESE directories
|
2023-11-07 17:23:39 +01:00
|
|
|
log_error "Are you really trying that?"
|
|
|
|
location
|
2023-11-08 19:47:37 +01:00
|
|
|
return
|
|
|
|
;;
|
|
|
|
/) # just do "rm -rf --no-preserve-root /" instead
|
2023-11-07 17:23:39 +01:00
|
|
|
log_error "you're making a recipe for desaster."
|
|
|
|
location
|
2023-11-08 19:47:37 +01:00
|
|
|
return
|
|
|
|
;;
|
|
|
|
"uwu"|"owo"|"~nya"|"~ nya"|"~ahh"|"~ ahh") # reference
|
2023-11-07 20:54:57 +01:00
|
|
|
log_error "eww!"
|
|
|
|
location
|
2023-11-08 19:47:37 +01:00
|
|
|
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."
|
2023-11-07 20:54:57 +01:00
|
|
|
location
|
2023-11-08 19:47:37 +01:00
|
|
|
return
|
|
|
|
;;
|
2023-11-07 17:23:39 +01:00
|
|
|
esac
|
2023-11-08 19:47:37 +01:00
|
|
|
# checks
|
2023-11-07 17:23:39 +01:00
|
|
|
if [ -a "${ANSWER}" ] && [ ! -d "${ANSWER}" ]; then
|
|
|
|
log_error "The location exists but is not a directory."
|
|
|
|
location
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
if [ -d "${ANSWER}" ]; then
|
2023-11-08 19:47:37 +01:00
|
|
|
if [ -n "$(ls -A "${ANSWER}")" ]; then
|
2023-11-07 17:23:39 +01:00
|
|
|
log_error "The location directory is not empty."
|
|
|
|
location
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
else
|
2023-11-08 19:47:37 +01:00
|
|
|
# create directory
|
|
|
|
indicate_exec "Creating location directory"
|
|
|
|
if ! mkdir -p "${ANSWER}/rootfs"; then
|
2023-11-08 21:13:49 +01:00
|
|
|
indicate_fail
|
2023-11-07 20:54:57 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-11-08 21:13:49 +01:00
|
|
|
indicate_ok
|
2023-11-07 17:23:39 +01:00
|
|
|
fi
|
2023-11-10 15:08:35 +01:00
|
|
|
echo "LOCATION=\"${ANSWER}\"" >> "${TMPDIR}/androot.env"
|
2023-11-07 17:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
arch_target
|
2023-11-07 20:54:57 +01:00
|
|
|
arch_executors
|
2023-11-07 17:23:39 +01:00
|
|
|
distribution
|
|
|
|
location
|
|
|
|
|
2023-11-10 15:08:35 +01:00
|
|
|
log_write "#### rootfs configuration\n$(cat "${TMPDIR}/androot.env")\n#### rootfs configuration"
|