From 69093fe2ec73eab386ee58bfafe29ecc292089cd Mon Sep 17 00:00:00 2001 From: Nathaniel van Diepen Date: Sun, 2 Jun 2024 12:53:28 -0600 Subject: [PATCH] Better bootstrap check-install (#704) * Update installed check messaging * Add note about unit_path * Error if trying to run with sh or other non-bash shell --- package/toltec-bootstrap/package | 4 ++-- scripts/bootstrap/bootstrap | 41 ++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/package/toltec-bootstrap/package b/package/toltec-bootstrap/package index 5edac385b..cc1d68274 100644 --- a/package/toltec-bootstrap/package +++ b/package/toltec-bootstrap/package @@ -5,8 +5,8 @@ pkgnames=(toltec-bootstrap) pkgdesc="Manage your Toltec install" url=https://toltec-dev.org/ -pkgver=0.4.3-2 -timestamp=2024-05-30T20:02Z +pkgver=0.4.4-1 +timestamp=2024-05-31T19:13Z section="utils" maintainer="Eeems " license=MIT diff --git a/scripts/bootstrap/bootstrap b/scripts/bootstrap/bootstrap index 0a61a772d..15da30019 100755 --- a/scripts/bootstrap/bootstrap +++ b/scripts/bootstrap/bootstrap @@ -15,6 +15,11 @@ # # +if [ -z "$BASH" ] || [[ "$(ps | awk '$1=='$$' { n=split($5,a,"/"); print a[n] }')" != "bash" ]]; then + echo "bootstrap must be run with bash" + exit 1 +fi + set -eEuo pipefail # Path to the temporary local wget and Opkg binaries @@ -61,17 +66,39 @@ exists-non-empty() { [[ -d $1 ]] && files="$(ls -A -- "$1")" && [[ -n $files ]] } +already-installed-message() { + log "Toltec is already installed or partially installed" + log "To re-enable Toltec after a system upgrade, run 'toltecctl reenable'" + log "To reinstall Toltec, run 'toltecctl uninstall' first" +} + # Check whether a Toltec install already exists or if conflicting files # remain from previous installs check-installed() { - if [[ ! -f $toltecctl_path ]]; then - return + local unit_path + local unit + # This should mimic get-bind-mount-path as close as possible to ensure it's always + # the path that an install or reenable would generate. + unit_path="/lib/systemd/system/$(systemd-escape --path /opt).mount" + unit="$(basename "$unit_path")" + if [[ -f $unit_path ]] && systemctl --quiet is-active "$unit" 2> /dev/null; then + log ERROR "opt.mount is currently active" + already-installed-message + exit 1 fi - - if exists-non-empty /opt || exists-non-empty /home/root/.entware; then - log "Toltec is already installed or partially installed" - log "To re-enable Toltec after a system upgrade, run 'toltecctl reenable'" - log "To reinstall Toltec, run 'toltecctl uninstall' first" + if [[ "$(grep ' /opt ' /proc/mounts)" != "" ]]; then + log ERROR "/opt is currently mounted" + already-installed-message + exit 1 + fi + if exists-non-empty /opt; then + log ERROR "/opt exists and is not empty" + already-installed-message + exit 1 + fi + if exists-non-empty /home/root/.entware; then + log ERROR "/home/root/.entware exists and is not empty" + already-installed-message exit 1 fi }