Lets keep our version of opftpd in the CVS
[oftpd.git] / debian / postinst
1 #!/bin/sh
2 set -e
3 . /usr/share/debconf/confmodule
4
5 CONFFILE=/etc/default/oftpd
6 LOGFILE=/var/log/oftpd.log
7 TMPFILE=$(tempfile)
8
9 #DEBHELPER#
10
11 update_value() {
12         if [ -e "$CONFFILE" ]; then
13                 if [ $(grep -c "$1" "$CONFFILE") = "0" ]; then
14                         echo "$1=\"$2\"" >> $CONFFILE
15                 else
16                         TMPVAL=$(echo $2 | sed -e "s/\\//\\\\\\//g")
17                         sed -e "s/$1=.*/$1=\"$TMPVAL\"/" < $CONFFILE > $TMPFILE
18                         mv -f $TMPFILE $CONFFILE
19                 fi
20         else
21                 echo "$1=\"$2\"" >> $TMPFILE
22         fi
23 }
24
25
26 if [ "$1" = "configure" ]; then
27         update-inetd --disable ftp || true
28         
29         update-rc.d oftpd defaults > /dev/null 2>/dev/null
30
31         /etc/init.d/oftpd stop
32
33 #       . $CONFFILE
34
35         db_get oftpd/enable_oftpd
36         if [ "$RET" = "true" ]; then
37                 update_value "ENABLE" "yes"
38                 db_get oftpd/which_user
39                 if [ -z "$RET" -o "$RET" = "oftpd" ]; then
40                         USER_TEST=$(cut -d ':' -f 1 < /etc/passwd | grep -w oftpd) || true
41                         if [ -z "$USER_TEST" ]; then
42                                 adduser --system oftpd
43                         fi
44                         update_value "USER" "oftpd"
45                 else
46                         update_value "USER" "$RET"
47                 fi
48                 db_get oftpd/which_dir
49                 if [ -z "$RET" ]; then
50                         update_value "DIR" "/home/oftpd"
51                 else
52                         update_value "DIR" "$RET"
53                 fi
54                 db_get oftpd/which_port
55                 if [ -n "$RET" ]; then
56                         update_value "PORT" "$RET"
57                 else
58                         update_value "PORT" "21"
59                 fi
60                 db_get oftpd/which_iface
61                 if [ -n "$RET" ]; then
62                         update_value "IFACE" "$RET"
63                 else
64                         update_value "IFACE" "0.0.0.0"
65                 fi
66                 db_get oftpd/max_conn
67                 if [ -n "$RET" ]; then
68                         update_value "MAXCON" "$RET"
69                 else
70                         update_value "MAXCON" "250"
71                 fi
72
73         else
74                 update_value "ENABLE" "no"
75                 db_get oftpd/which_user
76                 update_value "USER" "$RET"
77                 db_get oftpd/which_dir
78                 update_value "DIR" "$RET"
79         fi
80         
81         if [ ! -e "$CONFFILE" ]; then
82                 mv -f $TMPFILE $CONFFILE
83         fi
84
85         /etc/init.d/oftpd start
86
87 fi
88
89 exit 0;