aboutsummaryrefslogtreecommitdiff
path: root/debian/jellyfin-server.postinst
blob: 947959aa7a8417ec8e845b38aea4ab3e0092648f (plain)
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
#!/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
    # ensure $PROGRAMDATA exists
    if [[ ! -d $PROGRAMDATA ]]; then
      mkdir $PROGRAMDATA
    fi
    # ensure $CONFIGDATA exists
    if [[ ! -d $CONFIGDATA ]]; then
      mkdir $CONFIGDATA
    fi
    # ensure $LOGDATA exists
    if [[ ! -d $LOGDATA ]]; then
      mkdir $LOGDATA
    fi
    # ensure $CACHEDATA exists
    if [[ ! -d $CACHEDATA ]]; then
      mkdir $CACHEDATA
    fi
    # Ensure permissions are correct on all config directories
    chown -R ${JELLYFIN_USER} $PROGRAMDATA $CONFIGDATA $LOGDATA $CACHEDATA
    chgrp adm $PROGRAMDATA $CONFIGDATA $LOGDATA $CACHEDATA
    chmod 0750 $PROGRAMDATA $CONFIGDATA $LOGDATA $CACHEDATA

    # 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
  # Manual init script handling
  deb-systemd-helper unmask jellyfin.service >/dev/null || true
  # 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

# End automatically added section
# Automatically added by dh_installinit
if [[ "$1" == "configure" ]] || [[ "$1" == "abort-upgrade" ]]; then
  if [[ -d "/run/systemd/system" ]]; then
    systemctl --system daemon-reload >/dev/null || true
    deb-systemd-invoke start jellyfin >/dev/null || true
  elif [[ -x "/etc/init.d/jellyfin" ]] || [[ -e "/etc/init/jellyfin.conf" ]]; then
    update-rc.d jellyfin defaults >/dev/null
    invoke-rc.d jellyfin start || exit $?
  fi
fi
exit 0
bgstack15