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