Created
July 6, 2021 17:53
-
-
Save xrpdevs/b53c9962dd72ffce2cdd6bd9d4d87f28 to your computer and use it in GitHub Desktop.
Revisions
-
xrpdevs created this gist
Jul 6, 2021 .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,61 @@ #!/bin/sh ## Put this file in /Library/StartupItems/Barrier . /etc/rc.common BARRIER="/Library/StartupItems/Barrier/barrierc_prelogin" SERVER="192.168.7.101:24800" SCREEN_NAME="Jamies-iMac-Pro.local" cmd="$BARRIER --name $SCREEN_NAME --no-tray -l /tmp/barrier1.log $SERVER" echo $(date) " " $cmd >>/tmp/barrier2.log run=($cmd) KeepAlive () { proc=${1##*/} echo "PID: $proc" while [ -x "$1" ] do echo $(date) " running test" >>/tmp/barrier2.log if ! ps axco command | grep -q "^${proc}\$"; then if ! ps axco command | grep -q "^barrierc\$"; then "$@" echo $(date) " restarting" >>/tmp/barrier2.log else echo $(date) " not restarting as user barrier process is running" >>/tmp/barrier2.log fi fi if [ -f /tmp/barrierc_user_running ]; then echo $(date) " killing root barrierc_prelogin" >>/tmp/barrier2.log killall barrierc_prelogin rm /tmp/barrierc_user_running fi sleep 3 done } StartService () { ConsoleMessage "Starting Barrier" KeepAlive "${run[@]}" & } StopService () { return 0 } RestartService () { return 0 } RunService "$1" 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,22 @@ Open "Terminal" and login as root (type sudo su -) Put the two files "Barrier" and "StartupParameters.plist" in /Library/StartupItems/Barrier/ create the Barrier directory if needed. Change BARRIER, SCREEN_NAME and SERVER to suit your setup. copy the barrierc binary from /Applications/Barrier.app/Contents/MacOS/barrierc to /Library/StartupItems/Barrier/barrierc_prelogin Create a launchd script which creates the file /tmp/barrierc_user_running when you log in. Barrier runs as root pre-login, checks for the presence of the "barrierc_user_running" file, and if so, terminates root's copy of barrierc (barrierc_prelogin) and deletes that file. When you log out, your (user) barrierc process stops, and barrierc_prelogin is restarted as root user. There are probably better ways to do this, I read about logout and login hooks, but their usage is not reccomended by Apple. You might want to get rid of the logging statements in the script, but the logs will go away on reboot anyways, they are just there to help with debugging. Give me a shout if you have any ideas for improvements. 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,6 @@ { Description = "Barrier Client"; Provides = ("Barrier"); Requires = ("Network"); OrderPreference = "None"; }