diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/wol-f3s | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/scripts/wol-f3s b/scripts/wol-f3s index 95c1766..a5f8030 100755 --- a/scripts/wol-f3s +++ b/scripts/wol-f3s @@ -44,12 +44,15 @@ PI3_IP="192.168.1.128" # from ~/.shelly_plug if that file exists. # # The shutdown paths need root (to umount NFS), so this script is typically -# run via sudo. Under sudo $HOME becomes /root, where ~/.shelly_plug does not -# exist — so resolve the file relative to the invoking user's home when -# $SUDO_USER is set, falling back to $HOME otherwise. +# run elevated. When elevated, $HOME becomes root's home, where ~/.shelly_plug +# does not exist — so resolve the file relative to the invoking user's home +# ($SUDO_USER under sudo on Linux, $DOAS_USER under doas on NetBSD Pis), +# falling back to $HOME otherwise. Uses ~-expansion (portable) rather than +# getent, which does not exist on NetBSD. SHELLY_IP="192.168.1.28" -if [[ -n "${SUDO_USER:-}" ]]; then - _shelly_home="$(getent passwd "$SUDO_USER" | cut -d: -f6)" +_shelly_user="${SUDO_USER:-${DOAS_USER:-}}" +if [[ -n "$_shelly_user" ]]; then + _shelly_home="$(eval echo "~${_shelly_user}")" SHELLY_PASS_FILE="${_shelly_home:-$HOME}/.shelly_plug" else SHELLY_PASS_FILE="${HOME}/.shelly_plug" |
