2019-03-10 01:06:18 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-03-10 20:49:26 +00:00
|
|
|
# If you have problems installing Jackett, please open an issue on
|
|
|
|
# https://github.com/Jackett/Jackett/issues
|
|
|
|
|
|
|
|
# Setting up colors
|
2019-03-10 01:06:18 +00:00
|
|
|
BOLDRED="$(printf '\033[1;31m')"
|
|
|
|
BOLDGREEN="$(printf '\033[1;32m')"
|
|
|
|
NC="$(printf '\033[0m')" # No Color
|
|
|
|
|
2020-03-10 20:49:26 +00:00
|
|
|
# Check if the install script is running as root
|
|
|
|
if [ "$EUID" -ne 0 ]; then
|
|
|
|
echo "${BOLDRED}ERROR${NC}: Please run this script as root"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if Jackett service is running
|
|
|
|
JACKETT_SERVICE="jackett.service"
|
|
|
|
echo "Checking if the service '${JACKETT_SERVICE}' is running ..."
|
|
|
|
if systemctl is-active --quiet "${JACKETT_SERVICE}"; then
|
|
|
|
echo "Service '${JACKETT_SERVICE}' is running"
|
|
|
|
|
|
|
|
# Stop and unload the service
|
|
|
|
if systemctl stop "${JACKETT_SERVICE}"; then
|
|
|
|
echo "Service '${JACKETT_SERVICE}' stopped"
|
|
|
|
else
|
|
|
|
echo "${BOLDRED}ERROR${NC}: The service '${JACKETT_SERVICE}' Can not be stopped"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
echo "Service '${JACKETT_SERVICE}' is not running"
|
|
|
|
fi
|
2019-03-10 01:06:18 +00:00
|
|
|
|
|
|
|
# Move working directory to Jackett's
|
2020-03-10 20:49:26 +00:00
|
|
|
JACKETT_DIR="$(dirname "$(readlink -f "$0")")"
|
|
|
|
echo "Jackett will be installed in '${JACKETT_DIR}'"
|
|
|
|
if ! cd "${JACKETT_DIR}"; then
|
|
|
|
echo "${BOLDRED}ERROR${NC}: Can not cd into '${JACKETT_DIR}' folder"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-03-10 01:06:18 +00:00
|
|
|
|
|
|
|
# Check if we're running from Jackett's directory
|
|
|
|
if [ ! -f ./jackett ]; then
|
2020-03-10 20:49:26 +00:00
|
|
|
echo "${BOLDRED}ERROR${NC}: Can not locate 'jackett' file in '${JACKETT_DIR}'."
|
|
|
|
echo "Is the script in the right directory?"
|
2019-03-10 01:06:18 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if Jackett's owner is root
|
2020-03-10 20:49:26 +00:00
|
|
|
JACKETT_USER="$(stat -c "%U" ./jackett)"
|
|
|
|
if [ "${JACKETT_USER}" == "root" ] || [ "${JACKETT_USER}" == "UNKNOWN" ] ; then
|
|
|
|
echo "${BOLDRED}ERROR${NC}: The owner of Jackett directory is '${JACKETT_USER}'."
|
|
|
|
echo "Please, change the owner with the command 'chown <user>:<user> -R \"${JACKETT_DIR}\"'"
|
|
|
|
echo "The user <user> will be used to run Jackett."
|
2019-03-10 01:06:18 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2020-03-10 20:49:26 +00:00
|
|
|
echo "Jackett will be executed with the user '${JACKETT_USER}'"
|
2019-03-10 01:06:18 +00:00
|
|
|
|
|
|
|
# Write the systemd service descriptor
|
2020-03-10 20:49:26 +00:00
|
|
|
JACKETT_SERVICE_PATH="/etc/systemd/system/${JACKETT_SERVICE}"
|
|
|
|
echo "Creating Jackett unit file in '${JACKETT_SERVICE_PATH}' ..."
|
|
|
|
cat > "${JACKETT_SERVICE_PATH}" <<EOL
|
2019-03-10 01:06:18 +00:00
|
|
|
[Unit]
|
|
|
|
Description=Jackett Daemon
|
|
|
|
After=network.target
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
SyslogIdentifier=jackett
|
|
|
|
Restart=always
|
|
|
|
RestartSec=5
|
|
|
|
Type=simple
|
2020-03-10 20:49:26 +00:00
|
|
|
User=${JACKETT_USER}
|
|
|
|
Group=${JACKETT_USER}
|
|
|
|
WorkingDirectory=${JACKETT_DIR}
|
2023-10-20 15:00:00 +00:00
|
|
|
Environment="DOTNET_EnableDiagnostics=0"
|
2020-03-10 20:49:26 +00:00
|
|
|
ExecStart=/bin/sh "${JACKETT_DIR}/jackett_launcher.sh"
|
|
|
|
TimeoutStopSec=30
|
2019-03-10 01:06:18 +00:00
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
|
|
|
|
EOL
|
2020-03-10 20:49:26 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "${BOLDRED}ERROR${NC}: Can not create the file '${JACKETT_SERVICE_PATH}'"
|
|
|
|
echo "The UnitPath of systemd changes from one distribution to another. You may have to edit the script and change the path manually."
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-03-10 01:06:18 +00:00
|
|
|
|
2020-03-10 20:49:26 +00:00
|
|
|
echo "Installing Jackett service ..."
|
2019-03-10 01:06:18 +00:00
|
|
|
# Reload systemd daemon
|
2020-03-10 20:49:26 +00:00
|
|
|
if ! systemctl daemon-reload; then
|
|
|
|
echo "${BOLDRED}ERROR${NC}: Can not reload systemd daemon"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-03-10 01:06:18 +00:00
|
|
|
|
|
|
|
# Enable the service for following restarts
|
2020-03-10 20:49:26 +00:00
|
|
|
if ! systemctl enable "${JACKETT_SERVICE}"; then
|
|
|
|
echo "${BOLDRED}ERROR${NC}: Can not enable the service '${JACKETT_SERVICE}'"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-03-10 01:06:18 +00:00
|
|
|
|
|
|
|
# Run the service
|
2020-03-10 20:49:26 +00:00
|
|
|
if systemctl start "${JACKETT_SERVICE}"; then
|
|
|
|
echo "${BOLDGREEN}Service successfully installed and launched!${NC}"
|
2019-03-10 01:06:18 +00:00
|
|
|
else
|
2020-03-10 20:49:26 +00:00
|
|
|
echo "${BOLDRED}ERROR${NC}: Can not start the service '${JACKETT_SERVICE}'"
|
|
|
|
exit 1
|
2019-03-10 01:06:18 +00:00
|
|
|
fi
|