Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better bootstrap check-install #704

Merged
merged 16 commits into from
Jun 2, 2024
Merged
4 changes: 2 additions & 2 deletions package/toltec-bootstrap/package
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"
license=MIT
Expand Down
41 changes: 34 additions & 7 deletions scripts/bootstrap/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
# <http://bin.entware.net/armv7sf-k3.2/installer/generic.sh>
#

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
Expand Down Expand Up @@ -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
}
Expand Down
Loading