From: Matteo Nastasi Date: Wed, 7 Oct 2026 10:04:45 +0000 (+0000) Subject: print the privileged commands with sudo where sudo is installed X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=commitdiff_plain;h=94d72c9b9ae270c0107cf9f4cf462466700a90bd;p=brisk.git print the privileged commands with sudo where sudo is installed The commands the "system" action prints, and the ones in the head of the files it generates, were all "su -c '...'". On debian 13 sudo is installed and the root account is left without a password, so those are commands nobody can run. as_root() now prints "sudo " where sudo is on the path and "su -c ''" where it is not, which is still the way on the older machines this has to keep working on. The one privileged command the action runs by itself, the copy of the sysv script into /etc/init.d, goes through sudo on the same condition. The heads of the generated files also said "run INSTALL.sh again instead", which stopped being true when they moved to the action: they say "INSTALL.sh system" now. Checked in the container: the action prints sudo for the nginx, nftables and systemd commands, the heads of the three generated files carry the same form, and as_root with sudo off the path falls back to su -c. Co-Authored-By: Claude Opus 5 (1M context) --- diff --git a/INSTALL.sh b/INSTALL.sh index 651bc93..4512f8b 100755 --- a/INSTALL.sh +++ b/INSTALL.sh @@ -205,6 +205,17 @@ function fpm_front_ports() { done | sort -un } +# How to say "as root" on this machine. debian 13 installs sudo and leaves +# the root account without a password, so a "su -c" printed there is a +# command nobody can run; where sudo is missing, su is still the way. +function as_root() { + if command -v sudo >/dev/null 2>&1; then + echo "sudo $1" + else + echo "su -c '$1'" + fi +} + # Whether this machine is run by systemd. A /etc/init.d script is of no use # where it is: debian 13 dropped the sysv compatibility generator, so the # script is never turned into a service and nothing starts it at boot. @@ -230,9 +241,9 @@ function systemd_unit_gen() { cat > "$tmp" < "$tmp" </dev/null 2>&1; then + sudo cp brisk-init.sh.wrk "/etc/init.d/${scrname}" + else + su -c "cp brisk-init.sh.wrk /etc/init.d/${scrname}" + fi rm brisk-init.sh.wrk echo "sysv script installed as /etc/init.d/${scrname}" - sys_todo="${sys_todo} su -c 'update-rc.d $scrname defaults'\n" + sys_todo="${sys_todo} $(as_root "update-rc.d $scrname defaults")\n" fi echo diff --git a/WARNING.txt b/WARNING.txt index 2d7d94a..b79560a 100644 --- a/WARNING.txt +++ b/WARNING.txt @@ -113,9 +113,13 @@ Where systemd is in charge the action writes a unit instead, in Etc as .service beside the other generated files, and leaves /etc/init.d alone. It is only written: copy it, reload, enable. - su -c 'cp /brisk.service /etc/systemd/system/' - su -c 'systemctl daemon-reload' - su -c 'systemctl enable --now brisk' + sudo cp /brisk.service /etc/systemd/system/ + sudo systemctl daemon-reload + sudo systemctl enable --now brisk + +(the action prints these with sudo where sudo is installed, with su -c where +it is not: debian 13 installs sudo and leaves root without a password, so a +su -c printed there is a command nobody can run) Without systemd nothing changes: the sysv script is installed as before.