ee44d5388fc46b0d1952bf7474c0d7fdaba84528
[openafs.git] / src / packaging / Debian / openafs-client.postinst
1 #! /bin/sh
2
3 set -e
4
5 if [ "$1" = configure ] || [ "$1" = reconfigure ] ; then
6     update-alternatives --install /usr/bin/pagsh pagsh \
7         /usr/bin/pagsh.openafs 100  \
8         --slave /usr/share/man/man1/pagsh.1.gz pagsh.1.gz \
9         /usr/share/man/man1/pagsh.openafs.1.gz
10     update-alternatives --install /usr/bin/klog klog \
11         /usr/bin/klog.afs 10 \
12         --slave /usr/share/man/man1/klog.1.gz klog.1.gz \
13         /usr/share/man/man1/klog.afs.1.gz
14
15     test -d /afs || mkdir /afs
16
17     . /usr/share/debconf/confmodule
18     db_version 2.0
19
20     db_get openafs-client/thiscell
21     THISCELL="$RET"
22     if [ -n "$THISCELL" ] ; then
23         echo "$THISCELL" > /etc/openafs/ThisCell
24     fi
25
26     if [ ! -f /etc/openafs/CellServDB ] ; then
27         cp /usr/share/openafs/CellServDB /etc/openafs
28     fi
29
30     # If ThisCell is not in CellServDB, we have to prompt the user for the
31     # VLDB servers.  Unfortunately, we can't do this in config because we
32     # need the CellServDB file, which is part of the package.
33     #
34     # If the user is using afsdb for cell location, don't worry about
35     # prompting them for cells for their local system.
36     db_get openafs-client/afsdb
37     afsdb="$RET"
38     if grep -q -F "$THISCELL" /etc/openafs/CellServDB \
39            && [ "x$THISCELL" != "x" ] ; then
40         :
41     elif [ x"$afsdb" != xtrue ] ; then
42         db_input critical openafs-client/cell-info || true
43         db_input high openafs-client/run-client || true
44         db_go
45         db_get openafs-client/cell-info
46         if [ "x$RET" != "x" ] ; then
47             echo ">$THISCELL" > /etc/openafs/CellServDB.new
48             perl -MSocket -e 'foreach (@ARGV) {' \
49                 -e '@a=gethostbyname($_) and ' \
50                 -e 'printf("%s\t\t# %s\n",inet_ntoa($a[4]),$a[0]) }' $RET \
51                     >>/etc/openafs/CellServDB.new
52             if [ `wc -l </etc/openafs/CellServDB.new` -eq 1 ] ; then
53                 echo None of the hostnames resolved to an address 2>&1
54                 db_reset openafs-client/cell-info || true
55                 rm /etc/openafs/CellServDB.new
56             else
57                 cat /etc/openafs/CellServDB.new /etc/openafs/CellServDB \
58                     > /etc/openafs/CellServDB.tmp
59                 mv /etc/openafs/CellServDB.tmp /etc/openafs/CellServDB
60                 rm /etc/openafs/CellServDB.new
61             fi
62         fi
63     fi
64                     
65     # Our config script will have already taken care of extracting the cache
66     # size from the cacheinfo file and using it as the default for the debconf
67     # prompt, but the mount point and cache directory have no debconf prompts.
68     # For those, we need to get the default from the file.
69     mountpoint=/afs
70     cachedir=/var/cache/openafs
71     if [ -r /etc/openafs/cacheinfo ] ; then
72         IFS=: read mountpoint cachedir cachesize < /etc/openafs/cacheinfo
73     fi
74     db_get openafs-client/cachesize
75     echo "${mountpoint}:${cachedir}:${RET}" > /etc/openafs/cacheinfo
76
77     echo <<'EOF' > /etc/openafs/afs.conf.client
78 # This file is managed by debconf.  You may change the parameters set below,
79 # but any additional lines or comments will be lost when the package is
80 # upgraded or reconfigured.  Local modifications other than setting the
81 # following parameters should be made in /etc/openafs/afs.conf instead.
82
83 EOF
84
85     db_get openafs-client/run-client
86     echo AFS_CLIENT="$RET" > /etc/openafs/afs.conf.client
87     echo AFS_AFSDB="$afsdb" >> /etc/openafs/afs.conf.client
88     db_get openafs-client/crypt
89     echo AFS_CRYPT="$RET" >> /etc/openafs/afs.conf.client
90     db_get openafs-client/dynroot
91     echo AFS_DYNROOT="$RET" >> /etc/openafs/afs.conf.client
92     db_get openafs-client/fakestat
93     echo AFS_FAKESTAT="$RET" >> /etc/openafs/afs.conf.client
94 fi
95
96 #DEBHELPER#
97
98 exit 0