Skip to content

Commit c3c5049

Browse files
Qstickstevietv
andcommittedFeb 6, 2024
Debian Install Script
Closes #4382 Closes #4383 Closes #4401 Closes #4407 Closes #4423 Closes #4474 Co-Authored-By: Stevie Robinson <stevie.robinson@gmail.com>
1 parent 6ae99ac commit c3c5049

File tree

2 files changed

+202
-0
lines changed

2 files changed

+202
-0
lines changed
 

‎distribution/debian/install.sh

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
#!/bin/bash
2+
### Description: Lidarr .NET Debian install
3+
### Originally written for Radarr by: DoctorArr - doctorarr@the-rowlands.co.uk on 2021-10-01 v1.0
4+
### Updates for servarr suite made by Bakerboy448, DoctorArr, brightghost, aeramor and VP-EN
5+
### Version v1.0.0 2023-12-29 - StevieTV - adapted from servarr script for Lidarr installs
6+
### Version V1.0.1 2024-01-02 - StevieTV - remove UTF8-BOM
7+
### Version V1.0.2 2024-01-03 - markus101 - Get user input from /dev/tty
8+
### Version V1.0.3 2024-01-06 - StevieTV - exit script when it is ran from install directory
9+
10+
### Boilerplate Warning
11+
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12+
#EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13+
#MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14+
#NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
15+
#LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
16+
#OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
17+
#WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18+
19+
scriptversion="1.0.3"
20+
scriptdate="2024-01-06"
21+
22+
set -euo pipefail
23+
24+
echo "Running Lidarr Install Script - Version [$scriptversion] as of [$scriptdate]"
25+
26+
# Am I root?, need root!
27+
28+
if [ "$EUID" -ne 0 ]; then
29+
echo "Please run as root."
30+
exit
31+
fi
32+
33+
app="lidarr"
34+
app_port="8686"
35+
app_prereq="curl sqlite3 wget"
36+
app_umask="0002"
37+
branch="main"
38+
39+
# Constants
40+
### Update these variables as required for your specific instance
41+
installdir="/opt" # {Update me if needed} Install Location
42+
bindir="${installdir}/${app^}" # Full Path to Install Location
43+
datadir="/var/lib/$app/" # {Update me if needed} AppData directory to use
44+
app_bin=${app^} # Binary Name of the app
45+
46+
# 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.
47+
if [ "$installdir" == "$(dirname -- "$( readlink -f -- "$0"; )")" ] || [ "$bindir" == "$(dirname -- "$( readlink -f -- "$0"; )")" ]; then
48+
echo "You should not run this script from the intended install directory. The script will exit. Please re-run it from another directory"
49+
exit
50+
fi
51+
52+
# Prompt User
53+
read -r -p "What user should ${app^} run as? (Default: $app): " app_uid < /dev/tty
54+
app_uid=$(echo "$app_uid" | tr -d ' ')
55+
app_uid=${app_uid:-$app}
56+
# Prompt Group
57+
read -r -p "What group should ${app^} run as? (Default: media): " app_guid < /dev/tty
58+
app_guid=$(echo "$app_guid" | tr -d ' ')
59+
app_guid=${app_guid:-media}
60+
61+
echo "This will install [${app^}] to [$bindir] and use [$datadir] for the AppData Directory"
62+
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"
63+
read -n 1 -r -s -p $'Press enter to continue or ctrl+c to exit...\n' < /dev/tty
64+
65+
# Create User / Group as needed
66+
if [ "$app_guid" != "$app_uid" ]; then
67+
if ! getent group "$app_guid" >/dev/null; then
68+
groupadd "$app_guid"
69+
fi
70+
fi
71+
if ! getent passwd "$app_uid" >/dev/null; then
72+
adduser --system --no-create-home --ingroup "$app_guid" "$app_uid"
73+
echo "Created and added User [$app_uid] to Group [$app_guid]"
74+
fi
75+
if ! getent group "$app_guid" | grep -qw "$app_uid"; then
76+
echo "User [$app_uid] did not exist in Group [$app_guid]"
77+
usermod -a -G "$app_guid" "$app_uid"
78+
echo "Added User [$app_uid] to Group [$app_guid]"
79+
fi
80+
81+
# Stop the App if running
82+
if service --status-all | grep -Fq "$app"; then
83+
systemctl stop "$app"
84+
systemctl disable "$app".service
85+
echo "Stopped existing $app"
86+
fi
87+
88+
# Create Appdata Directory
89+
90+
# AppData
91+
mkdir -p "$datadir"
92+
chown -R "$app_uid":"$app_guid" "$datadir"
93+
chmod 775 "$datadir"
94+
echo "Directories created"
95+
# Download and install the App
96+
97+
# prerequisite packages
98+
echo ""
99+
echo "Installing pre-requisite Packages"
100+
# shellcheck disable=SC2086
101+
apt update && apt install -y $app_prereq
102+
echo ""
103+
ARCH=$(dpkg --print-architecture)
104+
# get arch
105+
dlbase="https://lidarr.servarr.com/v1/update/$branch/updatefile?os=linux&runtime=netcore"
106+
case "$ARCH" in
107+
"amd64") DLURL="${dlbase}&arch=x64" ;;
108+
"armhf") DLURL="${dlbase}&arch=arm" ;;
109+
"arm64") DLURL="${dlbase}&arch=arm64" ;;
110+
*)
111+
echo "Arch not supported"
112+
exit 1
113+
;;
114+
esac
115+
echo ""
116+
echo "Removing previous tarballs"
117+
# -f to Force so we fail if it doesnt exist
118+
rm -f "${app^}".*.tar.gz
119+
echo ""
120+
echo "Downloading..."
121+
wget --content-disposition "$DLURL"
122+
tar -xvzf "${app^}".*.tar.gz
123+
echo ""
124+
echo "Installation files downloaded and extracted"
125+
126+
# remove existing installs
127+
echo "Removing existing installation"
128+
rm -rf "$bindir"
129+
echo "Installing..."
130+
mv "${app^}" $installdir
131+
chown "$app_uid":"$app_guid" -R "$bindir"
132+
chmod 775 "$bindir"
133+
rm -rf "${app^}.*.tar.gz"
134+
# Ensure we check for an update in case user installs older version or different branch
135+
touch "$datadir"/update_required
136+
chown "$app_uid":"$app_guid" "$datadir"/update_required
137+
echo "App Installed"
138+
# Configure Autostart
139+
140+
# Remove any previous app .service
141+
echo "Removing old service file"
142+
rm -rf /etc/systemd/system/"$app".service
143+
144+
# Create app .service with correct user startup
145+
echo "Creating service file"
146+
cat <<EOF | tee /etc/systemd/system/"$app".service >/dev/null
147+
[Unit]
148+
Description=${app^} Daemon
149+
After=syslog.target network.target
150+
[Service]
151+
User=$app_uid
152+
Group=$app_guid
153+
UMask=$app_umask
154+
Type=simple
155+
ExecStart=$bindir/$app_bin -nobrowser -data=$datadir
156+
TimeoutStopSec=20
157+
KillMode=process
158+
Restart=on-failure
159+
[Install]
160+
WantedBy=multi-user.target
161+
EOF
162+
163+
# Start the App
164+
echo "Service file created. Attempting to start the app"
165+
systemctl -q daemon-reload
166+
systemctl enable --now -q "$app"
167+
168+
# Finish Update/Installation
169+
host=$(hostname -I)
170+
ip_local=$(grep -oP '^\S*' <<<"$host")
171+
echo ""
172+
echo "Install complete"
173+
sleep 10
174+
STATUS="$(systemctl is-active "$app")"
175+
if [ "${STATUS}" = "active" ]; then
176+
echo "Browse to http://$ip_local:$app_port for the ${app^} GUI"
177+
else
178+
echo "${app^} failed to start"
179+
fi
180+
181+
# Exit
182+
exit 0

‎distribution/debian/lidarr.service

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This file is owned by the lidarr package, DO NOT MODIFY MANUALLY
2+
# Instead use 'dpkg-reconfigure -plow lidarr' to modify User/Group/UMask/-data
3+
# Or use systemd built-in override functionality using 'systemctl edit lidarr'
4+
[Unit]
5+
Description=Lidarr Daemon
6+
After=network.target
7+
8+
[Service]
9+
User=lidarr
10+
Group=lidarr
11+
UMask=002
12+
13+
Type=simple
14+
ExecStart=/opt/Lidarr/Lidarr -nobrowser -data=/var/lib/lidarr
15+
TimeoutStopSec=20
16+
KillMode=process
17+
Restart=on-failure
18+
19+
[Install]
20+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)
Please sign in to comment.