#!/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