summarylogtreecommitdiffstats
path: root/hudson.install
blob: 5c2b62627a7bc6ca6c87691d9e431b5f405f28db (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
#!/bin/sh

_service_name=hudson.service
_service_username=hudson
_service_groupname=${_service_username}
_service_home_dir=/var/lib/hudson
_service_tmpfiles_conf=${_service_username}.conf

# Test whether the systemd service is enabled (presuming that systemd is running).
_is_systemd_service_enabled() {
  /usr/bin/systemctl is-enabled --quiet ${_service_name} 2>/dev/null
}

# arg 1:  the new package version
pre_install() {
  /bin/true
}

# arg 1:  the new package version
post_install() {
  getent passwd ${_service_username} > /dev/null || /usr/sbin/useradd --system --user-group --home-dir "${_service_home_dir}" --create-home --shell "/bin/bash" --skel /dev/null ${_service_username} &> /dev/null
  [ -n "${_service_tmpfiles_conf}" ] && systemd-tmpfiles --create ${_service_tmpfiles_conf}
}

# arg 1:  the new package version
# arg 2:  the old package version
pre_upgrade() {
  /bin/true
}

# arg 1:  the new package version
# arg 2:  the old package version
post_upgrade() {
  [ -n "${_service_tmpfiles_conf}" ] && systemd-tmpfiles --create ${_service_tmpfiles_conf}
  _is_systemd_service_enabled && cat <<EOF
=> Remember to issue the following commands:
  sudo systemctl --system daemon-reload
  sudo systemctl restart ${_service_name}
EOF
}

# arg 1:  the old package version
pre_remove() {
  /usr/bin/systemctl stop ${_service_name} 2>/dev/null
  _is_systemd_service_enabled && /usr/bin/systemctl disable ${_service_name} 2>/dev/null
  [ -n "${_service_tmpfiles_conf}" ] && systemd-tmpfiles --remove ${_service_tmpfiles_conf}
  return 0;
}

# arg 1:  the old package version
post_remove() {
  getent passwd ${_service_username} > /dev/null && /usr/sbin/userdel ${_service_username} &>/dev/null
  for d in ${_service_home_dir}; do
    [ -n "${d}" -a -d "${d}" ] && echo "=> directory ${d} needs to be removed manually"
  done
  return 0;
}