Fixed network setup scripts
[mtetherd] / mtetherd-usbnet-enable.sh
1 #!/bin/sh
2 # This file is part of mtetherd
3 #
4 # Copyright (c) 2010 Gregor Riepl <onitake@gmail.com>
5 #
6 # Based on osso-usb-mass-storage-enable.sh and osso-usb-mass-storage-disable.sh,
7 # Copyright (C) 2004-2009 Nokia Corporation. All rights reserved.
8 # Contact: Kimmo Hämäläinen <kimmo.hamalainen@nokia.com>
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License 
12 # version 2 as published by the Free Software Foundation. 
13 #
14 # This program is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 # 02110-1301 USA
23
24 RC=0
25
26 /sbin/lsmod | grep g_nokia > /dev/null
27 if [ $? = 0 ]; then
28     logger "$0: removing g_nokia"
29
30     initctl emit G_NOKIA_REMOVE
31
32     PNATD_PID=`pidof pnatd`
33     if [ $? = 0 ]; then
34         kill $PNATD_PID
35     else
36         logger "$0: pnatd is not running"
37     fi
38     OBEXD_PID=`pidof obexd`
39     if [ $? = 0 ]; then
40         kill -HUP $OBEXD_PID
41     else
42         logger "$0: obexd is not running"
43     fi
44     SYNCD_PID=`pidof syncd`
45     if [ $? = 0 ]; then
46         kill $SYNCD_PID
47     else
48         logger "$0: syncd is not running"
49     fi
50
51     sleep 2
52     /sbin/rmmod g_nokia
53     if [ $? != 0 ]; then
54         logger "$0: failed to rmmod g_nokia!"
55         exit 1
56     fi
57 fi
58
59 /sbin/lsmod | grep g_file_storage > /dev/null
60 if [ $? = 0 ]; then
61     logger "$0: removing g_file_storage"
62
63     GADGETPATH='/sys/devices/platform/musb_hdrc/gadget'
64     LUN0='gadget-lun0'
65     LUN1='gadget-lun1'
66
67     if [ $# = 0 ]; then
68       # unload all
69       echo "" > $GADGETPATH/$LUN0/file
70       echo "" > $GADGETPATH/$LUN1/file
71       exit 0
72     fi
73
74     # NOTE: works only for 1 or 2 device arguments
75     for lun in $LUN0 $LUN1; do
76       grep $1 $GADGETPATH/$lun/file > /dev/null
77       RC=$?
78
79       if [ $# = 2 ]; then
80         grep $2 $GADGETPATH/$lun/file > /dev/null
81         RC2=$?
82       else
83         RC2=1
84       fi
85
86       if [ $RC = 0 -o $RC2 = 0 ]; then
87         echo "" > $GADGETPATH/$lun/file
88       fi
89     done
90
91     /sbin/rmmod g_file_storage
92     if [ $? != 0 ]; then
93         logger "$0: failed to rmmod g_file_storage!"
94         exit 1
95     fi
96 fi
97
98 /sbin/lsmod | grep g_ether > /dev/null
99 if [ $? != 0 ]; then
100     /sbin/modprobe g_ether
101     RC=$?
102 fi
103
104 if [ $RC != 0 ]; then
105     logger "$0: failed to install g_ether"
106     exit 1
107 fi
108
109 exit 0