mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 18:18:55 +00:00
The current test installation fails because it is operating in a headless environment without a display user. Some more testing of the `who` command showed that we can simply take the first user. That avoids `grep` which was previously failing with an exit code of 1, aborting the installation because our `postinst` script has `pipefail` set.
31 lines
983 B
Bash
Executable File
31 lines
983 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
SERVICE_NAME="firezone-client-tunnel"
|
|
|
|
DISPLAY_USER=$(who | awk '{print $1}' | head -n 1)
|
|
|
|
if [ -n "${PKEXEC_UID:-}" ]; then
|
|
INVOKING_USER=$(id -un "$PKEXEC_UID" 2>/dev/null) # Detect user from PolicyKit.
|
|
|
|
echo "Detected invoking user from PolicyKit: $INVOKING_USER"
|
|
elif [ -n "${SUDO_USER:-}" ]; then
|
|
INVOKING_USER="$SUDO_USER" # Detect user from `sudo apt/dnf install`.
|
|
|
|
echo "Detected invoking user from SUDO_USER: $INVOKING_USER"
|
|
elif [ -n "${DISPLAY_USER:-}" ]; then
|
|
INVOKING_USER="$DISPLAY_USER" # Detect user from display session.
|
|
|
|
echo "Detected invoking user from display session: $INVOKING_USER"
|
|
fi
|
|
|
|
sed -i "s/<<USER>>/${INVOKING_USER:-root}/g" "/usr/lib/sysusers.d/firezone-client-tunnel.conf"
|
|
|
|
# Creates the system group `firezone-client` and adds the group membership.
|
|
systemd-sysusers firezone-client-tunnel.conf
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable "$SERVICE_NAME"
|
|
systemctl restart "$SERVICE_NAME"
|