summaryrefslogtreecommitdiff
blob: 8ea1dd3ce056c32842318781e260648a68079eb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-misc/hylafax/files/hylafax-4.2,v 1.1 2004/08/10 04:15:54 nerdboy Exp $

depend() {
	use net
}

checkconfig() {
	SPOOL=/var/spool/fax
	if [ ! -f $SPOOL/etc/setup.cache ] ; then
		eerror "No $SPOOL/etc/setup.cache file exists! Use faxsetup(8C) !"
	fi

}

start() {
	ebegin "Starting HylaFAX Servers."
	SPOOL=/var/spool/fax
	checkconfig || return 1

	. $SPOOL/etc/setup.cache

	# Just in case these are not in setup.cache yet
	if [ -z "$HFAXD_SERVER" ]; then
		HFAXD_SERVER=yes
	fi
	if [ -z "$FAXQ_SERVER" ]; then
		FAXQ_SERVER=yes
	fi
	if [ -z "$HFAXD_OLD_PROTOCOL" ]; then
		HFAXD_OLD_PROTOCOL=no
	fi
	if [ -z "$HFAXD_SNPP_SERVER" ]; then
		HFAXD_SNPP_SERVER=no
	fi

	IS_ON=/etc/chkconfig            # NB: chkconfig is IRIX- and Linux-specific
	FAXQ=$SBIN/faxq
	HFAXD=$LIBEXEC/hfaxd
	FAXQUIT=$SBIN/faxquit
	FAXPORT=hylafax                 # designated port for new protocol
	SNPPPORT=444                    # official port for SNPP

	if test ! -x $IS_ON ; then
		IS_ON=true
	fi

	if $IS_ON verbose ; then
		ECHO=echo
	else            # For a quiet startup and shutdown
		ECHO=:
	fi
#
# Figure out which brand of echo we have and define prompt
# and printf shell functions accordingly.  Note that we
# assume that if the System V-style echo is not present,
# then the BSD printf program is available.  These functions
# are defined here so that they can be tailored on a per-site,
# etc. basis.
#
	if [ `echo foo\\\c`@ = "foo@" ]; then
# System V-style echo supports \r
# and \c which is all that we need
		printf()
        	{
			$ECHO "$*\\c"
		}
	elif [ "`echo -n foo`@" = "foo@" ]; then
# BSD-style echo; use echo -n to get
# a line without the trailing newline
		printf()
		{
			$ECHO -n "$*"
		}
	else
# something else; do without
		printf()
		{
			$ECHO "$*"
		}
	fi

#
#
# killall -SIGNAL process-name
#
# Emulate the necessary functionality of the
# killall program
#
	killall()
	{
# NB: ps ax should give an error on System V, so we try it first!
		pid="`ps ax 2>/dev/null | $AWK \"\
		/[\/ (]$2[ )]/  {print \\$1;}
		/[\/ ]$2\$/     {print \\$1;}\"`"
		test "$pid" ||
		pid="`ps -e 2>/dev/null | $AWK \"/ $2[ ]*\$/ {print \\$1;}\"`"
		test "$pid" && kill $1 $pid; return
	}

	if $IS_ON fax && test -x $FAXQ; then
		if test $FAXQ_SERVER = yes ; then
			killall -15 faxq
		fi
		if test $HFAXD_SERVER = yes ; then
			killall -15 hfaxd
		fi
		printf "HylaFAX:"
		if test $FAXQ_SERVER = yes ; then
			$FAXQ; printf " faxq "
		fi
		if test $HFAXD_SERVER = yes ; then
			HFAXD_OPT="-i $FAXPORT"
#			HFAXD="$HFAXD -i $FAXPORT"
			HFAXMSG=" hfaxd"
			if [ $HFAXD_OLD_PROTOCOL = yes ]; then
				HFAXD_OPT="$HFAXD_OPT -o 4557"
#				HFAXD="$HFAXD -o 4557"
				HFAXMSG="$HFAXMSG (with old protocol"
			else
				HFAXMSG="$HFAXMSG (without old protocol"
			fi
			if [ $HFAXD_SNPP_SERVER = yes ]; then
				HFAXD_OPT="$HFAXD_OPT -s $SNPPPORT"
#				HFAXD="$HFAXD -s $SNPPPORT"
				HFAXMSG="$HFAXMSG & with SNPP support)"
			else
				HFAXMSG="$HFAXMSG & without SNPP support)"
			fi
#			$HFAXD ; printf "$HFAXMSG\n"
			echo $HFAXMSG
			echo $HFAXD $HFAXD_OPT
			/sbin/start-stop-daemon --start --quiet --exec $HFAXD -- $HFAXD_OPT
		fi
		if test $FAXQ_SERVER != yes -a $HFAXD_SERVER != yes ; then
			printf " not started (script disabled by configure)\n"
		fi
		$ECHO "."
	fi
	eend $?

}

stop() {
	ebegin "Stopping HylaFAX Servers."
        checkconfig || return 2
	. $SPOOL/etc/setup.cache
	FAXQUIT=$SBIN/faxquit
        HFAXD=$LIBEXEC/hfaxd

#        $ECHO "Stopping HylaFAX Servers."
	$FAXQUIT >/dev/null 2>&1
	/sbin/start-stop-daemon --stop --quiet --exec $HFAXD
	eend $?
#        killall -15 hfaxd

}