calculate the directories in a central manner.
[citadel.git] / citadel / debian / citadel-server.postinst
1 #! /bin/sh
2 # postinst.skeleton
3 # Skeleton maintainer script showing all the possible cases.
4 # Written by Charles Briscoe-Smith, March-June 1998.  Public Domain.
5
6 # Abort if any command returns an error value
7 set -e
8
9 # Use debconf.
10 . /usr/share/debconf/confmodule
11
12 # This script is called as the last step of the installation of the
13 # package.  All the package's files are in place, dpkg has already done
14 # its automatic conffile handling, and all the packages we depend of
15 # are already fully installed and configured.
16
17 # The following idempotent stuff doesn't generally need protecting
18 # against being run in the abort-* cases.
19
20 #### Install info files into the dir file
21 ###: install-info --quiet --section "section pattern" "Section Title" \
22 ###:              --description="Name of the document" /usr/info/foo.info
23 ###
24 #### Create stub directories under /usr/local
25 ###: if test ! -d /usr/local/lib/foo; then
26 ###:   if test ! -d /usr/local/lib; then
27 ###:     if mkdir /usr/local/lib; then
28 ###:       chown root.staff /usr/local/lib || true
29 ###:       chmod 2775 /usr/local/lib || true
30 ###:     fi
31 ###:   fi
32 ###:   if mkdir /usr/local/lib/foo; then
33 ###:     chown root.staff /usr/local/lib/foo || true
34 ###:     chmod 2775 /usr/local/lib/foo || true
35 ###:   fi
36 ###: fi
37 ###
38 #### Ensure the menu system is updated
39 ###: [ ! -x /usr/bin/update-menus ] || /usr/bin/update-menus
40 ###
41 #### Arrange for a daemon to be started at system boot time
42 ###: update-rc.d foo default >/dev/null
43 ###
44
45 case "$1" in
46   configure)
47     # Configure this package.  If the package must prompt the user for
48     # information, do it here.
49     if ! getent group citadel >/dev/null; then 
50                 groupadd citadel
51         fi
52         if ! getent passwd citadel >/dev/null; then 
53                 adduser --system --ingroup citadel --home /var/lib/citadel \
54                         --gecos "Citadel system user" --shell /bin/sh \
55                         --disabled-password citadel
56         fi
57         mkdir -p /etc/citadel
58         chown citadel:citadel /etc/citadel
59     # Activate menu-methods script
60     #: chmod a+x /etc/menu-methods/foo
61
62     # Update ld.so cache
63     #: ldconfig
64
65     # Make our version of a program available
66     #: update-alternatives \
67     #:       --install /usr/bin/program program /usr/bin/alternative 50 \
68     #:       --slave /usr/share/man/man1/program.1.gz program.1.gz \
69     #:               /usr/share/man/man1/alternative.1.gz
70
71     # Tell ucf that the file in /usr/share/foo is the latest
72     # maintainer version, and let it handle how to manage the real
73     # confuguration file in /etc. This is how a static configuration
74     # file can be handled:
75     ucf /usr/share/doc/citadel-server/examples/mail.aliases /etc/citadel/mail.aliases
76     ucf /usr/share/doc/citadel-server/examples/public_clients /etc/citadel/public_clients
77
78         #: !TODO: should network/systems  go to /etc/citadel?
79
80         mkdir -p \
81                 /var/lib/citadel/help \
82                 /var/lib/citadel/messages \
83                 /var/lib/citadel/data/ \
84                 /var/lib/citadel/bio/ \
85                 /var/lib/citadel/bitbucket/ \
86                 /var/lib/citadel/files/ \
87                 /var/lib/citadel/images/ \
88                 /var/lib/citadel/info/ \
89                 /var/lib/citadel/userpics/ \
90                 /var/spool/citadel/network/spoolin \
91                 /var/spool/citadel/network/spoolout \
92                 /var/spool/citadel/network/spoolsystems \
93                 /var/run/citadel
94
95
96     mkdir -p /var/lib/citadel/help
97         for i in   aide  floors  hours  intro.gz  mail  network  nice.gz  policy  software  summary.gz; do
98                 case $i in 
99                         *.gz)
100                                 j=`echo $i|sed "s;.gz;;"`
101                                 gunzip -c "/usr/share/doc/citadel-server/examples/help/$i" >"/tmp/$j"
102                                 i=$j
103                                 ;;
104                         *)
105                                 cp "/usr/share/doc/citadel-server/examples/help/$i" "/tmp"
106                                 ;;
107                 esac
108                 ucf "/tmp/$i" "/var/lib/citadel/help/$i"
109                 rm -f "/tmp/$i"
110         done
111         
112 #       # TODO: there is a file named '?'. this gives trouble with ucf, so do it by hand for now.
113 #       if test ! -e '/var/lib/citadel/help/?'; then 
114 #               cp '/usr/share/doc/citadel/examples/data/help/?' '/var/lib/citadel/help'
115 #       fi
116         mkdir -p /var/lib/citadel/messages
117         for i in aideopt  changepw  dotopt  entermsg  entopt  goodbye  hello  help  mainmenu  newuser  readopt  register  roomaccess  unlisted; do
118                 ucf "/usr/share/doc/citadel-server/examples/messages/$i" "/var/lib/citadel/messages/$i"
119
120         done
121
122         chown -R citadel:citadel /var/lib/citadel /var/run/citadel /var/spool/citadel
123
124     ### We could also do this on the fly. The following is from Tore
125     ### Anderson:
126     
127     #. /usr/share/debconf/confmodule
128
129     ### find out what the user answered.
130     #  db_get foo/run_on_boot
131     #  run_on_boot=$RET
132     #  db_stop
133
134     ### safely create a temporary file to generate our suggested
135     ### configuration file.
136     #    tempfile=`tempfile`
137     #    cat << _eof > $tempfile
138     ### Configuration file for Foo.
139
140     ### this was answered by you, the user in a debconf dialogue
141     #  RUNONBOOT=$run_on_boot
142
143     ### this was not, as it has a sane default value.
144     #  COLOUROFSKY=blue
145
146     #_eof
147
148     ### Note that some versions of debconf do not release stdin, so
149     ### the following invocation of ucf may not work, since the stdin
150     ### is never coneected to ucfr.
151
152     ### now, invoke ucf, which will take care of the rest, and ask
153     ### the user if he wants to update his file, if it is modified.
154     #ucf $tempfile /etc/foo.conf
155
156     ### done! now we'll just clear up our cruft.
157     #rm -f $tempfile
158
159         db_get citadel/Administrator && admin="$RET"
160         db_get citadel/ServerIPAddress && ip_addr="$RET"
161         export IP_ADDR=$ip_addr
162         export CITADEL=''
163         export CITADEL_INSTALLER=yes
164         export ACT_AS_MTA=no
165         export SYSADMIN_NAME=$admin
166         export CREATE_XINETD_ENTRY=no
167         export CREATE_INITTAB_ENTRY=yes
168         echo "applying your settings."
169 # citadel home
170 # sysadmin
171 # uid
172 # server ip
173 # port
174 # postfix?
175 # exim?
176 #       echo "/usr/sbin
177 #$admin
178 #citadel
179 #$ip_addr
180 #
181 #no
182 #no
183 #" | \
184         /usr/lib/citadel-server/setup -q
185         killall -HUP init
186     #### There are three sub-cases:
187     ###if test "${2+set}" != set; then
188     ###  # We're being installed by an ancient dpkg which doesn't remember
189     ###  # which version was most recently configured, or even whether
190     ###  # there is a most recently configured version.
191     ###  :
192         ###
193     ###elif test -z "$2" -o "$2" = "<unknown>"; then
194     ###  # The package has not ever been configured on this system, or was
195     ###  # purged since it was last configured.
196     ###  :
197         ###
198     ###else
199     ###  # Version $2 is the most recently configured version of this
200     ###  # package.
201     ###  :
202         ###
203     ###fi 
204         ;;
205   abort-upgrade)
206     # Back out of an attempt to upgrade this package FROM THIS VERSION
207     # to version $2.  Undo the effects of "prerm upgrade $2".
208     #:
209
210     ;;
211   abort-remove)
212     ###if test "$2" != in-favour; then
213     ###  echo "$0: undocumented call to \`postinst $*'" 1>&2
214     ###  exit 0
215     ###fi
216     #### Back out of an attempt to remove this package, which was due to
217     #### a conflict with package $3 (version $4).  Undo the effects of
218     #### "prerm remove in-favour $3 $4".
219     ###:
220
221     ;;
222   abort-deconfigure)
223     ###if test "$2" != in-favour -o "$5" != removing; then
224     ###  echo "$0: undocumented call to \`postinst $*'" 1>&2
225     ###  exit 0
226     ###fi
227     #### Back out of an attempt to deconfigure this package, which was
228     #### due to package $6 (version $7) which we depend on being removed
229     #### to make way for package $3 (version $4).  Undo the effects of
230     #### "prerm deconfigure in-favour $3 $4 removing $6 $7".
231     ###:
232
233     ;;
234   *) echo "$0: didn't understand being called with \`$1'" 1>&2
235      exit 0;;
236 esac
237
238 exit 0