Skip to content

Commit f1d371d

Browse files
committed
2024-08-08 installer script - master branch
1. Adopts recommended she-bang syntax. 2. Adds version number to banner (mainly as a visual aid when discussing installation issues on Discord). 3. Removes internal SCRIPT variable which has a dependency on whether the script is invoked directly or piped to bash. 4. No need to resolve absolute path for `IOTSTACK` variable. This just causes an error in green-fields situations. 5. Better messaging in `handle_exit()` so it is clear whether the script completed normally with no further work to do, or should be re-run. 6. Better handling of "logout required" situation. Rather than killing the immediate parent process (`$PPID`), now iterates the process ancestry to find the most-distant ancestor owned by the current user. For SSH connections this is typically the `sshd` spawned for the user. For console connections, it's typically the shell launched by the login process. This deals with the problem where a script (eg the menu) calling the installer script would be the immediate parent process, and it would be killed without necessarily causing the required logout to enable group membership changes to take effect. 7. Removes `is_running_OS_release()` function which was only being used to infer modern Python behaviour from "bookworm" (ie a hack) and which failed on Ubuntu. 8. Uses and documents use of `PIP_BREAK_SYSTEM_PACKAGES` variable which triggers the desired modern Python behaviour on systems which support it, being ignored otherwise. Signed-off-by: Phill Kelley <[email protected]>
1 parent b1d67ed commit f1d371d

File tree

1 file changed

+26
-32
lines changed

1 file changed

+26
-32
lines changed

install.sh

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
3+
# version - MUST be exactly 7 characters!
4+
UPDATE="2024v02"
25

36
echo " "
4-
echo " _____ ____ _______ _ _ "
5-
echo " |_ _/ __ \\__ __|| | installer | | "
7+
echo " _____ ____ _______ _ installer _ "
8+
echo " |_ _/ __ \\__ __|| | $UPDATE | | "
69
echo " | || | | | | |___| |_ __ _ ___| | __"
710
echo " | || | | | | / __| __/ _\` |/ __| |/ /"
811
echo " _| || |__| | | \\__ \\ || (_| | (__| < "
@@ -21,18 +24,12 @@ echo " "
2124
# overuse of sudo is a very common problem among new IOTstack users
2225
[ "$EUID" -eq 0 ] && echo "This script should NOT be run using sudo" && exit 1
2326

24-
# the name of this script is
25-
SCRIPT=$(basename "$0")
26-
2727
# this script should be run without arguments
28-
[ $# -ne 0 ] && echo "$SCRIPT parameter(s) $@ ignored"
28+
[ $# -ne 0 ] && echo "command line argument(s) $@ ignored"
2929

3030
# assumption(s) which can be overridden
3131
IOTSTACK=${IOTSTACK:-"$HOME/IOTstack"}
3232

33-
# form absolute path
34-
IOTSTACK=$(realpath "$IOTSTACK")
35-
3633
# derived path(s) - note that the menu knows about most of these so
3734
# they can't just be changed without a lot of care.
3835
IOTSTACK_ENV="$IOTSTACK/.env"
@@ -113,7 +110,10 @@ function handle_exit() {
113110
[ -d "$IOTSTACK" ] && echo "$1" >"$IOTSTACK_INSTALLER_HINT"
114111

115112
# inform the user
116-
echo -n "$SCRIPT completed"
113+
echo -n "install.sh completed"
114+
115+
# advise if should be re-run
116+
[ $1 -ne 0 ] && echo -n " - but should be re-run"
117117

118118
# reboot takes precedence over logout
119119
if [ "$REBOOT_REQUIRED" = "true" ] ; then
@@ -123,7 +123,16 @@ function handle_exit() {
123123
elif [ "$LOGOUT_REQUIRED" = "true" ] ; then
124124
echo " - a logout is required."
125125
sleep 2
126-
kill -HUP "$PPID"
126+
# iterate ancestor processes
127+
for ANCESTOR in $(ps -o ppid=) ; do
128+
# find first process belonging to current user
129+
if [ "$(ps -p $ANCESTOR -o user=)" = "$USER" ] ; then
130+
# kill it
131+
kill -HUP $ANCESTOR
132+
fi
133+
done
134+
# should not reach this
135+
sleep 2
127136
fi
128137

129138
# exit as instructed
@@ -229,13 +238,6 @@ echo ""
229238
# is in the expected location, the necessary symlink can be created by
230239
# this script and then docker-compose will be installed "correctly".
231240

232-
function is_running_OS_release() {
233-
unset VERSION_CODENAME
234-
[ -f "/etc/os-release" ] && eval $(grep "^VERSION_CODENAME=" /etc/os-release)
235-
[ "$VERSION_CODENAME" = "$1" ] && return 0
236-
return 1
237-
}
238-
239241
function is_python_script() {
240242
[ $(file -b "$1" | grep -c "^Python script") -gt 0 ] && return 0
241243
return 1
@@ -305,13 +307,9 @@ else
305307
echo "having installed docker and docker-compose without using the official"
306308
echo "'convenience script'. You may be able to solve this problem by running"
307309
if is_python_script "$COMPOSE_CMD_PATH" ; then
308-
if is_running_OS_release bookworm ; then
309-
echo " \$ pip3 uninstall -y --break-system-packages docker-compose"
310-
echo " \$ sudo pip3 uninstall -y --break-system-packages docker-compose"
311-
else
312-
echo " \$ pip3 uninstall -y docker-compose"
313-
echo " \$ sudo pip3 uninstall -y docker-compose"
314-
fi
310+
echo " \$ export PIP_BREAK_SYSTEM_PACKAGES=1"
311+
echo " \$ pip3 uninstall -y docker-compose"
312+
echo " \$ sudo pip3 uninstall -y docker-compose"
315313
echo " (ignore any errors from those commands)"
316314
else
317315
echo " \$ sudo apt purge -y docker-compose"
@@ -384,12 +382,8 @@ fi
384382
# implement menu requirements
385383
if [ -e "$IOTSTACK_MENU_REQUIREMENTS" ] ; then
386384
echo -e "\nChecking and updating IOTstack dependencies (pip)"
387-
unset PYTHON_OPTIONS
388-
if is_running_OS_release bookworm ; then
389-
echo "Note: pip3 installs bypass externally-managed environment check"
390-
PYTHON_OPTIONS="--break-system-packages"
391-
fi
392-
pip3 install -U $PYTHON_OPTIONS -r "$IOTSTACK_MENU_REQUIREMENTS"
385+
echo "Note: pip3 installs bypass externally-managed environment check"
386+
PIP_BREAK_SYSTEM_PACKAGES=1 pip3 install -U -r "$IOTSTACK_MENU_REQUIREMENTS"
393387
fi
394388

395389
# trigger re-creation of venv on next menu launch. Strictly speaking,

0 commit comments

Comments
 (0)