### Version v1.0.0 2023-12-29 - StevieTV - adapted from servarr script for Sonarr installs
### Version V1.0.1 2024-01-02 - StevieTV - remove UTF8-BOM
### Version V1.0.2 2024-01-03 - markus101 - Get user input from /dev/tty
### Version V1.0.3 2024-01-06 - StevieTV - exit script when it is ran from install directory
### Version V1.0.3 2024-01-06 - StevieTV - exit script when it is ran from install
### Version V1.0.4 2024-04-10 - nostrusdominion - added colors, moved root check, moved architecture check, added title splash screen, improved readablity, changed app_prereq to not bother apt if they are already installed, supressed tarball extraction, add sleep timers.
### Boilerplate Warning
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
#MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
#LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
#OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
#WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
#MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
#LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
#OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
#WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
scriptversion="1.0.3"
scriptdate="2024-01-06"
### Colors
green=$(tput setaf 2)
yellow=$(tput setaf 3)
red=$(tput setaf 1)
orange=$(tput setaf 166)
cyan=$(tput setaf 6)
reset=$(tput sgr0)# No Color
set -euo pipefail
scriptversion="1.0.4"
scriptdate="2024-04-10"
echo"Running Sonarr Install Script - Version [$scriptversion] as of [$scriptdate]"
set -euo pipefail
# Am I root?, need root!
if["$EUID" -ne 0];then
echo"Please run as root."
echo -e ${red}"Please run as root!"
echo -e "Exiting script!"
exit
fi
# Stuff the gremlins needs to know
app="sonarr"
app_port="8989"
app_prereq="curl sqlite3 wget"
app_umask="0002"
branch="main"
# Constants
### Update these variables as required for your specific instance
### Constants
# Update these variables as required for your specific instance
installdir="/opt"# {Update me if needed} Install Location
bindir="${installdir}/${app^}"# Full Path to Install Location
datadir="/var/lib/$app/"# {Update me if needed} AppData directory to use
echo -e " Running version ${orange}[$scriptversion]${reset} as of ${orange}[$scriptdate]${reset}"
# This script should not be ran from installdir, otherwise later in the script the extracted files will be removed before they can be moved to installdir.
echo"You should not run this script from the intended install directory. The script will exit. Please re-run it from another directory"
echo""
echo -e "$ {red}Error!${reset} You should not run this script from the intended install directory."
echo" Please re-run it from another directory."
echo" Exiting Script!"
exit
fi
# User warning about permission conflicts
echo""
echo -e ${red}" WARNING!"${reset}
echo""
echo -e " It is ${red}CRITICAL${reset} that the ${orange}User${reset} and ${orange}Group${reset} you select"
echo -e " to run ${orange}[${app^}]${reset} will have both ${red}READ${reset} and ${red}WRITE${reset} access"
echo -e " to your Media Library and Download Client directories!"${reset}
# Prompt User
read -r -p "What user should ${app^} run as? (Default: $app): " app_uid < /dev/tty
echo""
read -r -p " What user should [${app^}] run as? (Default: $app): " app_uid < /dev/tty
app_uid=$(echo"$app_uid"| tr -d ' ')
app_uid=${app_uid:-$app}
# Prompt Group
read -r -p "What group should ${app^} run as? (Default: media): " app_guid < /dev/tty
echo""
read -r -p " What group should [${app^}] run as? (Default: media): " app_guid < /dev/tty
app_guid=$(echo"$app_guid"| tr -d ' ')
app_guid=${app_guid:-media}
echo"This will install [${app^}] to [$bindir] and use [$datadir] for the AppData Directory"
echo"${app^} will run as the user [$app_uid] and group [$app_guid]. By continuing, you've confirmed that that user and group will have READ and WRITE access to your Media Library and Download Client Completed Download directories"
read -n 1 -r -s -p $'Press enter to continue or ctrl+c to exit...\n' < /dev/tty
# Info for the user and user confirmation
echo""
echo -e "${cyan}[${app^}]${reset} will be installed to ${orange}[$bindir]${reset} and use ${orange}[$datadir]${reset} for the AppData Directory"
echo""
echo -e "${cyan}[${app^}]${reset} will run as the user ${orange}[$app_uid]${reset} and group ${orange}[$app_guid]${reset}."
echo""
echo -e " By continuing, you ${red}CONFIRM${reset} that that ${orange}[$app_uid]${reset} and ${orange}[$app_guid]${reset}"
echo -e " will have both ${red}READ${reset} and ${red}WRITE${reset} access to all required directories."
# User confirmation for installation to continue.
echo""
while true;do
read -r -p " Do you want to continue with the installation? [y/N]: " response