2024-02-03 16:08:56 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
NAME=jellyfin
|
|
|
|
|
DEFAULT_FILE=/etc/default/${NAME}
|
|
|
|
|
|
|
|
|
|
# Source Jellyfin default configuration
|
|
|
|
|
if [[ -f $DEFAULT_FILE ]]; then
|
|
|
|
|
. $DEFAULT_FILE
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
JELLYFIN_USER=${JELLYFIN_USER:-jellyfin}
|
|
|
|
|
RENDER_GROUP=${RENDER_GROUP:-render}
|
|
|
|
|
VIDEO_GROUP=${VIDEO_GROUP:-video}
|
|
|
|
|
|
|
|
|
|
# Data directories for program data (cache, db), configs, and logs
|
|
|
|
|
PROGRAMDATA=${JELLYFIN_DATA_DIRECTORY-/var/lib/$NAME}
|
|
|
|
|
CONFIGDATA=${JELLYFIN_CONFIG_DIRECTORY-/etc/$NAME}
|
|
|
|
|
LOGDATA=${JELLYFIN_LOG_DIRECTORY-/var/log/$NAME}
|
|
|
|
|
CACHEDATA=${JELLYFIN_CACHE_DIRECTORY-/var/cache/$NAME}
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
|
configure)
|
|
|
|
|
# create jellyfin group if it does not exist
|
|
|
|
|
if [[ -z "$(getent group ${JELLYFIN_USER})" ]]; then
|
|
|
|
|
addgroup --quiet --system ${JELLYFIN_USER} > /dev/null 2>&1
|
|
|
|
|
fi
|
|
|
|
|
# create jellyfin user if it does not exist
|
|
|
|
|
if [[ -z "$(getent passwd ${JELLYFIN_USER})" ]]; then
|
|
|
|
|
adduser --system --ingroup ${JELLYFIN_USER} --shell /bin/false ${JELLYFIN_USER} --no-create-home --home ${PROGRAMDATA} \
|
|
|
|
|
--gecos "Jellyfin default user" > /dev/null 2>&1
|
|
|
|
|
fi
|
|
|
|
|
# add jellyfin to the render group for hwa
|
|
|
|
|
if [[ ! -z "$(getent group ${RENDER_GROUP})" ]]; then
|
|
|
|
|
usermod -aG ${RENDER_GROUP} ${JELLYFIN_USER} > /dev/null 2>&1
|
|
|
|
|
fi
|
|
|
|
|
# add jellyfin to the video group for hwa
|
|
|
|
|
if [[ ! -z "$(getent group ${VIDEO_GROUP})" ]]; then
|
|
|
|
|
usermod -aG ${VIDEO_GROUP} ${JELLYFIN_USER} > /dev/null 2>&1
|
|
|
|
|
fi
|
2024-09-03 15:05:23 -04:00
|
|
|
|
2024-09-03 15:02:28 -04:00
|
|
|
# Ensure directories exist and, on initial creation, are chowned to the correct user(s)
|
|
|
|
|
for DIRECTORY in $PROGRAMDATA $CONFIGDATA $LOGDATA $CACHEDATA; do
|
|
|
|
|
if [[ ! -d $DIRECTORY ]]; then
|
|
|
|
|
mkdir -p $DIRECTORY
|
|
|
|
|
fi
|
|
|
|
|
if [[ $(stat -c '%u' $DIRECTORY) -eq 0 ]]; then
|
|
|
|
|
chown -R ${JELLYFIN_USER}:adm $DIRECTORY
|
|
|
|
|
chmod 0750 $DIRECTORY
|
|
|
|
|
fi
|
|
|
|
|
done
|
2024-02-03 16:08:56 -05:00
|
|
|
|
2025-10-23 18:01:02 -04:00
|
|
|
# Refresh ldconfig cache and get libjemalloc.so path
|
|
|
|
|
ldconfig &>/dev/null
|
2025-06-14 22:53:04 -04:00
|
|
|
LIBJEMALLOC_PATH="$( ldconfig -p | grep libjemalloc | awk '{print $NF}' | head -n1 )"
|
2025-10-20 13:43:55 -04:00
|
|
|
if [[ -z ${LIBJEMALLOC_PATH} ]]; then
|
|
|
|
|
# Try to find the path with `find` instead of `ldconfig`; hackier, but a good fallback
|
|
|
|
|
LIBJEMALLOC_PATH="$( find /usr/lib -type f -name "libjemalloc.so*" | head -n1 )"
|
|
|
|
|
fi
|
2025-10-23 18:01:02 -04:00
|
|
|
# Install libjemalloc.so symlink into /usr/lib/jellyfin
|
2025-06-14 22:53:04 -04:00
|
|
|
if [[ -n ${LIBJEMALLOC_PATH} && -f ${LIBJEMALLOC_PATH} ]]; then
|
|
|
|
|
ln -sf ${LIBJEMALLOC_PATH} /usr/lib/jellyfin/libjemalloc.so
|
2025-10-07 09:38:42 -04:00
|
|
|
else
|
2025-10-20 13:43:55 -04:00
|
|
|
echo "failed to find libjemalloc on system; ensure the 'libjemalloc2' package is [being] installed"
|
2025-10-07 09:38:42 -04:00
|
|
|
exit 1
|
2025-06-14 22:53:04 -04:00
|
|
|
fi
|
2025-06-14 22:31:43 -04:00
|
|
|
|
2024-02-03 16:08:56 -05:00
|
|
|
# Install jellyfin symlink into /usr/bin
|
|
|
|
|
ln -sf /usr/lib/jellyfin/bin/jellyfin /usr/bin/jellyfin
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
abort-upgrade|abort-remove|abort-deconfigure)
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "postinst called with unknown argument \`$1'" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
#DEBHELPER
|
|
|
|
|
|
|
|
|
|
if [[ -x "/usr/bin/deb-systemd-helper" ]]; then
|
|
|
|
|
# was-enabled defaults to true, so new installations run enable.
|
|
|
|
|
if deb-systemd-helper --quiet was-enabled jellyfin.service; then
|
|
|
|
|
# Enables the unit on first installation, creates new
|
|
|
|
|
# symlinks on upgrades if the unit file has changed.
|
|
|
|
|
deb-systemd-helper enable jellyfin.service >/dev/null || true
|
|
|
|
|
else
|
|
|
|
|
# Update the statefile to add new symlinks (if any), which need to be
|
|
|
|
|
# cleaned up on purge. Also remove old symlinks.
|
|
|
|
|
deb-systemd-helper update-state jellyfin.service >/dev/null || true
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ "$1" == "configure" ]] || [[ "$1" == "abort-upgrade" ]]; then
|
|
|
|
|
if [[ -d "/run/systemd/system" ]]; then
|
|
|
|
|
systemctl --system daemon-reload >/dev/null || true
|
2024-11-20 22:09:55 -05:00
|
|
|
if [[ -z ${DISABLE_JELLYFIN_AUTOSTART} ]]; then
|
|
|
|
|
deb-systemd-invoke start jellyfin >/dev/null || true
|
|
|
|
|
fi
|
2024-02-03 16:08:56 -05:00
|
|
|
elif [[ -x "/etc/init.d/jellyfin" ]] || [[ -e "/etc/init/jellyfin.conf" ]]; then
|
2024-11-20 22:09:55 -05:00
|
|
|
if [[ -z ${DISABLE_JELLYFIN_AUTOSTART} ]]; then
|
|
|
|
|
update-rc.d jellyfin defaults >/dev/null
|
|
|
|
|
invoke-rc.d jellyfin start || exit $?
|
|
|
|
|
fi
|
2024-02-03 16:08:56 -05:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
exit 0
|