blob: 08ff2a21cbbe8bac0a08993e633af8cefde4bd9e [file] [log] [blame]
#!/bin/sh
. /etc/utils.sh
# Prints the ethernet MAC address of eth0.
get_mac_addr()
{
ip link show eth0 | (
read junk
read words macaddr junk
echo $macaddr
)
}
# Prints the first word of the first line on stdin
firstword()
{
read word junk
echo "$word"
}
# Given an ssid format string in $1, replace a %d or %s in the format string
# with a number between 1 and 5, based on a number generated from the
# machine's ethernet MAC address. If no %-substitution exists in the
# string, returns the string unmodified.
render_ssid()
{
local ssid="$1"
local macaddr=$(get_mac_addr)
local macsha="$(echo $macaddr | sha1sum | firstword)"
local last_4_digits=0x${macsha#????????????????????????????????????}
local ssid="$(printf "$ssid" $(($last_4_digits % 5 + 1)))"
echo "$ssid"
}
# Returns true if the machine is a fat bruno (ie. has storage)
is_fat()
{
[ -e $(find_sata_blkdev) ] && grep GFMS /tmp/platform >/dev/null
}
if [ -n "$1" ]; then
SSID=$1
else
SSID=Gladis_%d
fi
SSID=$(render_ssid "$SSID")
set -x
if ! is_fat; then
brctl delif br0 eth2
wl radio on
wl down
wl ap 0
wl band auto
wl up
wl scan
sleep 3
wl scanresults
wl join "$SSID"
sleep 1
wl status
dhclient eth2
fi
exit 0