Last active
April 5, 2016 18:48
-
-
Save opragel/1a45a0a7193ceca3399a to your computer and use it in GitHub Desktop.
Revisions
-
Owen Pragel revised this gist
Mar 25, 2016 . 2 changed files with 29 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ #!/bin/bash LAUNCH_AGENT_PATH="/Library/LaunchAgents/com.pritunl.client.plist" currentUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");') currentUserPID=$(pgrep WindowServer -m1) currentUserUID=$(id -u "$currentUser") osvers=$(sw_vers -productVersion | awk -F. '{print $2}') if [[ $EUID -ne 0 ]]; then printf "Run this script as root." exit 10 fi if [ ! -f "$LAUNCH_AGENT_PATH" ]; then printf "Launch agent not found at path: %s" "$LAUNCH_AGENT_PATH" exit 20 fi if [[ $osvers -lt 10 ]]; then launchctl bsexec "$currentUserPID" launchctl load "$LAUNCH_AGENT_PATH" > /dev/null 2>&1 & elif [[ $osvers -eq 10 ]]; then launchctl asuser "$currentUser" launchctl load "$LAUNCH_AGENT_PATH" > /dev/null 2>&1 & elif [[ $osvers -ge 11 ]]; then launchctl bootstrap "gui/$currentUserUID" "$LAUNCH_AGENT_PATH" > /dev/null 2>&1 & else printf "Things have gone terribly wrong. OS Version: %s" "$osvers" exit 30 fi -
mpanighetti created this gist
Mar 25, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ #!/bin/sh # variable-ing loggedInUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }') loggedInUID=$(stat -f%u /dev/console) loggedInPID=$(ps -A | grep -m1 Dock | awk '{print $1}') osvers=$(sw_vers -productVersion | awk -F. '{print $2}') # modify LaunchAgent for correct ownership chown -R $loggedInUser "path/to/LaunchAgent" # load LaunchAgent as user (using launchctl bsexec or launchctl bootstrap depending on OS X version) if [[ $osvers -lt 10 ]]; then launchctl bsexec $loggedInPID /usr/bin/sudo -iu $loggedInUser "launchctl load 'path/to/launchagent'" else launchctl bootstrap gui/$loggedInUID "path/to/launchagent" fi