conn

A script repository to manage connections in Linux.
git clone git://r-36.net/conn
Log | Files | Refs | LICENSE

commit 579cd65912785d0cc507747e4512b964d52a38f0
parent f97c5f1f20b3db74df156013a5987c401e896f14
Author: Christoph Lohmann <20h@r-36.net>
Date:   Thu, 30 Jun 2011 01:36:24 +0200

Removing the bash dependency.

Diffstat:
README.md | 2+-
config.mk | 2+-
etc/conn/common.sh | 17++++++++---------
etc/conn/config.sh | 7++++++-
etc/conn/run.sh | 18+++++++++---------
examples/eth/run.sh | 4++--
examples/wifi/run.sh | 2+-
examples/wifi/wlan0-action.sh | 10+++++-----
examples/wwan/ppp0-run.sh | 5+++--
examples/wwan/run.sh | 6+++---
10 files changed, 39 insertions(+), 34 deletions(-)

diff --git a/README.md b/README.md @@ -5,7 +5,7 @@ many different connections in a Unix like environment. ## Dependencies -* bash (Could be easily rewritten.) +* sh * dhcpcd * wpa-supplicant * ping diff --git a/config.mk b/config.mk @@ -1,5 +1,5 @@ # conn version -VERSION = 0.5 +VERSION = 0.6 # Customize below to fit your system diff --git a/etc/conn/common.sh b/etc/conn/common.sh @@ -64,19 +64,19 @@ getstate() { } getstates() { - getstate $1 | grep "$2 $3" + getstate $1 | egrep "$2|$3" return 0 } isset() { - isin=`getstate $1 | grep "$2 $3"` - [ "$isin" == "" ] && return 1 + isin=`getstate $1 | grep "$2|$3"` + [ -z "$isin" ] && return 1 return 0 } addstate() { isset $1 $2 $3 && return 1 - echo "$2 $3" >> $STATEDIR/$1 + echo "$2|$3" >> $STATEDIR/$1 } delstate() { @@ -86,7 +86,7 @@ delstate() { then return 1 else - cat $STATEDIR/$1 | grep -v "$2 $3" \ + cat $STATEDIR/$1 | grep -v "$2|$3" \ > $STATEDIR/$1.bak mv $STATEDIR/$1.bak $STATEDIR/$1 fi @@ -125,8 +125,7 @@ stopwpa() { # $WPA_ID must be set from within the calling action script. getssid() { $WPACLIREQ -i $1 list_networks \ - | grep "^$WPA_ID" \ - | awk -F'\t' '{print $2}' + | awk -F'\t' "/^$WPA_ID/ {print \$2}" } ## DHCP handling @@ -182,7 +181,7 @@ setlinkdown() { islinkup() { state=`ip link show $1 2>/dev/null | grep ',UP'` - if [ "$state" == "" ]; + if [ -z "$state" ]; then return 1 else @@ -193,7 +192,7 @@ islinkup() { ## Rfkill handling isblocked() { res=`rfkill list $1 | grep ' yes'` - if [ "$res" == "" ]; + if [ -z "$res" ]; then return 1 else diff --git a/etc/conn/config.sh b/etc/conn/config.sh @@ -95,5 +95,10 @@ PINGHOST="8.8.8.8" # # If a connection type is blocked by rfkill, should it be unblocked? # -DOUNBLOCK=0 +DOUNBLOCK=1 + +# +# Should a connection be blocked, when it is killed? +# +DOBLOCK=1 diff --git a/etc/conn/run.sh b/etc/conn/run.sh @@ -58,7 +58,7 @@ do ;; esac done -shift $(($OPTIND - 1)) +shift `expr $OPTIND - 1` if [ $dolist -eq 1 ]; then @@ -74,7 +74,7 @@ fi if [ $dolistopen -eq 1 ]; then conns=`getstate "open"` - if [ "$conns" == "" ]; + if [ -z "$conns" ]; then echo "There are no connections open." exit 1 @@ -111,7 +111,7 @@ then exit $? fi -if [ "$cmdarg" == "" ]; +if [ -z "$cmdarg" ]; then usage $0 exit 1 @@ -119,7 +119,7 @@ fi connection=$1 profile=$2 -if [ "$1" == "" ]; +if [ -z "$1" ]; then if [ $dostart -eq 1 ] && [ ! $dowakeup -eq 1 ]; then @@ -128,16 +128,16 @@ then conns=`getstate "open"` fi - [ "$conns" == "" ] && exit 0 + [ -z "$conns" ] && exit 0 [ $doforce -eq 1 ] && cmdarg="-f $cmdarg" for conn in $conns; do - args=(`echo $conn`) - [ ${#args[@]} -eq 0 ] && continue - [ ${#args[@]} -eq 1 ] && args[1]="" + narg0=`echo $conn | awk -F'|' '{print $1}'` + [ -z "$narg0" ] && continue; + narg1=`echo $conn | awk -F'|' '{print $2}'` - $0 $cmdarg ${args[0]} ${args[1]} + $0 $cmdarg $narg0 $nargs1 exit 0 done diff --git a/examples/eth/run.sh b/examples/eth/run.sh @@ -3,7 +3,7 @@ . ../common.sh interface=$2 -[ "$2" == "" ] && interface="eth0" +[ -z "$2" ] && interface="eth0" case "$1" in -s) @@ -20,7 +20,6 @@ case "$1" in exit $? ;; -u) - exit $? ;; -r) $0 -k $interface; @@ -31,4 +30,5 @@ case "$1" in exit 1 ;; esac +exit 0 diff --git a/examples/wifi/run.sh b/examples/wifi/run.sh @@ -3,7 +3,7 @@ . ../common.sh interface=$2 -[ "$2" == "" ] && interface="wlan0" +[ -z "$2" ] && interface="wlan0" case "$1" in -s) diff --git a/examples/wifi/wlan0-action.sh b/examples/wifi/wlan0-action.sh @@ -7,7 +7,7 @@ WIFIDIR="${ETCDIR}/wifi" interface="$1" action="$2" ssid="$3" -[ "$ssid" == "" ] && ssid=`getssid $interface` +[ -z "$ssid" ] && ssid=`getssid $interface` [ $LOGGING -eq 1 ] && \ logger -t "$interface-action" "Got request for $interface $ssid $action." @@ -16,16 +16,16 @@ getscript() { awk -F'\t' "/$1\$/ {print \$1}" ${WIFIDIR}/networks.tbl } -if [ "$ssid" != "" ]; +if [ ! -z "$ssid" ]; then case "$action" in CONNECTED) aps=`getstates "wifi" $interface $ssid` - if [ "$aps" != "" ]; + if [ ! -z "$aps" ]; then for i in "$aps": do - issid=`echo $i | awk '{print $2}'` + issid=`echo $i | awk -F'|' '{print $2}'` $0 $interface DISCONNECTED $issid done fi @@ -41,7 +41,7 @@ then esac script=`getscript $ssid` - if [ "$script" != "" ]; + if [ ! -z "$script" ]; then cd ${WIFIDIR}/networks ./$script $interface $action diff --git a/examples/wwan/ppp0-run.sh b/examples/wwan/ppp0-run.sh @@ -28,11 +28,12 @@ case "$1" in sleep 0.5 ip link show $interface 2>&1 >/dev/null done + echo "done" echo -n "Waiting for $interface to be online ..." i=0 - while [ "`ip addr show dev $interface 2>/dev/null \ - | grep inet`" == "" ]; + while [ -z "`ip addr show dev $interface 2>/dev/null \ + | grep inet`" ]; do i=`expr $i + 1` if [ $i -gt 100 ]; diff --git a/examples/wwan/run.sh b/examples/wwan/run.sh @@ -14,8 +14,8 @@ then fi fi -inteface=$2 -[ "$2" == "" ] && interface="ppp0" +interface=$2 +[ -z "$2" ] && interface="ppp0" iffile="${WWANDIR}/${interface}-run.sh" @@ -23,7 +23,7 @@ iffile="${WWANDIR}/${interface}-run.sh" $iffile $1 -if [ "$1" == "-k" ] && [ $DOBLOCK -eq 1 ] && ! isblocked "wwan"; +if [ "$1" = "-k" ] && [ $DOBLOCK -eq 1 ] && ! isblocked "wwan"; then doblock "wwan" sleep 4