Skip to content

Commit a064180

Browse files
committed
use env var with default instead of hardcoding sudo
1 parent 2e82bb4 commit a064180

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

DEV

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
33
PKG_GLOB="archinstoo-*.pkg.tar.zst"
4+
ELEV="${ELEV:-sudo}"
45

56
go_to () {
67
cd "$SCRIPT_DIR/archinstoo" || exit 1
@@ -54,7 +55,7 @@ case "$1" in
5455
-i|--install)
5556
go_to
5657
# shellcheck disable=SC2086
57-
sudo pacman -U --overwrite '*' $PKG_GLOB
58+
"$ELEV" pacman -U --overwrite '*' $PKG_GLOB
5859
;;
5960
-tf | --test-full)
6061
./RUN --config examples/config-sample-full.json

ISOMOD

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/bin/bash
2+
ELEV="${ELEV:-"$ELEV"}"
3+
24
# Strict
35
set -e #uo pipefail
46

5-
# DO NOT RUN AS ROOT // Will prompt for sudo when needed
6-
[ "$(id -u)" -eq 0 ] && echo "Error: Sudo not required." && exit 1
7+
# DO NOT RUN AS ROOT // Will prompt when needed
8+
[ "$(id -u)" -eq 0 ] && echo "Error: Root not required." && exit 1
79

810
# Build stage 1 ISO with slight modifs
911
# Requires 'archiso'
@@ -39,10 +41,10 @@ cleanup() {
3941

4042
if [ -d "$WORK_DIR" ]; then
4143
# Kill any processes using the work dir
42-
sudo fuser -sk "$WORK_DIR" 2>/dev/null || true
44+
"$ELEV" fuser -sk "$WORK_DIR" 2>/dev/null || true
4345
# Force lazy recursive unmount
44-
sudo umount -lR "$WORK_DIR" 2>/dev/null || true
45-
sudo rm -rf "$WORK_DIR"
46+
"$ELEV" umount -lR "$WORK_DIR" 2>/dev/null || true
47+
"$ELEV" rm -rf "$WORK_DIR"
4648
fi
4749
echo "Cleanup complete."
4850
else
@@ -140,16 +142,16 @@ mkdir -p "$WORK_DIR"
140142

141143
# Will prompt to build
142144
if [ "$SILENT_MODE" = "1" ]; then
143-
sudo taskset -c 0-$((THREADS-1)) mkarchiso -v -w "$WORK_DIR" -o "$OUTPUT_DIR" -L "$ISO_LABEL" "$PROFILE_DIR" >/dev/null 2>&1 || error_exit "mkarchiso failed"
145+
"$ELEV" taskset -c 0-$((THREADS-1)) mkarchiso -v -w "$WORK_DIR" -o "$OUTPUT_DIR" -L "$ISO_LABEL" "$PROFILE_DIR" >/dev/null 2>&1 || error_exit "mkarchiso failed"
144146
else
145-
sudo taskset -c 0-$((THREADS-1)) mkarchiso -v -w "$WORK_DIR" -o "$OUTPUT_DIR" -L "$ISO_LABEL" "$PROFILE_DIR" || error_exit "mkarchiso failed"
147+
"$ELEV" taskset -c 0-$((THREADS-1)) mkarchiso -v -w "$WORK_DIR" -o "$OUTPUT_DIR" -L "$ISO_LABEL" "$PROFILE_DIR" || error_exit "mkarchiso failed"
146148
fi
147149

148150
echo ""
149151
echo "✓ SUCCESS! ISO created in: $OUTPUT_DIR"
150152
echo "Restoring permissions..."
151153
# restores both folder and any file within to correct permissions
152-
sudo chown -R "$USER":"$USER" "$OUTPUT_DIR"
154+
"$ELEV" chown -R "$USER":"$USER" "$OUTPUT_DIR"
153155
echo ""
154156

155157
cleanup

RUN

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash
22
# shellcheck disable=SC1091,SC2154
3-
4-
(cd archinstoo && sudo python -B -m archinstall "$@")
3+
ELEV="${ELEV:-sudo}"
4+
# help / list / size
5+
# do not need root but we append it for most features
6+
# can be launched with ELEV=doas env var
7+
(cd archinstoo && "$ELEV" python -B -m archinstall "$@")

RUN_VENV

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22
# shellcheck disable=SC1091,SC2154
3+
ELEV="${ELEV:-sudo}"
34
cd archinstoo || exit 1
45

56
# launch venv and run archinstall
@@ -11,4 +12,4 @@ else
1112
. .venv/bin/activate
1213
fi
1314

14-
sudo .venv/bin/python -B -m archinstall "$@"
15+
"$ELEV" .venv/bin/python -B -m archinstall "$@"

0 commit comments

Comments
 (0)