Dash:
[t2.git] / package / network / rocknet / ifup.sh
blob1fffc2f91a9131788e3e9c26ffd316de9c9293fd
1 #!/bin/bash
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by scripts/Create-CopyPatch.
4 #
5 # T2 SDE: package/*/rocknet/ifup.sh
6 # Copyright (C) 2004 - 2021 The T2 SDE Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
16 rocknet_tmp_base="/var/run/rocknet"
17 [ -d $rocknet_tmp_base ] || mkdir -p $rocknet_tmp_base
19 var_contains() {
20 local tmp
21 eval "tmp=\"\$$1\""
23 [ "${tmp/$3$2/}" != "$tmp" ]
26 usage() {
27 echo "Usage: $0 interface [ profile ] [ -force ]"
28 exit 1
31 force=0
33 if="$1" ; shift ; [ "$if" ] || usage
34 profile=""
35 action="${0/#*\/if}"
37 while [ "$1" ] ; do
38 case $1 in
39 -force) force=1 ;;
40 *) [ "$profile" = "" ] && profile="$1" || usage ;;
41 esac
42 shift
43 done
45 [ "$profile" ] || profile="`cat /etc/conf/network-profile 2> /dev/null`"
46 profile=${profile:-default}
48 # sanity checks (...)
50 if [ $force -eq 0 ] ; then
51 active_interfaces="`cat $rocknet_tmp_base/active-interfaces 2>/dev/null`"
53 if test $action = "up" && var_contains active_interfaces ',' "$if($profile)"
54 then
55 echo "Interface $if($profile) is already listed active, it is probably a good idea to"
56 echo "take it down before activating it. Use -force to suppress this warning."
57 exit 2
60 if test $action = "down" && ! var_contains active_interfaces ',' "$if($profile)"
61 then
62 echo "Interface $if($profile) is not listed active, it is probably a good idea to"
63 echo "activate it before deactivating it. Use -force to suppress this warning."
64 exit 2
68 /sbin/rocknet "$profile" "$if" "$action"
69 echo "$profile" > /etc/conf/network-profile