Debian Codegraph @

debian/gavodachs2-server.postinst

raw
1 #! /bin/sh
2 set -e
3
4 #DEBHELPER#
5
6 set_user_account()
7 {
8 # have stuff the server needs to see belong to this group.
9 if ! getent group gavo > /dev/null ; then
10 addgroup gavo
11 fi
12
13 # This is the user that the server changes to if it can.
14 if ! getent passwd gavo > /dev/null ; then
15 adduser --system --no-create-home --home /nonexistent --ingroup gavo gavo
16 fi
17
18 # dachsroot should be used to write RDs, handle data, etc. People can
19 # also use other other accounts with group membership gavo. Since
20 # 2020 CI doesn't let us create users with home directories, fall back
21 # to creating one without.
22 if ! getent passwd dachsroot > /dev/null ; then
23 adduser --disabled-password --gecos "" --ingroup gavo dachsroot \
24 || adduser --system --shell /bin/sh --no-create-home --home /nonexistent --ingroup gavo dachsroot
25 fi
26 }
27
28
29 create_database()
30 {
31 # create the database
32 if ! su postgres -c "createdb --encoding=UTF-8 --template template0 gavo" ; then
33 echo "Creation of gavo database failed; assuming it's already there"
34 echo "and carrying on."
35 fi
36 }
37
38
39 create_dachs_env()
40 {
41 # give postgres superuser privileges to user "dachsroot"
42 ! su postgres -c "createuser -s dachsroot"
43
44 # create the "gavo" rootDir
45 mkdir -p /var/gavo/
46
47 # make sure that the rootDir is writable by "dachsroot"
48 chown dachsroot /var/gavo/
49
50 # let DaCHS create its filesystem hierarchy
51 su dachsroot -c "dachs init"
52
53 # in case there already was a DaCHS (perhaps dachs 1.x, perhaps because
54 # as a remnant of a previous installation), run an upgrade immdiately;
55 # the stuff from upgrade_dachs_env won't run on install.
56 su dachsroot -c "dachs upgrade"
57 }
58
59
60 start_dachs()
61 {
62 # register the "dachs" init script
63 if [ -x "/etc/init.d/dachs" ]; then
64 update-rc.d dachs defaults > /dev/null
65 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
66 invoke-rc.d dachs start || exit $?
67 else
68 /etc/init.d/dachs start || exit $?
69 fi
70 fi
71 }
72
73
74 upgrade_dachs_env()
75 {
76 echo " "
77 echo "If this step fails, run dachs upgrade yourself"
78 echo "and read the error messages. If that doesn't help,"
79 echo "please notify to [email protected] ."
80 echo " "
81
82 su -s/bin/sh -c "dachs upgrade" dachsroot || exit $?
83
84 # restart the "dachs" server
85 invoke-rc.d dachs restart || exit $?
86 }
87
88
89 case "$1" in
90 configure)
91 if [ -z "$2" ]; then
92 set_user_account
93 create_database
94 create_dachs_env
95 start_dachs
96 else
97 upgrade_dachs_env
98 fi
99 ;;
100 *)
101 echo "$0: does not understand being called with \`$1'" 1>&2
102 exit
103 ;;
104 esac