Debian Codegraph @

debian/micro-httpd.postinst

raw
1 #!/bin/sh
2
3 set -e
4
5 PATH="/sbin:/bin:/usr/sbin:/usr/bin"
6 PACKAGE=$(basename $0 | sed 's/\..*//')
7 WWWDIR=/var/www/html
8 conf=/etc/inetd.conf
9 pkgdir=/usr/share/$PACKAGE
10 port="www"
11 entry="$port\tstream\ttcp\tnowait nobody:www-data\t/usr/sbin/tcpd /usr/sbin/$PACKAGE $WWWDIR"
12
13 Debhelper ()
14 {
15 :
16 #DEBHELPER#
17 }
18
19 Which ()
20 {
21 which "$1" > /dev/null 2>&1
22 }
23
24 Warn ()
25 {
26 echo "$*" >&2
27 }
28
29 IsInetd ()
30 {
31 [ -x /usr/sbin/update-inetd ]
32 }
33
34 IsInetdConf ()
35 {
36 [ -f $conf ]
37 }
38
39 IsInInetd ()
40 {
41 [ -f $conf ] || return 10
42
43 # Debian may have inetd.conf entry already
44 grep -q "^[[:space:]]*$port.*$PACKAGE" $conf ||
45
46 # check for other PORT alias name as well
47 grep -q "^[[:space:]]*(http|80)[[:space:]].*$PACKAGE" $conf
48 }
49
50 IsConflictInetd ()
51 {
52 # Check if some other service already uses PORT
53 grep -q "^[[:space:]#]*$port" $conf
54 }
55
56 HttpdWarning ()
57 {
58 # There isn't much point of inetd if apache already installed and
59 # occupies port 80
60
61 if ls /etc/init.d/apache* > /dev/null 2>&1 ; then
62 Warn "$0: [WARN] Apache found. $PACKAGE $conf uses port '$port'" \
63 "which may be same as in Apache (you may need to change $PACKAGE port)"
64 fi
65 }
66
67 InetdName ()
68 {
69 local name=
70
71 if [ -f /etc/init.d/inetutils-inetd ]; then
72 name=inetutils-inetd
73 elif [ -f /etc/init.d/openbsd-inetd ]; then
74 name="openbsd-inetd"
75 elif [ -f /etc/init.d/rlinetd ]; then
76 name="rlinetd"
77 fi
78
79 [ ! "$name" ] || echo $name
80 }
81
82 CallInetd ()
83 {
84 local name=$1
85 local cmd=$2
86
87 [ "$cmd" ] || return 0
88
89 if Which invoke-rc.d ; then
90 invoke-rc.d $name $cmd
91 else
92 /etc/init.d/$name $cmd
93 fi
94 }
95
96 InstallInetd ()
97 {
98 Warn "$0: adding new $conf entry"
99 update-inetd --group STANDARD --add "$entry"
100
101 # This directory must be there
102
103 [ ! -d $WWWDIR ] && mkdir -p $WWWDIR
104
105 local name=$(InetdName)
106
107 CallInetd $name reload
108 }
109
110 MainInetd ()
111 {
112 if [ "$1" = "install" ] || [ "$1" = "configure" ]
113 then
114 if IsConflictInetd ; then
115 Warn "$PACKAGE: [WARNING] Not installing to $conf" \
116 "due to existing '$port' entry"
117 else
118 IsInInetd || InstallInetd
119 HttpdWarning
120 fi
121 fi
122 }
123
124 Main ()
125 {
126 if IsInetd ; then
127 MainInetd "$@"
128 fi
129
130 Debhelper "$@"
131 }
132
133 Main "$@"
134
135 # End of file