+ correct FS-flags on citadel.co* on startup
[citadel.git] / citadel / debian / citadel-server.postinst
index 5b10ff3f05b749316b78f611508cad5d9809c07f..25663616f114dec3bdf5fce8c75cedbf4ff0ad03 100644 (file)
-#! /bin/sh
-# citadel-server.postinst
-# by Wilfried Goesgens & Fathi Boudra
+#!/bin/sh
+# postinst script for citadel-server
 
 set -e
 
-# Use debconf.
+# source debconf stuff
 . /usr/share/debconf/confmodule
+db_version 2.0
 
-
+# glitch: this mustn't be in /var/run/
+if test -f /var/run/refcount_adjustments.dat; then
+    mv /var/run/refcount_adjustments.dat /etc/citadel/
+fi
 case "$1" in
-  configure)
-    if ! getent group citadel >/dev/null; then 
-               groupadd citadel
-       fi
-       if ! getent passwd citadel >/dev/null; then 
-               adduser --system --ingroup citadel --home /var/lib/citadel \
-                       --gecos "Citadel system user" --shell /bin/sh \
-                       --disabled-password citadel
-       fi
-       mkdir -p /etc/citadel
-       chown citadel:citadel /etc/citadel
+    configure)
+        chown -R citadel:citadel /etc/citadel
+        chown -R citadel:citadel /var/lib/citadel /var/spool/citadel
 
-       #: !TODO: should network/systems  go to /etc/citadel?
-       mkdir -p \
-               /var/lib/citadel/data/ \
-               /var/lib/citadel/bio/ \
-               /var/lib/citadel/bitbucket/ \
-               /var/lib/citadel/files/ \
-               /var/lib/citadel/images/ \
-               /var/lib/citadel/info/ \
-               /var/lib/citadel/userpics/ \
-               /var/spool/citadel/network/spoolin \
-               /var/spool/citadel/network/spoolout \
-               /var/spool/citadel/network/spoolsystems 
+        db_get citadel/Administrator && admin="$RET"
+        db_get citadel/ServerIPAddress && ip_addr="$RET"
+        db_get citadel/LoginType && deb_enable_unix_auth="$RET"
 
-       chown -R citadel:citadel /var/lib/citadel /var/spool/citadel
+        if test "$deb_enable_unix_auth" = "true"; then
+            export ENABLE_UNIX_AUTH=yes
+        else
+            export ENABLE_UNIX_AUTH=no
+        fi
 
-        chown root:root /usr/sbin/chkpwd
-        chmod 4755 /usr/sbin/chkpwd
+        export IP_ADDR=$ip_addr
+        export CITADEL='/var/run/citadel'
+       export CITADEL_PORT=504
+        export CITADEL_INSTALLER=yes
+       export CITADEL_UID=`grep citadel /etc/passwd | cut -d :  -f 3`
+        export ACT_AS_MTA=no
+        export SYSADMIN_NAME=$admin
+        export CREATE_XINETD_ENTRY=no
+        export CREATE_INITTAB_ENTRY=no
+        export NO_INIT_SCRIPTS=yes
 
-       db_get citadel/Administrator && admin="$RET"
-       db_get citadel/ServerIPAddress && ip_addr="$RET"
-       db_get citadel/LoginType && enable_unix_auth="$RET"
-       if test "$enable_unix_auth" = "true"; then
-           export ENABLE_UNIX_AUTH=yes
-       else
-           export ENABLE_UNIX_AUTH=no
+#This is not debian conformant, and uniq to the citadel.org debs.
+       export ALTER_ETC_SERVICES=yes
+#
+        if test -S /var/run/citadel/citadel.socket; then 
+            /usr/sbin/sendcommand "DOWN"
+        fi
+        while test -S /var/run/citadel/citadel.socket; do 
+            sleep 1
+        done
+       if test ! -f /var/lib/citadel/data/citadel.control -a -f /etc/citadel/citadel.control; then
+           mv /etc/citadel/citadel.control /var/lib/citadel/data/
+           mv /etc/citadel/citadel.config /var/lib/citadel/data/
        fi
-       export IP_ADDR=$ip_addr
-       export CITADEL=''
-       export CITADEL_INSTALLER=yes
-       export ACT_AS_MTA=no
-       export SYSADMIN_NAME=$admin
-       export CREATE_XINETD_ENTRY=no
-       export CREATE_INITTAB_ENTRY=no
-       export NO_INIT_SCRIPTS=yes
-
-       echo "applying your settings."
-       /usr/lib/citadel-server/setup -q
 
-       if test -S /var/run/citadel/citadel.socket; then 
-           /usr/sbin/sendcommand "DOWN"
+        echo -n "applying your settings.... "
+        /usr/lib/citadel-server/setup -q
+       echo "done"
+        # we're in a fresh install, so we send the welcome message.
+        if test -z "$2"; then
+           echo "migrating mail aliases from other mailers"
+           /usr/lib/citadel-server/migrate_aliases.sh /etc/citadel/mail.aliases
+           i=0;
+           while test ! -S /var/run/citadel/lmtp.socket -a "$i" -lt "10"; do
+               sleep 1
+               i=$(($i + 1))
+           done
+           if test -S /var/run/citadel/lmtp.socket ; then
+               echo "sending welcome mail"
+               export SEPERATOR=2600908b3f21ae7f692b973ed26e212d
+               export WELCOMEHTML=/usr/share/doc/citadel-server/welcomemail.html
+               export WELCOMETXT=/usr/share/doc/citadel-server/welcomemail.txt
+               export FROM=room_citadel_stats@uncensored.citadel.org
+               export TO=room_lobby
+               (
+                    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"; 
+                    cat $WELCOMETXT
+                    printf "\r\n\r\n--$SEPERATOR\r\nContent-Type: text/html; charset=US-ASCII\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n"
+                    cat $WELCOMEHTML; 
+                    printf "\r\n\r\n--$SEPERATOR--\r\n\r\n") | \
+                       /usr/sbin/citmail -bm -r "$FROM" "$TO"
+            fi
        fi
 
-       while test -S /var/run/citadel/citadel.socket; do 
-           sleep 1
-       done
+        if test -S /var/run/citadel/citadel.socket; then 
+            /usr/sbin/sendcommand "DOWN"
+        fi
 
-       db_stop
-       
-       ;;
-  abort-upgrade|abort-remove|abort-deconfigure)
+        while test -S /var/run/citadel/citadel.socket; do 
+            sleep 1
+        done
+
+        db_stop
+    ;;
+
+    abort-upgrade|abort-remove|abort-deconfigure)
     ;;
 
-  *) echo "$0: didn't understand being called with \`$1'" 1>&2
-     exit 1;;
+    *)
+        echo "postinst called with unknown argument \`$1'" >&2
+        exit 1
+    ;;
 esac
 
-       #DEBHELPER#
+#DEBHELPER#
 
 exit 0