| 1 |
#!/bin/bash
|
| 2 |
# Copyright (c) 2004-2005 Gentoo Foundation
|
| 3 |
# Distributed under the terms of the GNU General Public License v2
|
| 4 |
|
| 5 |
# Contributed by Roy Marples (uberlord@gentoo.org)
|
| 6 |
|
| 7 |
# char* ipppd_provides(void)
|
| 8 |
#
|
| 9 |
# Returns a string to change module definition for starting up
|
| 10 |
ipppd_provides() {
|
| 11 |
echo "isdn"
|
| 12 |
}
|
| 13 |
|
| 14 |
# void ipppd_depend(void)
|
| 15 |
#
|
| 16 |
# Sets up the dependancies for the module
|
| 17 |
ipppd_depend() {
|
| 18 |
after macnet
|
| 19 |
before interface
|
| 20 |
}
|
| 21 |
|
| 22 |
# bool ipppd_check_installed(void)
|
| 23 |
#
|
| 24 |
# Returns 1 if isnd4k-utils is installed, otherwise 0
|
| 25 |
ipppd_check_installed() {
|
| 26 |
[[ -x /usr/sbin/ipppd ]] && return 0
|
| 27 |
${1:-false} && eerror "For ISDN (ipppd) support, emerge net-dialup/isdn4k-utils"
|
| 28 |
return 1
|
| 29 |
}
|
| 30 |
|
| 31 |
# bool ipppd_check_depends(void)
|
| 32 |
#
|
| 33 |
# Checks to see if we have the needed functions
|
| 34 |
ipppd_check_depends() {
|
| 35 |
local f
|
| 36 |
|
| 37 |
for f in interface_exists interface_type clean_pidfile; do
|
| 38 |
[[ $( type -t "${f}" ) == "function" ]] && continue
|
| 39 |
eerror "ipppd: missing required function ${f}\n"
|
| 40 |
return 1
|
| 41 |
done
|
| 42 |
|
| 43 |
return 0
|
| 44 |
}
|
| 45 |
|
| 46 |
# bool ipppd_start(char *iface)
|
| 47 |
#
|
| 48 |
# Start isdn on an interface
|
| 49 |
#
|
| 50 |
# Returns 0 (true) when successful, non-zero otherwise
|
| 51 |
ipppd_pre_start() {
|
| 52 |
local iface="$1" opts itype=$( interface_type "$1" )
|
| 53 |
local pidfile="/var/run/ipppd-${iface}.pid"
|
| 54 |
|
| 55 |
# Check that we are a valid isdn interface
|
| 56 |
[[ ${itype} != "ippp" && ${itype} != "isdn" ]] && return 0
|
| 57 |
|
| 58 |
# Check that the interface exists
|
| 59 |
interface_exists "${iface}" true || return 1
|
| 60 |
|
| 61 |
if ! clean_pidfile "${pidfile}" ; then
|
| 62 |
ewarn "ipppd is already running on ${iface}"
|
| 63 |
eend 0
|
| 64 |
return 0
|
| 65 |
fi
|
| 66 |
|
| 67 |
local ifvar=$( bash_variable "${iface}" )
|
| 68 |
# Might or might not be set in conf.d/net
|
| 69 |
eval opts=\"\$\{ipppd_${ifvar}\}\"
|
| 70 |
|
| 71 |
einfo "Starting ipppd for ${iface}"
|
| 72 |
/usr/sbin/ipppd "${opts}" pidfile "${pidfile}" \
|
| 73 |
file "/etc/ppp/options.${iface}" >/dev/null
|
| 74 |
eend $? || return $?
|
| 75 |
|
| 76 |
return 0
|
| 77 |
}
|
| 78 |
|
| 79 |
# bool ipppd_stop(char *iface)
|
| 80 |
#
|
| 81 |
# Stop isdn on an interface
|
| 82 |
# Returns 0 (true) when successful, non-zero otherwise
|
| 83 |
ipppd_stop() {
|
| 84 |
local iface="$1" pidfile="/var/run/ipppd-$1.pid"
|
| 85 |
|
| 86 |
ipppd_check_installed || return 0
|
| 87 |
[[ ! -f ${pidfile} ]] && return 0
|
| 88 |
|
| 89 |
clean_pidfile "${pidfile}" && return 0
|
| 90 |
local pid=$( < "${pidfile}" ) r=0
|
| 91 |
|
| 92 |
einfo "Stopping ipppd for ${iface}"
|
| 93 |
kill -s TERM "${pid}"
|
| 94 |
if ! process_finished "${pid}" ipppd 10 ; then
|
| 95 |
kill -s KILL "${pid}"
|
| 96 |
process_finished "${pid}" ipppd 10 || r=1
|
| 97 |
fi
|
| 98 |
|
| 99 |
eend ${r}
|
| 100 |
return ${r}
|
| 101 |
}
|
| 102 |
|
| 103 |
# vim:ts=4
|