Skip to content

Commit a09d247

Browse files
committed
refactoring
1 parent 684c8c0 commit a09d247

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

usr/bin/upgrade-nonroot

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,29 @@ set -e
88
# shellcheck source=../../../helper-scripts/usr/libexec/helper-scripts/as_root.sh
99
source /usr/libexec/helper-scripts/as-root.sh
1010

11-
leaprun_exe="$(which leaprun)"
12-
# If privleap is installed and usable by the current user, use that, otherwise
13-
# try to run the script directly. This allows upgrade-nonroot to work even if
14-
# privleapd isn't running or the root user has no privleap socket.
15-
if [ -n "${leaprun_exe}" ] \
16-
&& [ -f "/etc/privleapd/pid" ] \
17-
&& [ -d "/proc/$(cat /etc/privleapd/pid)" ] \
18-
&& [ -e "/etc/privleapd/comm/$(id -nu)" ]; then
19-
"${leaprun_exe}" apt-get-update-plus-dist-upgrade
20-
else
11+
## If privleap is installed and usable by the current user, use that, otherwise
12+
## try to run the script directly. This allows upgrade-nonroot to work even if
13+
## privleapd isn't running or the root user has no privleap socket.
14+
15+
if ! command -v leaprun >/dev/null ; then
2116
as_root
2217
exec /usr/bin/apt-get-update-plus dist-upgrade
2318
fi
19+
## This is never reached if running 'exec' above.
20+
21+
if ! [ -f "/etc/privleapd/pid" ] ; then
22+
echo "$0: ERROR: code 1: TODO"
23+
exit 1
24+
fi
25+
26+
if ! [ -d "/proc/$(cat /etc/privleapd/pid)" ] ; then
27+
echo "$0: ERROR: code 2: TODO"
28+
exit 1
29+
fi
30+
31+
if ! [ -e "/etc/privleapd/comm/$(id -nu)" ]; then
32+
echo "$0: ERROR: code 3: TODO"
33+
exit 1
34+
fi
35+
36+
exec leaprun apt-get-update-plus-dist-upgrade

0 commit comments

Comments
 (0)