Debian Codegraph @

debian/hylafax-server.postinst

raw
1 #! /bin/sh -e
2
3 #DEBHELPER#
4
5 # Source debconf library.
6 . /usr/share/debconf/confmodule
7 db_title HylaFAX Server
8
9 # Create the faxmaster account if it doesn't exist already
10 if ! id faxmaster >/dev/null 2>&1; then
11 adduser --system --group --home /var/spool/hylafax --no-create-home --disabled-password \
12 --gecos "HylaFAX administrative mailbox" faxmaster
13 fi
14
15 # recover from an old install error
16 if [ -f /etc/hylafax/hosts -a ! -f /etc/hylafax/hosts.hfaxd ]; then
17 mv /etc/hylafax/hosts /etc/hylafax/hosts.hfaxd
18 fi
19
20 # Add getty symlinks
21 if [ -e /sbin/mgetty ]; then
22 [ -e /etc/hylafax/getty-link ] \
23 || ln -s /sbin/mgetty /etc/hylafax/getty-link
24 [ -e /etc/hylafax/egetty-link ] \
25 || ln -s /sbin/mgetty /etc/hylafax/egetty-link
26 fi
27 if [ -e /usr/sbin/vgetty ]; then
28 [ -e /etc/hylafax/vgetty-link ] \
29 || ln -s /usr/sbin/vgetty /etc/hylafax/vgetty-link
30 fi
31
32 # Change owner and group to uucp so that the FIFO pipes could be created.
33 chown uucp:uucp /var/spool/hylafax
34
35 if [ ! -e /etc/hylafax/setup.cache ]
36 then
37 [ ! -d /var/spool/hylafax/etc ] && mkdir -p /var/spool/hylafax/etc
38 (echo ; echo no; echo no) | faxsetup -server
39
40 #
41 # Check if faxsetup worked correctly
42 #
43 if [ ! -f /etc/hylafax/setup.cache ]
44 then
45 db_input critical hylafax-server/setup_failed || true
46 db_go
47 exit 1
48 fi
49 else
50 #
51 # These links are normally created via faxsetup during the first
52 # installation. If we are upgrading from an earlier version (and not
53 # installing for the first time) we have to create them by hand.
54 # 4.2.1-5
55 if [ ! -e /var/spool/hylafax/bin/pdf2fax ]
56 then
57 (cd /var/spool/hylafax/bin && ln -s pdf2fax.gs pdf2fax)
58 fi
59 if [ ! -e /var/spool/hylafax/bin/ps2fax ]
60 then
61 (cd /var/spool/hylafax/bin && ln -s ps2fax.gs ps2fax)
62 fi
63 fi
64
65 setupcache=/etc/hylafax/setup.cache
66 sed -i -e 's@^DPSRIP=.*$@DPSRIP=@' $setupcache
67 sed -i -e "s@^AWK='/bin/awk'@AWK='/usr/bin/awk'@" $setupcache
68 sed -i -e "s@^ENCODING=''@ENCODING='base64'@" $setupcache
69 sed -i -e "s@^MANDIR='/usr/local/man'@MANDIR='/usr/share/man'@" $setupcache
70 sed -i -e "s@^FONTPATH='/usr/local/lib/ghostscript/common:/usr/local/lib/ghostscript/7.07:/usr/local/lib/ghostscript/fonts:/usr/local/share/ghostscript/common:/usr/local/share/ghostscript/7.07:/usr/local/share/ghostscript/fonts:/var/lib/defoma/gs.d/dirs/fonts:/usr/share/ghostscript/common:/usr/share/gs/7.07'@FONTPATH='/usr/share/enscript/afm:/usr/share/fonts/afms/adobe:/usr/share/fonts/type1/gsfonts'@" $setupcache
71
72 # When upgrading to 4.2.1, be sure that all fields are present in the configuration.
73 if [ -x /usr/bin/uuencode ]
74 then
75 grep -q '^UUENCODE=' $setupcache || echo "UUENCODE='/usr/bin/uuencode'" >> $setupcache
76 grep -q '^ENCODING=' $setupcache || echo "ENCODING='base64'" >> $setupcache
77
78 # if uuencode was specified without complete PATH then add it
79 # see bug #377914
80 if grep -q "^UUENCODE='uuencode'" $setupcache
81 then
82 sed -i -e "s@^UUENCODE='uuencode'@UUENCODE='/usr/bin/uuencode'@" $setupcache
83 fi
84 fi
85
86 # bug #429614
87 # check for uuencode used for base64encoding. Change it to use mimencode
88 if [ -x /usr/bin/mimencode ]
89 then
90 sed -i -e "s@BASE64ENCODE='/usr/bin/uuencode'@BASE64ENCODE='/usr/bin/mimencode'@" $setupcache
91 sed -i -e "s@BASE64ENCODE='/usr/bin/uuencode -m ===='@BASE64ENCODE='/usr/bin/mimencode'@" $setupcache
92 fi
93
94 # bug #425191
95 # Update psrip path
96 if [ -x /usr/bin/psrip ]
97 then
98 sed -i -e "s@IMPRIP='/usr/lib/print/psrip'@IMPRIP='/usr/bin/psrip'@" $setupcache
99 fi
100
101 [ -x /usr/bin/tty ] && grep -q '^TTYCMD=' $setupcache || echo "TTYCMD='/usr/bin/tty'" >> $setupcache
102
103 restart=false
104 [ active = $(systemctl is-active hylafax) ] && restart=true
105
106 # disable hfaxd from inetd since it requires file system binding
107 # as the one done in hfaxd.service unit file
108 update-inetd --disable hylafax || true
109
110 # fix default values set by faxsetup without check on the real presence
111 # of the binary executable
112
113 uuenc=$(grep '^UUENCODE=' $setupcache | sed -e "s/^UUENCODE='\(.*\)'$/\1/" | (read a b; echo $a))
114 mmenc=$(grep '^MIMENCODE=' $setupcache | sed -e "s/^MIMENCODE='\(.*\)'$/\1/" | (read a b; echo $a))
115 baenc=$(grep '^BASE64ENCODE=' $setupcache | sed -e "s/^BASE64ENCODE='\(.*\)'$/\1/" | (read a b; echo $a))
116
117 if [ ! -x "$uuenc" ]
118 then
119 sed -i -e "s@UUENCODE='.*'@UUENCODE=''@" $setupcache
120 fi
121
122 if [ ! -x "$mmenc" ]
123 then
124 sed -i -e "s@MIMENCODE='.*'@MIMENCODE=''@" $setupcache
125 fi
126
127 if [ ! -x "$baenc" ]
128 then
129 sed -i -e "s@BASE64ENCODE='.*'@BASE64ENCODE=''@" $setupcache
130 fi
131
132 # copy some customised variables from sysv init configuration to systemd service configuration
133 if [ -f /etc/default/hylafax ] ; then
134 tmpconf=/etc/hylafax/hfaxd.systemd.conf.tmp
135 for v in BINDTO OLDPROT NEWPROT SNPP
136 do
137 if [ $(grep -c "^${v}=" /etc/default/hylafax) -gt 0 ]; then
138 value="$(grep "^${v}=" /etc/default/hylafax | tail -1)"
139 grep -v "^${v}=" /etc/hylafax/hfaxd.systemd.conf > $tmpconf
140 cat $tmpconf > /etc/hylafax/hfaxd.systemd.conf
141 rm $tmpconf
142 echo "$value" >> /etc/hylafax/hfaxd.systemd.conf
143 fi
144 done
145
146 if [ $(grep '^RUN_HYLAFAX=' /etc/default/hylafax | tail -1 | grep -c '^RUN_HYLAFAX=1') -gt 0 ]
147 then
148 deb-systemd-helper enable hylafax.service hfaxd.service
149 fi
150 fi
151
152 # enable faxgetty for already present configs, only for existing devices
153 enablefaxq=false
154 for c in /etc/hylafax/config.*
155 do
156 if [ ! -f "$c" ]
157 then
158 continue
159 fi
160 devname=$(echo $(basename "$c") | sed -e 's@^config\.\(.*\)$@\1@')
161 if [ -e /dev/${devname} ]
162 then
163 deb-systemd-helper enable faxgetty@${devname}.service
164 enablefaxq=true
165 restart=true
166 fi
167 done
168
169 # only enable faxq when modems are available via faxgetty
170 if [ "$enablefaxq" = true ]
171 then
172 deb-systemd-helper enable faxq.service
173 fi
174
175 if [ $restart = true ]; then
176 deb-systemd-helper restart hylafax
177 fi
178
179 # manually fix permissione when upgrading from old package
180 if [ "$1" = configure ] && dpkg --compare-versions "$2" lt 3:6.0.6-4
181 then
182 chmod o+t /var/spool/hylafax/tmp
183 fi
184
185 db_stop
186
187 exit 0