Updated documentation for 0.2 release
[mtetherd] / mtetherd-net-shutdown.sh
1 # mtetherd
2 # (c) 2010 Gregor Riepl <onitake@gmail.com>
3
4 # Tethering utility for Maemo
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 INTERFACE=$1
20 WAN=$2
21
22 log() {
23         echo $@
24         echo $(date): $@ >> /tmp/mtetherd-script.log
25 }
26
27 die() {
28         echo $@ >&2
29         echo $(date): $@ >> /tmp/mtetherd-script.log
30         exit 1
31 }
32
33 if [ "${INTERFACE}" = "" ]; then
34         die "Usage: $0 <interface> [<wan interface>]"
35 fi
36
37 log "Shutting down routing for: ${INTERFACE} ${WAN}"
38
39 echo "${INTERFACE}" | grep -E -q '^[a-zA-Z]+[0-9]+$' || die "Invalid interface name"
40 if [ "${WAN}" != "" ]; then
41         echo "${WAN}" | grep -E -q '^[a-zA-Z]+[0-9]+$' || die "Invalid WAN interface name"
42 fi
43
44 RUNFILE="/var/run/mtetherd.${INTERFACE}.pid"
45
46 log "echo 0 > /proc/sys/net/ipv4/conf/${INTERFACE}/forwarding"
47 echo 0 > /proc/sys/net/ipv4/conf/${INTERFACE}/forwarding
48 log "/sbin/start-stop-daemon -K -p \"${RUNFILE}\" -x /usr/sbin/dnsmasq"
49 msg=$(/sbin/start-stop-daemon -K -p "${RUNFILE}" -x /usr/sbin/dnsmasq 2>&1)
50 log "$msg"
51 if [ "${WAN}" != "" ]; then
52         log "/usr/sbin/iptables -t nat -D POSTROUTING -o ${WAN} -j MASQUERADE"
53         msg=$(/usr/sbin/iptables -t nat -D POSTROUTING -o ${WAN} -j MASQUERADE 2>&1)
54         log $msg
55 fi
56
57 log "Finished shutting down routing for ${INTERFACE}"
58