aboutsummarylogtreecommitdiffstats
path: root/nordlayer-runit.install
blob: 1f3e413af6c7f1b8c1e2ec38601f13776bf9fb22 (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
VAR_LIB=/var/lib/nordlayer-runit
NORDLAYER_RESOLVCONF=/usr/bin/nordlayer-resolvconf

post_install() {
  # Set capabilities and permissions
  if [ -f /usr/bin/nordlayerd ]; then
    setcap CAP_NET_BIND_SERVICE,CAP_NET_ADMIN,CAP_NET_RAW+eip /usr/bin/nordlayerd
  fi

  if [ -f /usr/bin/nordlayer-openvpn ]; then
    setcap CAP_NET_BIND_SERVICE,CAP_NET_ADMIN,CAP_NET_RAW+eip /usr/bin/nordlayer-openvpn
  fi

  # Add necessary groups
  groupadd -r -f nordlayer
  groupadd -r -f nordlayer-resolve

  # Add user if it doesn't exist
  if ! id "nordlayer" >/dev/null 2>&1; then
    useradd -s /usr/bin/nologin -c "Used for running NordLayer" -r -M -d /run/nordlayer -g nordlayer nordlayer
  fi

  # Add user to the group
  usermod -a -G nordlayer-resolve nordlayer

  # Create and set directory permissions
  if [ -n "$VAR_LIB" ]; then
    mkdir -p "$VAR_LIB"
    chmod 0770 -R "$VAR_LIB"
    chown nordlayer:nordlayer -R "$VAR_LIB"
  fi

  # Set up file permissions
  if [ -f "$NORDLAYER_RESOLVCONF" ]; then
    chown root:nordlayer-resolve "$NORDLAYER_RESOLVCONF"
    chmod 4750 "$NORDLAYER_RESOLVCONF"
  fi

  # Enable and start the service with runit
  ln -s /etc/runit/sv/nordlayer /run/runit/service/
  sv start nordlayer || true
}

post_upgrade() {
  post_install
}

pre_remove() {
  # Stop and disable service with runit
  sv down nordlayer || true
  rm -f /run/runit/service/nordlayer

  # Remove directory
  if [ -n "$VAR_LIB" ]; then
    rm -rf "$VAR_LIB"
  fi
}