androot/prepare.sh
2023-11-07 17:23:39 +01:00

117 lines
No EOL
3.5 KiB
Bash
Executable file

#!/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_executers() {
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_executers
return;;
esac
### MISIMPLEMENTED
echo "ARCH_EXECUTERS=${ANSWER}" >> "${TMPDIR}/androot.env"
}
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
/tmp*|/dev/shm/*)
log_error "Using /tmp or /dev/shm is unsupported as you may run into disk space issues very quickly, please retry."
location
return;;
/dev|/proc|/run|/sys|/dev/*|/proc/*|/run/*|/sys/*)
log_error "Are you really trying that?"
location
return ;;
/)
log_error "you're making a recipe for desaster."
location
return ;;
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" "${ANSWER}/bootscripts"
fi
echo "LOCATION=${ANSWER}" >> "${TMPDIR}/androot.env"
}
arch_target
arch_executers
distribution
location
log_diag "androot.env:\n$(cat "${TMPDIR}/androot.env")"
{
echo "#### rootfs configuration"
cat "${TMPDIR}/androot.env"
echo "#### rootfs configuration"
}&>> "${TMPDIR}/androot.log"