#!/bin/bash # shellcheck disable=SC2181 disable=SC1091 disable=SC2236 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" if [ -f "${TMPDIR}/rootfs.env" ]; then source "${TMPDIR}/rootfs.env" if [ "${ARCH_TARGET_WRITTEN}" == "${ARCH_TARGET}" ] && [ "${DISTRIBUTION_WRITTEN}" == "${DISTRIBUTION}" ]; then echo "#### found existing rootfs archive" &>> "${TMPDIR}/androot.log" log_askyn "true" "androot found a existing rootfs archive matching your configuration, do you want to use it? " if [ "${ANSWER}" == "true" ]; then echo "#### skipping download" &>> "${TMPDIR}/androot.log" exit 0 else echo "#### removing existing rootfs archive" &>> "${TMPDIR}/androot.log" rm -rf "${TMPDIR}/rootfs.tar.gz" fi else echo "#### removing existing rootfs archive" &>> "${TMPDIR}/androot.log" log_diag "Removing existing rootfs archive (not matching)" rm -rf "${TMPDIR}/rootfs.tar.gz" fi fi log_exec "Downloading rootfs" case "${ARCH_TARGET}" in "x86_64") ;; "arm64") ;; *) echo "#### invalid architecture \"${ARCH_TARGET}\"" &>> "${TMPDIR}/androot.log" log_fail log_error "Internal inconsistency detected: Invalid target architecture \"${ARCH_TARGET}\"" exit 1;; esac case "${DISTRIBUTION}" in "archlinux") ;; *) echo "#### invalid distribution \"${DISTRIBUTION}\"" &>> "${TMPDIR}/androot.log" log_fail log_error "Internal inconsistency detected: Invalid distribution \"${DISTRIBUTION}\"" exit 1;; esac echo "#### download rootfs (${DOWNLOADSERVER_ROOTFS}${DISTRIBUTION}-${ARCH_TARGET}.tar.gz)" &>> "${TMPDIR}/androot.log" wget "${DOWNLOADSERVER_ROOTFS}${DISTRIBUTION}-${ARCH_TARGET}.tar.gz" -qqq -O "${TMPDIR}/rootfs.tar.gz" &>> "${TMPDIR}/androot.log" if [ ! -f "${TMPDIR}/rootfs.tar.gz" ]; then echo "#### rootfs not present" &>> "${TMPDIR}/androot.log" log_fail fi echo -e "ARCH_TARGET_WRITTEN=${ARCH_TARGET}\nDISTRIBUTION_WRITTEN=${DISTRIBUTION}" > "${TMPDIR}/rootfs.env" log_ok;; "--decompress") log_diag "Using decompress mode" log_exec "Decompressing archive" echo "#### decompress rootfs" &>> "${TMPDIR}/androot.log" bsdtar -xpf "${TMPDIR}/rootfs.tar.gz" -C "${LOCATION}/rootfs" &>> "${TMPDIR}/androot.log" if [ ! "${?}" == "0" ]; then echo "#### bsdtar failed" &>> "${TMPDIR}/androot.log" log_fail exit 1 fi log_ok;; *) log_error "--download or --decompress required" exit 1;; esac