Repository navigation
Expand file tree
/
Copy pathinstall-debuntu.sh
More file actions
executable file
·322 lines (293 loc) · 12.6 KB
/
Copy pathinstall-debuntu.sh
File metadata and controls
executable file
·322 lines (293 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/usr/bin/env bash
shopt -s extglob
# Lists of supported architectures, Debian, and Ubuntu releases
SUPPORTED_ARCHITECTURES='@(amd64|armhf|arm64)'
SUPPORTED_DEBIAN_RELEASES='@(bullseye|bookworm|trixie)'
SUPPORTED_UBUNTU_RELEASES='@(focal|jammy|noble|resolute)'
SCRIPT_URL="https://repo.jellyfin.org/install-debuntu.sh"
GPG_KEY_URL="https://repo.jellyfin.org/jellyfin_team.gpg.key"
DOWNLOADS_URL="https://jellyfin.org/downloads/server"
CONTACT_URL="https://jellyfin.org/contact"
# Fail out if we can't find /etc/apt or /etc/os-release
if [[ ! -d /etc/apt || ! -f /etc/os-release ]]; then
echo "ERROR: Couldn't find the '/etc/apt' directory or '/etc/os-release' manifest."
echo "This script is for Debian-based distributions using APT only. Please consider a Docker-based or manual install instead: ${DOWNLOADS_URL}"
exit 1
fi
# Check that we're root; if not, fail out
if [[ $(whoami) != "root" ]]; then
echo "ERROR: This script must be run as 'root' or with 'sudo' to function."
echo "Try using this command instead: curl ${SCRIPT_URL} | sudo bash"
exit 1
fi
echo "> Determining optimal repository settings."
# Get the (dpkg) architecture and base OS from /etc/os-release
ARCHITECTURE="$( dpkg --print-architecture )"
BASE_OS="$( awk -F'=' '/^ID=/{ print $NF }' /etc/os-release )"
# Validate that we're running on a supported (dpkg) architecture
# shellcheck disable=SC2254
# We cannot quote this extglob expansion or it doesn't work
case "${ARCHITECTURE}" in
${SUPPORTED_ARCHITECTURES})
true
;;
*)
echo "ERROR: We don't support the CPU architecture '${ARCHITECTURE}' with this script."
echo "Please consider a Docker-based or manual install instead: ${DOWNLOADS_URL}"
exit 1
;;
esac
# Handle some known alternative base OS values with 1-to-1 mappings
# Use the result as our repository base OS
case "${BASE_OS}" in
raspbian)
# Raspbian uses our Debian repository
REPO_OS="debian"
VERSION="$( awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release )"
;;
neon)
# Neon uses our Ubuntu repository
REPO_OS="ubuntu"
VERSION="$( awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release )"
;;
tuxedo)
REPO_OS="ubuntu"
VERSION="$( awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release )"
;;
*)
# Try to determine upstream info automatically (e.g. Linux Mint)
if grep -q "DEBIAN_CODENAME=" /etc/os-release &>/dev/null; then
REPO_OS="debian"
VERSION="$( awk -F'=' '/^DEBIAN_CODENAME=/{ print $NF }' /etc/os-release )"
elif grep -q "UBUNTU_CODENAME=" /etc/os-release &>/dev/null; then
REPO_OS="ubuntu"
VERSION="$( awk -F'=' '/^UBUNTU_CODENAME=/{ print $NF }' /etc/os-release )"
else
REPO_OS="${BASE_OS}"
VERSION="$( awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release )"
fi
;;
esac
# Validate that we're running a supported release (variables at top of file)
case "${REPO_OS}" in
debian)
# shellcheck disable=SC2254
# We cannot quote this extglob expansion or it doesn't work
case "${VERSION}" in
${SUPPORTED_DEBIAN_RELEASES})
true
;;
*)
echo "ERROR: We don't support the Debian codename '${VERSION}' with this script."
echo "Note: We only support stable versions of Debian."
echo "Please consider a Docker-based or manual install instead: ${DOWNLOADS_URL}"
exit 1
;;
esac
;;
ubuntu)
# shellcheck disable=SC2254
# We cannot quote this extglob expansion or it doesn't work
case "${VERSION}" in
${SUPPORTED_UBUNTU_RELEASES})
true
;;
*)
echo "ERROR: We don't support the Ubuntu codename '${VERSION}' with this script."
echo "Note: We only support LTS versions of Ubuntu."
echo "Please consider a Docker-based or manual install instead: ${DOWNLOADS_URL}"
exit 1
;;
esac
;;
*)
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
echo -e "${YELLOW}WARNING${NC}: Autodetection of base OS and version failed."
echo -e "To continue, please enter the following as 'Repo OS' and 'Repo Release', respectively::"
echo -e " (1) The upstream distribution of your current distro (either 'debian' or 'ubuntu')."
echo -e " (2) The closest upstream release codename of your current distro ('bookworm', 'focal', etc.)."
echo -e "If you do not know, please consult your distribution's documentation, or try the latest Ubuntu LTS details."
echo
echo -en "Repo OS: "
read -r REPO_OS < /dev/tty
echo -en "Repo Release: "
read -r VERSION < /dev/tty
;;
esac
# Perform free space checks on default locations (`/var/lib/jellyfin` and `/tmp`)
echo "> Checking for free space and known-problematic filesystem targets."
read DATA_FREE DATA_FSTYPE <<< "$( df --block-size=1K --output=avail,fstype /var/lib | tail -1 )"
if [[ ${DATA_FREE} -lt $(( 2 * 1024 * 1024 )) ]]; then
echo "Insufficient free space for /var/lib/jellyfin: ${DATA_FREE}KB found, $(( 2 * 1024 * 1024 ))KB required"
echo
echo "Please free up space and try again."
exit 1
else
echo ">> OK: Data directory has $(( ${DATA_FREE} / 1024 ))MB of available space."
fi
if [[ " nfs ceph " =~ " ${DATA_FSTYPE} " ]]; then
echo "ERROR: Data directory target is on network storage. This configuration is NOT SUPPORTED."
echo "Install Jellyfin manually and move your data directory target to a non-network filesystem."
exit 1
elif [[ " zfs btrfs bcachefs " =~ " ${DATA_FSTYPE} " ]]; then
echo ">> WARNING: Data directory on COW storage. This is probably fine, but issues have been reported in the past."
else
echo ">> OK: Data directory on ${DATA_FSTYPE}, this is supported."
fi
read TMP_FREE TMP_FSTYPE <<< "$( df --block-size=1K --output=avail,fstype /tmp | tail -1 )"
if [[ ${TMP_FREE} -lt $(( 1024 * 1024 )) ]]; then
echo "Insufficient free space for /tmp: ${TMP_FREE}KB found, $(( 1024 * 1024 ))KB required"
echo
echo "Please increase tmpfs size or free up space and try again."
exit 1
else
echo ">> OK: Temporary directory has $(( ${TMP_FREE} / 1024 ))MB of available space."
fi
if [[ " nfs ceph " =~ " ${TMP_FSTYPE} " ]]; then
echo "ERROR: Temporary directory target is on network storage. This configuration is NOT SUPPORTED."
echo "Install Jellyfin manually and move your temporary directory target to a non-network filesystem."
exit 1
elif [[ " zfs btrfs bcachefs " =~ " ${TMP_FSTYPE} " ]]; then
echo ">> WARNING: Temporary directory on COW storage. This is probably fine, but issues have been reported in the past."
else
echo ">> OK: Temporary directory on ${TMP_FSTYPE}, this is supported."
fi
echo
echo -e "Found the following details from '/etc/os-release':"
echo -e " Real OS: ${BASE_OS}"
echo -e " Repository OS: ${REPO_OS}"
echo -e " Repository Release: ${VERSION}"
echo -e " CPU Architecture: ${ARCHITECTURE}"
echo -en "If this looks correct, press <Enter> now to continue installing Jellyfin. "
# Use < /dev/tty construct to ensure we stop even in a curl|bash scenario
# See https://stackoverflow.com/a/6562852/5253131
# shellcheck disable=SC2162
# We are OK with this read stripping backslashes, as it is just a pause and is discarded
# Use SKIP_CONFIRM in the environment to skip this read check (PR#10)
if [[ ! "${SKIP_CONFIRM,,}" =~ ^(true|1)$ ]]; then
read -r < /dev/tty
fi
echo
# Get the paths to curl and wget
CURL=$( which curl )
WGET=$( which wget )
# Create our array of to-be-installed packages
INSTALL_PKGS=()
# Pick our optimal fetching program (curl, then wget, then install curl)
if [[ -n ${CURL} ]]; then
FETCH="${CURL} -fsSL"
elif [[ -n ${WGET} ]]; then
FETCH="${WGET} -O-"
else
echo "Failed to find a suitable download program. We're not sure how you downloaded this script, but we'll install 'curl' automatically."
# shellcheck disable=SC2206
# We are OK with word-splitting here since we control the contents
INSTALL_PKGS=( ${INSTALL_PKGS[@]} curl )
FETCH="${CURL} -fsSL"
echo
fi
# Get the path to gpg or install it
GNUPG=$( which gpg )
if [[ -z ${GNUPG} ]]; then
echo "Failed to find the GNUPG binary, but we'll install 'gnupg' automatically."
# shellcheck disable=SC2206
# We are OK with word-splitting here since we control the contents
INSTALL_PKGS=( ${INSTALL_PKGS[@]} gnupg )
echo
fi
# If we have at least 1 dependency package to install (either curl or gnupg), do so
if [[ ${#INSTALL_PKGS[@]} -gt 0 ]]; then
echo "> Updating APT repositories."
apt update
echo
echo "> Installing required dependencies."
apt install --yes "${INSTALL_PKGS[@]}"
echo
fi
# If the keyring directory is absent, create it
if [[ ! -d /etc/apt/keyrings ]]; then
echo "> Creating APT keyring directory."
mkdir -p /etc/apt/keyrings
echo
fi
# Download our repository signing key and install it to the keyring directory
echo "> Fetching repository signing key."
$FETCH ${GPG_KEY_URL} | gpg --dearmor --yes --output /etc/apt/keyrings/jellyfin.gpg
# shellcheck disable=SC2181
# We don't want to explicitly include the command in the 'if' for readability
if [[ $? -gt 0 ]]; then
echo "ERROR: Failed to install key. Use ${CONTACT_URL} to find us for troubleshooting."
exit 1
fi
chmod 644 /etc/apt/keyrings/jellyfin.gpg
echo
# Check for and remove the obsoleted jellyfin.list configuration if present
if [[ -f /etc/apt/sources.list.d/jellyfin.list ]]; then
echo "> Found old-style '/etc/apt/sources.list.d/jellyfin.list' configuration; removing it."
rm -f /etc/apt/sources.list.d/jellyfin.list
echo
fi
# Install the Deb822 format jellyfin.sources entry
echo "> Installing Jellyfin repository into APT."
cat <<EOF | tee /etc/apt/sources.list.d/jellyfin.sources
Types: deb
URIs: https://repo.jellyfin.org/${REPO_OS}
Suites: ${VERSION}
Components: main
Architectures: ${ARCHITECTURE}
Signed-By: /etc/apt/keyrings/jellyfin.gpg
EOF
echo
# Update the apt repositories to fetch the new Jellyfin repository
echo "> Updating APT repositories."
apt update
# shellcheck disable=SC2181
# We don't want to explicitly include the command in the 'if' for readability
if [[ $? -gt 0 ]]; then
echo "ERROR: Failed to update APT repositories. Something is wrong with your APT sources, GPG keys, or Internet connection. Try again shortly or use ${CONTACT_URL} to find us for troubleshooting."
exit 1
fi
echo
# Install Jellyfin using the metapackage (which will fetch jellyfin-server, jellyfin-web, and jellyfin-ffmpeg[5]
echo "> Installing Jellyfin."
apt install --yes jellyfin
# shellcheck disable=SC2181
# We don't want to explicitly include the command in the 'if' for readability
if [[ $? -gt 0 ]]; then
echo "ERROR: Failed to install Jellyfin. Use ${CONTACT_URL} to find us for troubleshooting."
exit 1
fi
# Works around https://github.com/jellyfin/jellyfin-packaging/issues/37 for now
chown -R jellyfin:adm /etc/jellyfin
echo
# Wait for Jellyfin to actually start up, preempting quick users who might click the link below too quickly
echo "> Waiting 15 seconds for Jellyfin to fully start up."
sleep 15
echo
# Output the result of systemctl status (or service status for init.d/upstart) to validate Jellyfin is running
echo "-------------------------------------------------------------------------------"
export SYSTEMD_PAGER=
systemctl status jellyfin.service || service jellyfin status
echo "-------------------------------------------------------------------------------"
echo
# Determine the IP address of the interface which contains the default gateway
# This is a relatively sure bet to be the IP address that Jellyfin can be accessed on, for later display
GATEWAY_IFACE="$( ip route \
| grep '^default' \
| head -1 \
| grep -o 'dev [a-z0-9]* ' \
| awk '{ print $NF }' )"
IP_ADDRESS="$( ip address show dev "${GATEWAY_IFACE}" \
| grep -w "inet .* ${GATEWAY_IFACE}$" \
| awk '{ print $2 }' \
| awk -F '/' '{ print $1 }' )"
# Output the explanation of the above output, next-step including link with IP address/port, and welcome message
echo "You should see the service as 'active (running)' above. If not, use ${CONTACT_URL} to find us for troubleshooting."
echo
echo "You can access your new instance now at http://${IP_ADDRESS}:8096 in your web browser to finish setting up Jellyfin."
echo
echo "Thank you for installing Jellyfin, and happy watching!"
echo
# Explicitly exit cleanly
exit 0