Skip to content

Instantly share code, notes, and snippets.

@xrpdevs
Created July 6, 2021 17:53
Show Gist options
  • Save xrpdevs/b53c9962dd72ffce2cdd6bd9d4d87f28 to your computer and use it in GitHub Desktop.
Save xrpdevs/b53c9962dd72ffce2cdd6bd9d4d87f28 to your computer and use it in GitHub Desktop.
Running Barrier pre-login on Mac OS
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.
#!/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"
{
Description = "Barrier Client";
Provides = ("Barrier");
Requires = ("Network");
OrderPreference = "None";
}
@timfea926
Copy link

Create a launchd script which creates the file /tmp/barrierc_user_running when you log in.

How do I create this launchd script?

I am a noob and I too have this question. It would be nice to have an "dummy" version of this tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment