#!/bin/bash
# Set inet values
function set_inet()
{
# I don't want a troube here
# So ... let's always make a new script
# Old script will be overwritten !!!!
new_inet | sed "
s#^DEVICE=.*#DEVICE='$interface'#
s#^IPADDR=.*#IPADDR='$IP'#
s#^NETMASK=.*#NETMASK='$MASK'#
s#^GATEWAY=.*#GATEWAY='$GATEWAY'#
s#^DHCP=.*#DHCP='$DHCP'#
s#^PROBE=.*#PROBE='no'#" > $inet_file
sh $inet_file start
#| zenity --progress --text="Installing $1" --pulsate --auto-close
}
## Create a new inet script
function new_inet()
{
echo '
#!/bin/sh
# This file is supposed to be created by vnetadd
# and modified by vnetset.
# You can modify it by hand, but be careful ;-)
#
# GNU GPL (c) Eko M. Budi, 2004
# (c) Vector Linux, 2004
#
###########################################################
## The settings
DEVICE=eth0
DHCP="yes"
IPADDR=""
NETMASK=""
GATEWAY=""
PROBE="no"
###########################################################
## The script
'
echo "$secure"
echo '
## You may make customized script here
## If not, source the standard network
. /etc/rc.d/functions-network "$@"
'
}
## Create a new /etc/wpa_supplicant.conf
function new_wpa()
{
echo '
# See /usr/doc/wpa_supplicant-0.5.7/wpa_supplicant.conf.sample
# for many more options that you can use in this file.
# This line enables the use of wpa_cli which is used by rc.wireless
# if possible (to check for successful association)
ctrl_interface=/var/run/wpa_supplicant
# By default, only root (group 0) may use wpa_cli
ctrl_interface_group=0
eapol_version=1
ap_scan=1
fast_reauth=1
'
}
## find wireless interface
interface=$(/sbin/iwconfig 2>/dev/null| cut -d " " -f1 | grep [a-z])
if [ x$interface = x ];then
zenity --warning --text "no wireless cards found"
exit 1
fi
if [ $(echo $interface|wc|cut -d " " -f7) -gt 1 ];then
interface=$(zenity --list --title INTERFACE --column interface \
--text "choose wireless interface" \
$(/sbin/iwconfig 2>/dev/null| cut -d " " -f1 | grep [a-z]))
else
zenity --info --text "wireless interface $interface was found \
\n \n Lets set it up"
fi
## keep devices from switching names in udev
ifconfig $interface up
rules=/etc/udev/rules.d/network-devices.rules
#if [ -f $rules ];then
# if [ ! $(grep $interface $rules) ];then
rm $rules
ifconfig|grep HWaddr|while read i;do
iface=$(echo $i|cut -d " " -f1)
mac=$(echo $i|cut -d " " -f5)
echo "KERNEL==\"eth?\"\, SYSFS{address}==\"$mac\", NAME=\"$iface\"" >>$rules
done
# fi
#fi
security=$(zenity --list --title WIFI-SECURITY --radiolist --column choice \
--column Security --text "Choose type of wireless security" \
TRUE none FALSE wep FALSE wpa)
case $security in
none)
ESSID=$(zenity --entry --text "enter essid to connect")
# iwconfig $interface essid $ESSID
secure="iwconfig $interface essid $ESSID"
;;
wep)
ESSID=$(zenity --entry --text "enter essid to connect")
KEY=$(zenity --entry --text "enter wep password")
# iwconfig $interface essid $ESSID key $KEY
secure="iwconfig $interface essid $ESSID key $KEY"
;;
wpa)
ESSID=$(zenity --entry --text "enter essid to connect")
PASS=$(zenity --entry --text "enter wpa passphrase")
if $(grep -q $ESSID /etc/wpa_supplicant.conf 2>/dev/null);then
rm /etc/wpa_supplicant.conf
else
mv /etc/wpa_supplicant.conf /etc/wpa_supplicant.bak 2>/dev/null
fi
new_wpa >/etc/wpa_supplicant.conf
wpa_passphrase $ESSID $PASS >>/etc/wpa_supplicant.conf
# wpa_supplicant -B -Dwext -i$interface -c/etc/wpa_supplicant.conf
secure="wpa_supplicant -B -Dwext -i$interface -c/etc/wpa_supplicant.conf"
;;
esac
OPT=$(zenity --list --title WIFI-OPTIONS --checklist --column choice \
--column Option --separator=" " --text "Choose dhcp or static and whether to start interface at boot. \nDo Not choose dhcp and static!" \
TRUE "start at boot" TRUE dhcp FALSE static)
#hcp=$(zenity --question title DHCP? --text "use dhcp to get ip address?" )
##setup rc.inet3 instead of serching for which rc.inet to use
inet_file="/etc/rc.d/rc.inet3"
#for i in 1 2 3 4; do
# if [ -f /etc/rc.d/rc.inet$i ]; then
# if [ $(grep -q $interface /etc/rc.d/rc.inet$i) ]; then
# rm /etc/rc.d/rc.inet$i
# inet_file="/etc/rc.d/rc.inet$i"
# fi
# else
# inet_file="/etc/rc.d/rc.inet$i"
# break
# fi
#done
for i in $OPT;do
case $i in
boot)
BOOT=yes
;;
dhcp)
#/sbin/dhcpcd $interface
DHCP=yes
;;
static)
IP=$(zenity --entry --text "enter static ip address" \
--entry-text="192.168.0.2")
MASK=$(zenity --entry --text "enter netmask" \
--entry-text="255.255.255.0")
GATEWAY=$(zenity --entry --text "enter gateway" \
--entry-text="192.168.0.1")
DHCP=no
;;
esac
done
set_inet
if [ "$BOOT" = yes ];then
chmod a+x $inet_file
ifplug=/etc/ifplugd/ifplugd.conf
cp $ifplug ${ifplug}.bak
. $ifplug
INTERFACES="$INTERFACES $interface"
echo "INTERFACES=\"$INTERFACES\"" >$ifplug
echo "ARGS=\"-fwI -u1 -d5 -pql\"" >>$ifplug
fi
##check for an ipaddress and let the user know
ipaddr=$(ifconfig|grep inet|grep -v 127.0.0.1|cut -d " " -f12|cut -d ":" -f2)
if [ "$ipaddr" != "" ];then
zenity --info --title SUCCESS --text "wireless interface $interface is configured with address $ipaddr"
else
zenity --info --title FAILED --text "could not obtain an address for wireless interface $interface"
fi
exit 0