summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ethernet.subr28
-rw-r--r--src/network.subr26
-rw-r--r--src/ppp.subr6
-rw-r--r--src/wireless.subr28
4 files changed, 44 insertions, 44 deletions
diff --git a/src/ethernet.subr b/src/ethernet.subr
index 39ae11a..ca694b7 100644
--- a/src/ethernet.subr
+++ b/src/ethernet.subr
@@ -4,7 +4,7 @@ mii_check() {
local conn_state=$(mii-tool $1 2> /dev/null)
local ret=$?
if echo $conn_state|grep "no link" &> /dev/null; then
- if [ $ret -eq 0 ]; then
+ if [[ $ret -eq 0 ]]; then
return 1
fi
fi
@@ -14,7 +14,7 @@ mii_check() {
ethernet_up() {
- if [ ! -e /sys/class/net/$INTERFACE ]; then
+ if [[ ! -e /sys/class/net/$INTERFACE ]]; then
if ! echo "$INTERFACE"|grep ":"; then
err_append "Interface $INTERFACE does not exist"
fi
@@ -28,7 +28,7 @@ ethernet_up() {
case $IP in
dhcp)
# Check if DHCP_TIMEOUT was set if not set a default value
- [ -z $DHCP_TIMEOUT ] && DHCP_TIMEOUT=10
+ [[ -z "$DHCP_TIMEOUT" ]] && DHCP_TIMEOUT=10
if checkyesno $DHCLIENT; then
rm -r /var/run/dhclient-${INTERFACE}.pid >/dev/null 2>&1
@@ -40,7 +40,7 @@ ethernet_up() {
# Clear remaining pid files.
rm -f /var/run/dhcpcd-${INTERFACE}.{pid,cache} >/dev/null 2>&1
# If using own dns, tell dhcpcd to NOT replace resolv.conf
- [ -n $DNS1 ] && DHCP_OPTIONS="-R $DHCP_OPTIONS"
+ [[ -n "$DNS1" ]] && DHCP_OPTIONS="-R $DHCP_OPTIONS"
# Start dhcpcd
if ! dhcpcd -L -t $DHCP_TIMEOUT $DHCP_OPTIONS $INTERFACE; then
err_append "DHCP IP lease attempt failed"
@@ -56,7 +56,7 @@ ethernet_up() {
fi
# bring up the default route (gateway)
- if [ "$GATEWAY" ]; then
+ if [[ -n "$GATEWAY" ]]; then
if ! route add default gw $GATEWAY; then
err_append "Adding gateway $GATEWAY failed"
return 1
@@ -66,7 +66,7 @@ ethernet_up() {
esac
# set the hostname
- if [ "$HOSTNAME" ]; then
+ if [[ -n "$HOSTNAME" ]]; then
if ! hostname $HOSTNAME; then
err_append "Cannot set hostname"
return 1
@@ -74,12 +74,12 @@ ethernet_up() {
fi
# Generate a new resolv.conf
- if [ "$DNS1" ]; then
+ if [[ -n "$DNS1" ]]; then
: >/etc/resolv.conf
- [ "$DOMAIN" ] && echo "domain $DOMAIN" >>/etc/resolv.conf
- [ "$SEARCH" ] && echo "search $SEARCH" >>/etc/resolv.conf
- [ "$DNS1" ] && echo "nameserver $DNS1" >>/etc/resolv.conf
- [ "$DNS2" ] && echo "nameserver $DNS2" >>/etc/resolv.conf
+ [[ -n "$DOMAIN" ]] && echo "domain $DOMAIN" >>/etc/resolv.conf
+ [[ -n "$SEARCH" ]] && echo "search $SEARCH" >>/etc/resolv.conf
+ [[ -n "$DNS1" ]] && echo "nameserver $DNS1" >>/etc/resolv.conf
+ [[ -n "$DNS2" ]] && echo "nameserver $DNS2" >>/etc/resolv.conf
fi
}
@@ -87,17 +87,17 @@ ethernet_down() {
case $IP in
dhcp)
if checkyesno $DHCLIENT; then
- if [ -f /var/run/dhclient-${INTERFACE}.pid ]; then
+ if [[ -f /var/run/dhclient-${INTERFACE}.pid ]]; then
kill `cat /var/run/dhclient-${INTERFACE}.pid`
fi
else
- if [ -f /var/run/dhcpcd-${INTERFACE}.pid ]; then
+ if [[ -f /var/run/dhcpcd-${INTERFACE}.pid ]]; then
dhcpcd -x $INTERFACE
fi
fi
;;
static)
- [ "$GATEWAY" ] && route del default gw $GATEWAY
+ [[ -n "$GATEWAY" ]] && route del default gw $GATEWAY
;;
esac
ifconfig $INTERFACE 0.0.0.0
diff --git a/src/network.subr b/src/network.subr
index b1d8e12..d571e3d 100644
--- a/src/network.subr
+++ b/src/network.subr
@@ -25,17 +25,17 @@ load_profile() {
# check whether profile exists and is usable
validate_profile()
{
- [ -z "$1" ] && return 1
- if [ ! -f $PROFILE_DIR/$1 ]; then
+ [[ -z "$1" ]] && return 1
+ if [[ ! -f $PROFILE_DIR/$1 ]]; then
err "Profile \"$1\" does not exist"
return 1
fi
. $PROFILE_DIR/$1
- if [ -z "$INTERFACE" ]; then
+ if [[ -z "$INTERFACE" ]]; then
err "Profile missing an interface to configure"
return 1
fi
- if [ ! -f $SUBR_DIR/$CONNECTION.subr ]; then
+ if [[ ! -f $SUBR_DIR/$CONNECTION.subr ]]; then
err "$CONNECTION is not a valid connection, check spelling or look at examples"
return 1
fi
@@ -58,7 +58,7 @@ all_down()
#
all_suspend()
{
- [ ! -d $STATE_DIR/suspend ] && mkdir $STATE_DIR/suspend
+ [[ ! -d $STATE_DIR/suspend ]] && mkdir $STATE_DIR/suspend
ls -1 $STATE_DIR/profiles/ | while read prof; do
cp $STATE_DIR/profiles/$prof $STATE_DIR/suspend/
@@ -129,7 +129,7 @@ profile_down()
fi
stat_busy "$1 down"
- if [ "$(get_iface_prof $INTERFACE)" == "external" ]; then
+ if [[ "$(get_iface_prof $INTERFACE)" == "external" ]]; then
err_append "$interface was connected by another application"
stat_fail
return 1
@@ -168,7 +168,7 @@ interface_down()
# Return 1 if interface down
#
check_iface() {
- [ -f $STATE_DIR/interfaces/$1 ] && return 0
+ [[ -f $STATE_DIR/interfaces/$1 ]] && return 0
return 1
}
@@ -190,7 +190,7 @@ get_iface_prof() {
# Return 1 if profile down
#
check_profile() {
- [ -f $STATE_DIR/profiles/$1 ] && return 0
+ [[ -f $STATE_DIR/profiles/$1 ]] && return 0
return 1
}
@@ -200,11 +200,11 @@ check_profile() {
# Set profile state, either up or down
#
set_profile() {
- if [ "$1" == "up" ]; then
+ if [[ "$1" == "up" ]]; then
. $PROFILE_DIR/$2
cp $PROFILE_DIR/$2 $STATE_DIR/profiles/
set_iface up $INTERFACE $2
- elif [ "$1" == "down" ]; then
+ elif [[ "$1" == "down" ]]; then
. $STATE_DIR/profiles/$2
rm $STATE_DIR/profiles/$2
set_iface down $INTERFACE $2
@@ -217,10 +217,10 @@ set_profile() {
#
set_iface() {
PROFILE=$3
- [ -z "$PROFILE" ] && PROFILE=external
- if [ "$1" == "up" ]; then
+ [[ -z "$PROFILE" ]] && PROFILE=external
+ if [[ "$1" == "up" ]]; then
echo "PROFILE=$PROFILE" > $STATE_DIR/interfaces/$2
- elif [ "$1" == "down" ]; then
+ elif [[ "$1" == "down" ]]; then
rm $STATE_DIR/interfaces/$2
fi
}
diff --git a/src/ppp.subr b/src/ppp.subr
index b659881..c78325e 100644
--- a/src/ppp.subr
+++ b/src/ppp.subr
@@ -1,11 +1,11 @@
#! /bin/bash
ppp_up() {
- [ -z "$PEER" ] && PEER="/etc/ppp/peers/provider"
- [ -z "$PPP_TIMEOUT" ] && PPP_TIMEOUT=30
+ [[ -z "$PEER" ]] && PEER="/etc/ppp/peers/provider"
+ [[ -z "$PPP_TIMEOUT" ]] && PPP_TIMEOUT=30
/usr/sbin/pppd call $PEER updetach child-timeout $PPP_TIMEOUT linkname $(basename $PEER)
- if [ $? -ne 0 ]; then
+ if [[ $? -ne 0 ]]; then
err_append "pppd connection failed"
exit 1
fi
diff --git a/src/wireless.subr b/src/wireless.subr
index 69550bc..373b22f 100644
--- a/src/wireless.subr
+++ b/src/wireless.subr
@@ -6,11 +6,11 @@ wpa_check()
{
INTERFACE=$1; TIMEOUT=$2
- [ -z $TIMEOUT ] && TIMEOUT=15
+ [[ -z "$TIMEOUT" ]] && TIMEOUT=15
let timeout=0
- while [ $timeout -ne $TIMEOUT ]; do
+ while [[ $timeout -ne $TIMEOUT ]; do
eval `wpa_cli status|grep wpa_state`
- [ "$wpa_state" = "COMPLETED" ] && return 0
+ [[ "$wpa_state" = "COMPLETED" ]] && return 0
sleep 1
let timeout++
done
@@ -26,11 +26,11 @@ wep_check()
{
INTERFACE=$1; TIMEOUT=$2
- [ -z $TIMEOUT ] && TIMEOUT=15
+ [[ -z "$TIMEOUT" ]] && TIMEOUT=15
let timeout=0
- while [ $timeout -ne $TIMEOUT ]; do
+ while [[ $timeout -ne $TIMEOUT ]; do
bssid=`iwgetid $INTERFACE -ra`
- [ ! "$bssid" = "00:00:00:00:00:00" ] && return 0
+ [[ ! "$bssid" = "00:00:00:00:00:00" ]] && return 0
sleep 1
let timeout++
done
@@ -45,7 +45,7 @@ find_essid()
{
INTERFACE=$1; ESSID=$2; RETRIES=4
try=0;
- while [ $try -ne $RETRIES ]; do
+ while [[ $try -ne $RETRIES ]; do
if iwlist $INTERFACE scan|sed "s/ESSID://g"|grep -q "\"$ESSID\""; then
return 0 # network found
fi
@@ -85,12 +85,12 @@ start_wpa()
{
INTERFACE=$1; WPA_CONF=$2; WPA_OPTS=$3
- [ "$WPA_OPTS" == "" ] && WPA_OPTS="-Dwext"
+ [[ "$WPA_OPTS" == "" ]] && WPA_OPTS="-Dwext"
wpa_supplicant -wB -P/var/run/wpa_supplicant_${INTERFACE}.pid -i${INTERFACE} -c $WPA_CONF $WPA_OPTS
sleep 1
- if [ ! -f /var/run/wpa_supplicant_${INTERFACE}.pid ]; then
+ if [[ ! -f /var/run/wpa_supplicant_${INTERFACE}.pid ]; then
err_append "wpa_supplicant did not start, possible configuration error"
return 1
fi
@@ -100,7 +100,7 @@ wireless_up() {
load_profile $1
- if [ ! -d /sys/class/net/$INTERFACE/wireless ]; then
+ if [[ ! -d /sys/class/net/$INTERFACE/wireless ]; then
err_append "Interface $INTERFACE is not a wireless interface"
return 1
fi
@@ -115,7 +115,7 @@ wireless_up() {
eval "iwconfig $INTERFACE mode managed essid \"$ESSID\""
# Kill any lingering wpa_supplicants.
- if [ -f /var/run/wpa_supplicant_$INTERFACE.pid ]; then
+ if [[ -f /var/run/wpa_supplicant_$INTERFACE.pid ]; then
kill $(cat /var/run/wpa_supplicant_$INTERFACE.pid)
fi
@@ -130,9 +130,9 @@ wireless_up() {
wep|none)
# 'none' security uses iwconfig, like wep, so use same code, minus keysetting.
# Use sane default if no alternative is specified
- if [ "$SECURITY" = "wep" -a "$WEP_OPTS" = "" ]; then
+ if [[ "$SECURITY" = "wep" -a "$WEP_OPTS" = "" ]; then
WEP_OPTS="mode managed essid \"$ESSID\" key open $KEY"
- elif [ "$SECURITY" = "none" -a "$WEP_OPTS" = "" ]; then
+ elif [[ "$SECURITY" = "none" -a "$WEP_OPTS" = "" ]; then
WEP_OPTS="mode managed essid \"$ESSID\""
fi
@@ -169,7 +169,7 @@ wireless_up() {
;;
wpa-config)
# If user hasnt defined one, use stock config.
- [ -z "$WPA_CONF" ] && WPA_CONF="/etc/wpa_supplicant.conf"
+ [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf"
start_wpa $INTERFACE $WPA_CONF $WPA_OPTS || return 1
wpa_check $INTERFACE $TIMEOUT || return 1
;;