-
-
Save keybits/f7d6d16f1972b3f1aaf906f83a45b56c to your computer and use it in GitHub Desktop.
Enable Syncthing automatic startup on login in macOS
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 characters
#!/bin/bash | |
#---------------------------------------------------- | |
# | |
# Copyright (C) 2017 Vlad Didenko | |
# | |
# This Source Code Form is subject to the terms | |
# of the Mozilla Public License, v. 2.0. If a copy | |
# of the MPL was not distributed with this file, | |
# You can obtain one at https://mozilla.org/MPL/2.0/ | |
# | |
#---------------------------------------------------- | |
# InstallDir is where the Syncthing software was copied to. | |
# To use the browser-based software update feature this folder | |
# and files in it should be writeable by the user running the | |
# Synching. | |
InstallDir=/Applications/Syncthing | |
# A directory dedicated for Syncthing logs | |
LogDir=${HOME}/Library/Logs/Syncthing | |
# LaunchAgent location | |
LaunchAgentDir=${HOME}/Library/LaunchAgents | |
# Launch Agent file name | |
LaunchAgentFile=local.syncthing.plist | |
# ServiceId is the identifier used by the launchd and launchctl | |
ServiceId=local.syncthing | |
# End of configuration | |
# | |
############################# | |
laf=${LaunchAgentDir}/${LaunchAgentFile} | |
function WriteLaunchAgent { | |
if [ -f "${laf}" ] | |
then | |
echo LaunchAgent file already exists at \"${laf}\". Please, review the file and delete it if nesessary before running this installation. 1>&2 | |
exit 1 | |
fi | |
cat > ${laf} <<EndPlist | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>${ServiceId}</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>${InstallDir}/syncthing</string> | |
<string>-no-browser</string> | |
</array> | |
<key>KeepAlive</key> | |
<true/> | |
<key>ThrottleInterval</key> | |
<integer>60</integer> | |
<key>LowPriorityIO</key> | |
<true/> | |
<key>ProcessType</key> | |
<string>Background</string> | |
<key>StandardOutPath</key> | |
<string>${LogDir}/Syncthing.out.log</string> | |
<key>StandardErrorPath</key> | |
<string>${LogDir}/Syncthing.err.log</string> | |
</dict> | |
</plist> | |
EndPlist | |
} | |
function DeleteLaunchAgent { | |
if [ ! -f "${laf}" ] | |
then | |
echo LaunchAgent file not found at \"${laf}\". Nothing to remove. 1>&2 | |
exit 1 | |
fi | |
rm "${laf}" | |
} | |
case ${1} in | |
enable) | |
WriteLaunchAgent | |
;; | |
disable) | |
DeleteLaunchAgent | |
;; | |
start) | |
launchctl load "${laf}" | |
;; | |
stop) | |
launchctl unload "${laf}" | |
;; | |
*) | |
echo Allowed commands are: enable, disable, start, and stop. 1>&2 | |
exit 1 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment