androot/rootfsinstall.sh
JeremyStarTM 3f0f0e0113 Update code
CHANGES
- [androot.sh] Improve code quality
- [androot.sh] Modify DOWNLOADSERVER* variables
- [patch.sh] Implement rootfs patching
- [prepare.sh] Squashed bugs
- [rootfsbuilder/archlinux-x86_64.sh] Remove "copy pacman config" flag causing some issues
- [systeminstall.sh] Implement rootfs configuration and update script

BUGS
- [systeminstall.sh|patch.sh] Scripts only work on the same architecture as the host
2023-11-10 15:08:35 +01:00

89 lines
3.1 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"
source "${TMPDIR}/androot.env"
log_diag "rootfsinstall is now executing, with arguments \"${*}\""
case "${1}" in
"--download")
log_diag "Using download mode"
# check if rootfs has been downloaded already
if [ -f "${TMPDIR}/rootfs.tar.gz" ] && [ -f "${TMPDIR}/rootfs.env" ]; then
# load rootfs info
source "${TMPDIR}/rootfs.env"
# check if downloaded rootfs and rootfs configuration match
if [ "${ARCH_TARGET_WRITTEN}" == "${ARCH_TARGET}" ] && [ "${DISTRIBUTION_WRITTEN}" == "${DISTRIBUTION}" ]; then
# ask if downloaded rootfs should be reused
log_write "#### found existing rootfs archive"
log_askyn "true" "androot found a existing rootfs archive matching your configuration, do you want to use it? "
if [ "${ANSWER}" == "true" ]; then
# yes, skip download
log_write "#### skipping download"
exit 0
else
# no, remove rootfs and continue
log_write "#### removing existing rootfs archive"
rm -rf "${TMPDIR}/rootfs.tar.gz"
fi
else
# downloaded rootfs and rootfs configuration
# do not matchremove and continue
log_write "#### removing existing rootfs archive"
log_diag "Removing existing rootfs archive (not matching)"
rm -rf "${TMPDIR}/rootfs.tar.gz"
fi
fi
indicate_exec "Downloading rootfs"
# check for internal inconsistencies or
# external modifications to androot.env
case "${ARCH_TARGET}" in
"x86_64") ;;
"arm64") ;;
*)
log_write "#### invalid architecture \"${ARCH_TARGET}\""
indicate_fail
log_error "Internal inconsistency detected: Invalid target architecture \"${ARCH_TARGET}\""
exit 1
;;
esac
case "${DISTRIBUTION}" in
"archlinux") ;;
*)
log_write "#### invalid distribution \"${DISTRIBUTION}\""
indicate_fail
log_error "Internal inconsistency detected: Invalid distribution \"${DISTRIBUTION}\""
exit 1
;;
esac
# download rootfs from download server
if ! log_execute wget "${DOWNLOADSERVER}/rootfs/${DISTRIBUTION}-${ARCH_TARGET}.tar.gz" --no-verbose -O "${TMPDIR}/rootfs.tar.gz"; then
indicate_fail
exit 1
fi
if [ ! -f "${TMPDIR}/rootfs.tar.gz" ]; then
# rootfs is missing (somehow)
log_write "#### rootfs not present"
indicate_fail
fi
# write rootfs configuration into file if the same rootfs config is used again
echo -e "ARCH_TARGET_WRITTEN=${ARCH_TARGET}\nDISTRIBUTION_WRITTEN=${DISTRIBUTION}" > "${TMPDIR}/rootfs.env"
indicate_ok
;;
"--decompress")
log_diag "Using decompress mode"
indicate_exec "Decompressing archive"
log_write "#### decompress rootfs"
if ! log_execute bsdtar -xpf "${TMPDIR}/rootfs.tar.gz" -C "${LOCATION}/rootfs"; then
indicate_fail
exit 1
fi
indicate_ok
;;
*)
log_error "--download or --decompress required"
exit 1
;;
esac