androot/rootfsinstall.sh

90 lines
3.1 KiB
Bash
Raw Normal View History

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