mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-21 12:59:08 +02:00
Both launch paths (pkg postinstall and the updater's startUIAsUser) run as root, so launchctl asuser alone moves the launch into the user's GUI domain but leaves root's HOME/USER/LOGNAME. Use sudo -u <user> -H to drop to the console user with their environment, fixing os.UserConfigDir() resolution. Drops the space-fragile dscl/awk home lookup and the duplicate-HOME append; extracts consoleUser() and aligns the skip list across both paths.
55 lines
1.6 KiB
Bash
Executable File
55 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
set -x
|
|
|
|
APP=/Applications/NetBird.app
|
|
AGENT=/usr/local/bin/netbird
|
|
LOG_FILE=/var/log/netbird/client_post_install.log
|
|
|
|
mkdir -p /var/log/netbird/
|
|
mkdir -p /usr/local/bin/
|
|
|
|
{
|
|
echo "Installing NetBird..."
|
|
|
|
if test -d $APP; then
|
|
echo "NetBird app copied successfully."
|
|
else
|
|
echo "NetBird app could not be copied to the Applications folder."
|
|
exit 1
|
|
fi
|
|
|
|
ln -fs $APP/Contents/MacOS/netbird $AGENT
|
|
if test -f $AGENT; then
|
|
echo "NetBird binary linked successfully."
|
|
else
|
|
echo "NetBird could not create symlink to /usr/local/bin"
|
|
exit 1
|
|
fi
|
|
|
|
$AGENT service install || true
|
|
$AGENT service start || true
|
|
|
|
console_user=$(stat -f%Su /dev/console 2>/dev/null)
|
|
case "$console_user" in
|
|
""|root|loginwindow|_mbsetupuser)
|
|
echo "No active GUI user session (console user: '${console_user:-none}'); skipping UI launch."
|
|
;;
|
|
*)
|
|
uid=$(id -u "$console_user" 2>/dev/null)
|
|
if [ -z "$uid" ]; then
|
|
echo "Could not resolve uid for console user '$console_user'; skipping UI launch."
|
|
else
|
|
echo "Launching NetBird UI as console user $console_user (uid $uid)."
|
|
if ! launchctl asuser "$uid" sudo -u "$console_user" -H open "$APP"; then
|
|
echo "Failed to launch NetBird UI; if autostart is enabled it will start at next login."
|
|
fi
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
echo "Finished Netbird installation successfully"
|
|
exit 0 # all good
|
|
} &> $LOG_FILE
|
|
|