aboutsummaryrefslogtreecommitdiff
path: root/debian/postinst
blob: f1469f1c1f0ffab6d7e4b728ac31c90109864550 (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
#!/bin/bash
set -e

NAME=emby-server
CONF_FILE=/etc/${NAME}.conf
DEFAULT_FILE=/etc/default/${NAME}

# Source Emby server default configuration
if [[ -f $DEFAULT_FILE ]]; then
  . $DEFAULT_FILE
fi

# Source Emby server user configuration overrides
if [[ -f $CONF_FILE ]]; then
  . $CONF_FILE
fi

# Data directory where Emby database, cache and logs are stored
PROGRAMDATA=${EMBY_DATA-/var/lib/$NAME}

case "$1" in
  configure)
    # create emby group if it does not exist
    if [[ -z "$(getent group emby)" ]]; then
      addgroup --quiet --system emby > /dev/null 2>&1
    fi
    # create emby user if it does not exist
    if [[ -z "$(getent passwd emby)"  ]]; then
      adduser --system --ingroup emby --shell /bin/false emby --no-create-home --home ${PROGRAMDATA} \
        --gecos "Emby Server default user" > /dev/null 2>&1
    fi
    # ensure $PROGRAMDATA has appropriate permissions
    if [[ ! -d $PROGRAMDATA ]]; then
      mkdir $PROGRAMDATA
      chown -R emby:emby $PROGRAMDATA
    fi
    # ensure emby-server binary has appropriate permissions
    chmod 755 /usr/bin/emby-server

    /usr/bin/mono --aot=full -O=all $EMBY_BIN > /dev/null 2>&1 || true

    chmod +x ${EMBY_DIR}/restart.sh > /dev/null 2>&1 || true

    ;;
    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 emby-server.service >/dev/null || true
  # was-enabled defaults to true, so new installations run enable.
  if deb-systemd-helper --quiet was-enabled emby-server.service; then
    # Enables the unit on first installation, creates new
    # symlinks on upgrades if the unit file has changed.
    deb-systemd-helper enable emby-server.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 emby-server.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/systemd" ]]; then
    systemctl --system daemon-reload >/dev/null || true
    deb-systemd-invoke start emby-server >/dev/null || true
  elif [[ -x "/etc/init.d/emby-server" ]] || [[ -e "/etc/init/emby-server.conf" ]]; then
    update-rc.d emby-server defaults >/dev/null
    invoke-rc.d emby-server start || exit $?
  fi
fi
exit 0