2020-06-09 19:30:14 +00:00
|
|
|
#!/bin/zsh
|
2019-03-24 04:57:11 +00:00
|
|
|
|
2020-06-09 19:30:14 +00:00
|
|
|
# Setting up colors
|
2019-03-24 04:57:11 +00:00
|
|
|
BOLDRED="$(printf '\033[1;31m')"
|
|
|
|
BOLDGREEN="$(printf '\033[1;32m')"
|
|
|
|
NC="$(printf '\033[0m')" # No Color
|
|
|
|
|
|
|
|
# Stop and unload the service if it's running
|
2020-06-10 04:24:12 +00:00
|
|
|
launchctl unload ~/Library/LaunchAgents/org.user.Jackett.plist &>/dev/null
|
2019-03-24 04:57:11 +00:00
|
|
|
|
|
|
|
# Move working directory to Jackett's
|
|
|
|
cd "$(dirname "$0")"
|
|
|
|
|
|
|
|
# Check if we're running from Jackett's directory
|
|
|
|
if [ ! -f ./jackett ]; then
|
|
|
|
echo "${BOLDRED}ERROR${NC}: Couldn't locate ./jackett - Is the script in the right directory?"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
jackettdir="$(pwd)"
|
|
|
|
|
|
|
|
# Check that no other service called Jackett is already running
|
|
|
|
if [[ $(launchctl list | grep org.user.Jackett) ]]; then
|
|
|
|
echo "${BOLDRED}ERROR${NC}: Jackett already seems to be running as a service. Please stop it before running this script again."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Write the plist to LaunchAgents
|
|
|
|
mkdir -p ~/Library/LaunchAgents/
|
|
|
|
cat >~/Library/LaunchAgents/org.user.Jackett.plist <<EOL
|
|
|
|
<?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>EnvironmentVariables</key>
|
|
|
|
<dict>
|
|
|
|
<key>PATH</key>
|
|
|
|
<string>/usr/bin:/bin:/usr/sbin:/sbin</string>
|
|
|
|
</dict>
|
|
|
|
<key>KeepAlive</key>
|
|
|
|
<true/>
|
|
|
|
<key>Label</key>
|
|
|
|
<string>org.user.Jackett</string>
|
|
|
|
<key>ProgramArguments</key>
|
|
|
|
<array>
|
|
|
|
<string>${jackettdir}/jackett</string>
|
|
|
|
<string>--NoRestart</string>
|
|
|
|
</array>
|
|
|
|
<key>RunAtLoad</key>
|
|
|
|
<true/>
|
|
|
|
<key>WorkingDirectory</key>
|
|
|
|
<string>${jackettdir}</string>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
|
|
|
|
EOL
|
|
|
|
|
2020-06-09 19:30:14 +00:00
|
|
|
# Un-quarantine all dylib and DLL files
|
2020-06-10 04:24:12 +00:00
|
|
|
qstr="$(xattr -p com.apple.quarantine jackett)" 2>/dev/null
|
|
|
|
if [[ $qstr ]]; then
|
|
|
|
echo "Removing Jackett executable and all .dylib and .dll files from quarantine..."
|
|
|
|
qstr="00c1${qstr:4}"
|
|
|
|
xattr -w com.apple.quarantine $qstr jackett
|
|
|
|
xattr -w com.apple.quarantine $qstr *.{dylib,dll}
|
|
|
|
fi
|
2020-06-09 19:30:14 +00:00
|
|
|
|
2019-03-24 04:57:11 +00:00
|
|
|
# Run the agent
|
|
|
|
launchctl load ~/Library/LaunchAgents/org.user.Jackett.plist
|
|
|
|
|
2020-06-17 20:09:55 +00:00
|
|
|
# Check that it's launched
|
|
|
|
userid=$(id -u)
|
2019-03-24 04:57:11 +00:00
|
|
|
if [[ $(launchctl list | grep org.user.Jackett) ]]; then
|
2020-06-17 20:09:55 +00:00
|
|
|
if [[ $(launchctl print gui/${userid}/org.user.Jackett | grep 'state') =~ "running" ]]; then
|
|
|
|
echo "${BOLDGREEN}Agent successfully installed and running!${NC}"
|
|
|
|
echo "Jackett location: ${jackettdir}"
|
|
|
|
echo "Jackett agent:"
|
|
|
|
launchctl print gui/${userid}/org.user.Jackett | egrep 'state|pid |path|working'
|
|
|
|
else
|
|
|
|
cat << EOL
|
|
|
|
${BOLDRED}ERROR${NC}: Agent was loaded but is not running. The installation might have failed.
|
2019-03-24 04:57:11 +00:00
|
|
|
Please open an issue on https://github.com/Jackett/Jackett/issues and paste following information:
|
2020-06-17 20:09:55 +00:00
|
|
|
*Jackett directory*: ${jackettdir}
|
|
|
|
*launchctl info*:
|
|
|
|
$(launchctl print gui/${userid}/org.user.Jackett)
|
|
|
|
*LaunchAgents permissions*:
|
|
|
|
$(ls -la ~/Library/LaunchAgents | egrep ' \.|Jackett')
|
2019-03-24 04:57:11 +00:00
|
|
|
|
|
|
|
EOL
|
2020-06-17 20:09:55 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "${BOLDRED}ERROR${NC}: Agent could not be loaded. Please open an issue on https://github.com/Jackett/Jackett/issues and paste the output."
|
|
|
|
echo "*Jackett directory*: ${jackettdir}"
|
|
|
|
echo "*LaunchAgents permissions*:"
|
|
|
|
ls -la ~/Library/LaunchAgents | egrep ' \.|Jackett'
|
2019-03-24 04:57:11 +00:00
|
|
|
fi
|