Skip to content

Instantly share code, notes, and snippets.

@johnnorro
Created January 9, 2019 11:36
Show Gist options
  • Save johnnorro/68584fa1a1ceecc2cf7bfef68f7bbf6e to your computer and use it in GitHub Desktop.
Save johnnorro/68584fa1a1ceecc2cf7bfef68f7bbf6e to your computer and use it in GitHub Desktop.
Autokinit for Mac
#!/bin/sh -e
autokinitFile=~/Library/LaunchAgents/autokinit.plist
if [ -e "$autokinitFile" ]
then
echo "autokinit service already exists"
cat "$autokinitFile"
read -p "Do you wish to remove it? [yN]: " overwrite
if [ "$overwrite" = "y" ]
then
launchctl unload "$autokinitFile"
rm "$autokinitFile"
else
exit
fi
fi
read -p "Please enter your kerberos principal (e.g. user@DOMAIN.COM): " principal
kinit --keychain "$principal"
cat >"$autokinitFile" <<END
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>autokinit</string>
<key>LowPriorityIO</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/kinit</string>
<string>$principal</string>
</array>
<key>WatchPaths</key>
<array>
<string>/etc/resolv.conf</string>
<string>/var/run/resolv.conf</string>
<string>/private/var/run/resolv.conf</string>
</array>
<key>StartInterval</key>
<integer>3600</integer>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
END
launchctl load "$autokinitFile"
echo "Success 😎"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment