* send welcome mail on first debian package installation.
[citadel.git] / citadel / debian / citadel-server.postinst
1 #!/bin/sh
2 # postinst script for citadel-server
3 set -e
4
5 # source debconf stuff
6 . /usr/share/debconf/confmodule
7 db_version 2.0
8
9 case "$1" in
10     configure)
11         if ! getent group citadel >/dev/null; then 
12             groupadd citadel
13         fi
14
15         if ! getent passwd citadel >/dev/null; then 
16             adduser --system --ingroup citadel --home /var/lib/citadel \
17                     --gecos "Citadel system user" --shell /bin/sh \
18                     --disabled-password citadel
19         fi
20
21         chown -R citadel:citadel /etc/citadel
22         chown -R citadel:citadel /var/lib/citadel /var/spool/citadel
23
24         # we're a bit paranoid here,
25         # because of this gave us many errors in the past.
26         chown root:root /usr/sbin/chkpwd
27         chmod 4755 /usr/sbin/chkpwd
28
29         db_get citadel/Administrator && admin="$RET"
30         db_get citadel/ServerIPAddress && ip_addr="$RET"
31         db_get citadel/LoginType && enable_unix_auth="$RET"
32
33         if test "$enable_unix_auth" = "true"; then
34             export ENABLE_UNIX_AUTH=yes
35         else
36             export ENABLE_UNIX_AUTH=no
37         fi
38
39         export IP_ADDR=$ip_addr
40         export CITADEL=''
41         export CITADEL_INSTALLER=yes
42         export ACT_AS_MTA=no
43         export SYSADMIN_NAME=$admin
44         export CREATE_XINETD_ENTRY=no
45         export CREATE_INITTAB_ENTRY=no
46         export NO_INIT_SCRIPTS=yes
47
48         echo "applying your settings."
49         /usr/lib/citadel-server/setup -q
50
51 # we're in a fresh install, so we send the welcome message.
52         if test -z "$2"; then
53             export SEPERATOR=2600908b3f21ae7f692b973ed26e212d
54             export WELCOMEHTML=/usr/share/doc/citadel-server/welcomemail.html
55             export WELCOMETXT=/usr/share/doc/citadel-server/welcomemail.txt
56             export FROM=room_citadel_stats@uncensored.citadel.org
57             export TO=room_lobby
58             (
59                 printf "MIME-Version: 1.0\r\nContent-Type: multipart/alternative; \r\n boundary=$SEPERATOR\r\n\r\nThis is a multi-part message in MIME format.\r\n\r\n--$SEPERATOR\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n"; 
60                 cat $WELCOMETXT
61                 printf "\r\n\r\n--$SEPERATOR\r\nContent-Type: text/html; charset=US-ASCII\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n"
62                 cat $WELCOMEHTML; 
63                 printf "\r\n\r\n--$SEPERATOR--\r\n\r\n") | \
64                     /usr/sbin/citmail -bm -r "$FROM" "$TO"
65         fi
66         
67
68         if test -S /var/run/citadel/citadel.socket; then 
69             /usr/sbin/sendcommand "DOWN"
70         fi
71
72         while test -S /var/run/citadel/citadel.socket; do 
73             sleep 1
74         done
75
76         db_stop
77     ;;
78
79     abort-upgrade|abort-remove|abort-deconfigure)
80     ;;
81
82     *)
83         echo "postinst called with unknown argument \`$1'" >&2
84         exit 1
85     ;;
86 esac
87
88 #DEBHELPER#
89
90 exit 0