Skip to content

Commit 69093fe

Browse files
authored
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
1 parent 58dfef7 commit 69093fe

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

package/toltec-bootstrap/package

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
pkgnames=(toltec-bootstrap)
66
pkgdesc="Manage your Toltec install"
77
url=https://toltec-dev.org/
8-
pkgver=0.4.3-2
9-
timestamp=2024-05-30T20:02Z
8+
pkgver=0.4.4-1
9+
timestamp=2024-05-31T19:13Z
1010
section="utils"
1111
maintainer="Eeems <[email protected]>"
1212
license=MIT

scripts/bootstrap/bootstrap

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
# <http://bin.entware.net/armv7sf-k3.2/installer/generic.sh>
1616
#
1717

18+
if [ -z "$BASH" ] || [[ "$(ps | awk '$1=='$$' { n=split($5,a,"/"); print a[n] }')" != "bash" ]]; then
19+
echo "bootstrap must be run with bash"
20+
exit 1
21+
fi
22+
1823
set -eEuo pipefail
1924

2025
# Path to the temporary local wget and Opkg binaries
@@ -61,17 +66,39 @@ exists-non-empty() {
6166
[[ -d $1 ]] && files="$(ls -A -- "$1")" && [[ -n $files ]]
6267
}
6368

69+
already-installed-message() {
70+
log "Toltec is already installed or partially installed"
71+
log "To re-enable Toltec after a system upgrade, run 'toltecctl reenable'"
72+
log "To reinstall Toltec, run 'toltecctl uninstall' first"
73+
}
74+
6475
# Check whether a Toltec install already exists or if conflicting files
6576
# remain from previous installs
6677
check-installed() {
67-
if [[ ! -f $toltecctl_path ]]; then
68-
return
78+
local unit_path
79+
local unit
80+
# This should mimic get-bind-mount-path as close as possible to ensure it's always
81+
# the path that an install or reenable would generate.
82+
unit_path="/lib/systemd/system/$(systemd-escape --path /opt).mount"
83+
unit="$(basename "$unit_path")"
84+
if [[ -f $unit_path ]] && systemctl --quiet is-active "$unit" 2> /dev/null; then
85+
log ERROR "opt.mount is currently active"
86+
already-installed-message
87+
exit 1
6988
fi
70-
71-
if exists-non-empty /opt || exists-non-empty /home/root/.entware; then
72-
log "Toltec is already installed or partially installed"
73-
log "To re-enable Toltec after a system upgrade, run 'toltecctl reenable'"
74-
log "To reinstall Toltec, run 'toltecctl uninstall' first"
89+
if [[ "$(grep ' /opt ' /proc/mounts)" != "" ]]; then
90+
log ERROR "/opt is currently mounted"
91+
already-installed-message
92+
exit 1
93+
fi
94+
if exists-non-empty /opt; then
95+
log ERROR "/opt exists and is not empty"
96+
already-installed-message
97+
exit 1
98+
fi
99+
if exists-non-empty /home/root/.entware; then
100+
log ERROR "/home/root/.entware exists and is not empty"
101+
already-installed-message
75102
exit 1
76103
fi
77104
}

0 commit comments

Comments
 (0)