New upstream release
[pkg-ocaml-ocsigen.git] / debian / ocsigenserver.postinst
blobb59d3dfb4ef62b25646b5a7adaf96ee6cd97b3c4
1 #!/bin/sh -e
3 if ! ([ "$1" = "configure" ] || [ "$1" = "reconfigure" ]); then
4 exit 0
5 fi
7 # Some useful variables
8 OCSIGEN="ocsigen"
9 CHOWN="/bin/chown"
10 CHMOD="/bin/chmod"
11 ADDUSER="/usr/sbin/adduser"
12 USERDEL="/usr/sbin/userdel"
13 USERADD="/usr/sbin/useradd"
14 GROUPDEL="/usr/sbin/groupdel"
15 GROUPMOD="/usr/sbin/groupmod"
16 ID="/usr/bin/id"
17 HOOKSDIR="/etc/ocsigenserver/update.d"
19 ###
20 # 1. Get current uid and gid if user exists.
21 set -e
22 if $ID $OCSIGEN > /dev/null 2>&1; then
23 IUID=`$ID --user $OCSIGEN`
24 IGID=`$ID --group $OCSIGEN`
25 else
26 IUID="NONE"
27 IGID="NONE"
30 ###
31 # 2. Ensure that no standard account or group will remain before adding the
32 # new user.
33 if [ "$IUID" = "NONE" ] || [ $IUID -ge 1000 ]; then # we must do sth :)
34 if ! [ "$IUID" = "NONE" ] && [ $IUID -ge 1000 ]; then
35 # user exists but isn't a system user... delete it.
36 $USERDEL $OCSIGEN
37 $GROUPDEL $OCSIGEN
40 ###
41 # 3. Add the system account.
42 # Issue a warning if it fails.
43 if $GROUPMOD $OCSIGEN > /dev/null 2>&1; then
44 # group already exists, use --ingroup
45 if ! $ADDUSER --system --disabled-password --disabled-login --home /var/lib/ocsigenserver --no-create-home --ingroup $OCSIGEN $OCSIGEN; then
46 echo "The adduser command failed."
48 else
49 if ! $ADDUSER --system --disabled-password --disabled-login --home /var/lib/ocsigenserver --no-create-home --group $OCSIGEN; then
50 echo "The adduser command failed."
54 set +e
56 ###
57 # 4.1 Change ownership of directory.
58 $CHOWN -R $OCSIGEN:$OCSIGEN /var/lib/ocsigenserver/
59 $CHMOD 750 /var/lib/ocsigenserver/
61 ###
62 # 4.2 Create log directory and empty log if needed
63 LOGDIR="/var/log/ocsigenserver"
64 LOGFILE="${LOGDIR}/access.log"
65 mkdir -p $LOGDIR
66 $CHOWN $OCSIGEN:$OCSIGEN $LOGDIR
67 $CHMOD 750 $LOGDIR
68 if [ ! -f $LOGFILE ]; then
69 touch $LOGFILE
70 $CHOWN $OCSIGEN:$OCSIGEN $LOGFILE
71 $CHMOD 640 $LOGFILE
73 # The empty log is a workaround to logrotate complaining about
74 # inexistent logs (see #550324)
76 ###
77 # 5. Call update hooks
78 if [ -d $HOOKSDIR ]; then
79 echo "Running hooks in $HOOKSDIR..."
80 if ! run-parts --exit-on-error $HOOKSDIR; then
81 echo "Some hook failed, you should have a look!"
82 exit 1
84 else
85 echo "No hook to run in $HOOKSDIR."
88 ###
89 # 6. Call default debhelper scripts.
91 #DEBHELPER#