aboutsummaryrefslogtreecommitdiffstats
path: root/debian/cgit-config.postinst
blob: 0383faef460fb5ffe6b2f1eb66eab900eace4529 (plain) (blame)
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
#!/bin/sh

set -eu

#DEBHELPER#

case "$1" in
  install|upgrade)

  # Sane defaults:
  git_home="${GIT_HOME:-/var/git}"
  git_user="${GIT_USER:-git}"
  git_name="${GIT_NAME:-git}"
  git_group="${GIT_GROUP:-www-data}"

  # create user to avoid running server as root
  # 1. create group if not existing
  if ! getent group | grep -q "^$git_group:" ; then
     printf 'Adding group %s..\n' "$git_group"
     addgroup --quiet --system "$git_group" 2>/dev/null
     printf '..done\n'
  fi

  # 2. create homedir if not existing
  if [ -d "$git_home" ]; then
    # `/var` *must* exist.
    mkdir -- "$git_home"
  fi

  # 3. create user if not existing
  if ! getent passwd "$git_user"; then
    printf  'Adding system user %s..\n' "$git_user"
    # XXX: Do I really want a shell here?
    adduser --quiet \
            --system \
            --ingroup "$git_group" \
            --home "$git_home" \
            --shell /bin/bash \
            --disabled-password \
            "$git_user"
    printf '..done\n'
  fi

  # 4. adjust passwd entry
  usermod \
    -c "$git_name" \
    -d "$git_home" \
    -g "$git_group" \
    "$git_user"

  # 5. adjust file and directory permissions
  if ! dpkg-statoverride --list "$git_home" >/dev/null
  then
      chown -R "$git_user":"$git_group" "$git_home"
      chmod u=rwx,g=rxs,o= "$git_home"
  fi

  deb-systemd-helper enable fcgiwrap
  deb-systemd-invoke restart fcgiwrap
  deb-systemd-invoke restart nginx
  ;;
  # TODO: Handle remove, not that I need it yet though.
esac