Skip to content

Commit

Permalink
Better bootstrap check-install (#704)
Browse files Browse the repository at this point in the history
* Update installed check messaging

* Add note about unit_path

* Error if trying to run with sh or other non-bash shell
  • Loading branch information
Eeems committed Jun 2, 2024
1 parent 58dfef7 commit 69093fe
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
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

0 comments on commit 69093fe

Please sign in to comment.