--- netconfig.orig 2008-03-19 17:45:19.000000000 -0300 +++ netconfig 2008-05-20 10:25:32.000000000 -0300 @@ -78,7 +78,7 @@ for((x=0;x<${HOW_MUCH_CALCULATE};x++)); do /sbin/ifconfig eth${x} > /dev/null 2>&1 if [ $? -eq 0 ]; then - IS_IT_WIFI=$(cat /proc/net/wireless | grep eth${x} | sed -e 's/ //g' | awk -F[:] '{print $1}') + IS_IT_WIFI=$(cat /proc/net/wireless 2>/dev/null | grep eth${x} | sed -e 's/ //g' | awk -F[:] '{print $1}') if [ "${IS_IT_WIFI}" != "eth${x}" ]; then if [ -n "${IPADDR[${x}]}" ]; then echo eth${x} ${IPADDR[${x}]} @@ -239,8 +239,17 @@ echo 2 "Static" } +function Exit(){ + rm $TEMP + for i in $(say_ifs() | awk '{print $1}'); do + bash /etc/rc.d/rc.inet $i restart + done + exit 0 +} + + if [ `id -u` -ne 0 ]; then - exit + Exit fi TOTAL_DNS=0 @@ -248,18 +257,21 @@ HOSTNAM=`cat /etc/HOSTNAME` dns_init calc_ifs +TEMP=$TMP/tmp.random +touch $TEMP while [ 1 ]; do - TODO=$(${DIALOG} --backtitle "Kwort Network Manager" --extra-button --extra-label "Save Conf" --cancel-label "Close" --stdout --title "Networking" --menu "What do you want to do?" 7 0 0 \ + ${DIALOG} --backtitle "Kwort Network Manager" --extra-button --extra-label "Save Conf" --cancel-label "Close" --title "Networking" --menu "What do you want to do?" 7 0 0 \ 1 "Configure lan devices" \ 2 "Configure wlan devices" \ 3 "Set Gateway" \ 4 "Set DNS's" \ 5 "Set Machine's Name" \ - 6 "Use a temporal Wireless access" \ - ) + 6 "Use a temporal Wireless access" 2>$TEMP RETMAIN=$? + TODO=$(cat $TEMP) + if [ "${RETMAIN}" = "1" ]; then - exit + Exit fi if [ "${RETMAIN}" = "3" ]; then write_inet1conf @@ -268,7 +280,8 @@ fi if [ "${TODO}" = "1" ]; then if [ ${IF_TOTAL} -ne 0 ]; then - IF_CONF=$(${DIALOG} --backtitle "Kwort Network Manager" --cancel-label "Back" --stdout --title "Networking" --menu "Network Card Chooser" 0 0 $((${IF_TOTAL} + 1)) `say_ifs`) + ${DIALOG} --backtitle "Kwort Network Manager" --cancel-label "Back" --title "Networking" --menu "Network Card Chooser" 0 0 $((${IF_TOTAL} + 1)) `say_ifs` 2>$TEMP + IF_CONF=$(cat $TEMP) if [ $? -ne 0 ]; then continue fi @@ -281,8 +294,20 @@ if [ -z "${IF_CONF}" ]; then continue fi - DHCP=$(${DIALOG} --default-item ${DEF_ITEM} --backtitle "Kwort Network Manager" --stdout --title "Networking" --menu "Network Type" 0 0 3 \ - `conf_card_opts`) + + dhcp-test eth${IF_NUM} + if [ $? -eq 0 ]; then + ${DIALOG} --backtitle "Kwort Network Manager" --title "Networking" --yesno "There's DHCP available, want to use it?" 0 0 + if [ $? -eq 0 ]; then + DHCP="1" + else + DHCP="2" + fi + else + ${DIALOG} --default-item ${DEF_ITEM} --backtitle "Kwort Network Manager" --title "Networking" --menu "Network Type" 0 0 3 \ + `conf_card_opts` 2>$TEMP + DHCP=$($TEMP) + fi if [ "${DHCP}" = "2" ]; then if [ ! -z "${IPADDR[${IF_NUM}]}" ]; then HOSTNM=$(cat /etc/hosts | grep ${IPADDR[${IF_NUM}]} | awk -F " " '{print $2}' | tail -n 1) @@ -292,17 +317,18 @@ fi while true; do if [ "${USE_DIALOG}" = "1" ]; then - OUTPUT=$(${DIALOG} --stdout --title "Networking" --ok-label Accept --extra-label Edit --cancel-label Cancel ${FORM1} \ + ${DIALOG} --title "Networking" --ok-label Accept --extra-label Edit --cancel-label Cancel ${FORM1} \ "Change the settings ${IF_CONF}" 16 50 9 \ - "Hostname:" "$HOSTNM" "IP address:" "${IPADDR[${IF_NUM}]}" "Netmask:" "${NETMASK[${IF_NUM}]}" \ - ) + "Hostname:" "$HOSTNM" "IP address:" "${IPADDR[${IF_NUM}]}" "Netmask:" "${NETMASK[${IF_NUM}]}" 2>$TEMP else - OUTPUT=$(${DIALOG} --stdout --title "Networking" --ok-label Accept --cancel-label Cancel ${FORM1} \ + ${DIALOG} --title "Networking" --ok-label Accept --cancel-label Cancel ${FORM1} \ "Change the settings ${IF_CONF}" 0 0 \ - "Hostname:" "$HOSTNM" "IP address:" "${IPADDR[${IF_NUM}]}" "Netmask:" "${NETMASK[${IF_NUM}]}" \ - ) + "Hostname:" "$HOSTNM" "IP address:" "${IPADDR[${IF_NUM}]}" "Netmask:" "${NETMASK[${IF_NUM}]}" 2>$TEMP fi + RETVAL=$? + OUTPUT=$(cat $TEMP) + if [ "${RETVAL}" = "0" ]; then if [ "${USE_DIALOG}" = "0" ]; then IFS='/' @@ -330,6 +356,8 @@ fi fi done + USE_DHCP[${IF_NUM}]="no" + DHCP_HOSTNAME[${IF_NUM}]="" else IPADDR[${IF_NUM}]="" NETMASK[${IF_NUM}]="" @@ -371,25 +399,29 @@ DATA=() say_essids ${WI_IF} if [ "${USE_DIALOG}" = "1" ]; then - WIFI_CONF=$(${DIALOG} --backtitle "Kwort Network Manager" --cancel-label "Back" --stdout --title "Networking" --ok-label "USE THIS" \ - --extra-button --extra-label "Rescan Networks" --menu "Choose which wireless network do you want to associate" 10 58 ${HOWMUCHESSIDS} "${DATA[@]}") + ${DIALOG} --backtitle "Kwort Network Manager" --cancel-label "Back" --title "Networking" --ok-label "USE THIS" \ + --extra-button --extra-label "Rescan Networks" --menu "Choose which wireless network do you want to associate" 10 58 ${HOWMUCHESSIDS} "${DATA[@]}" 2>$TEMP else - WIFI_CONF=$(${DIALOG} --backtitle "Kwort Network Manager" --cancel-label "Back" --stdout --title "Networking" --ok-label "USE THIS" \ - --extra-button --extra-label "Rescan Networks" --menu "Choose which wireless network do you want to associate" 0 0 $((${HOWMUCHESSIDS} + 1)) "${DATA[@]}") + ${DIALOG} --backtitle "Kwort Network Manager" --cancel-label "Back" --title "Networking" --ok-label "USE THIS" \ + --extra-button --extra-label "Rescan Networks" --menu "Choose which wireless network do you want to associate" 0 0 $((${HOWMUCHESSIDS} + 1)) "${DATA[@]}" 2>$TEMP fi + WIFI_CONF=$(cat $TEMP) if [ -z "${WIFI_CONF}" ]; then break fi if [ "${RETVAL}" = "3" ]; then continue fi + if [ "${USE_DIALOG}" = "1" ]; then - WLAN_KEY[4]=$(${DIALOG} --backtitle "Kwort Network Manager" --stdout --title "Networking" --inputbox "Insert SKEY" 8 40) - RETINGI=$? + ${DIALOG} --backtitle "Kwort Network Manager" --title "Networking" --inputbox "Insert SKEY" 8 40 2>$TEMP else - WLAN_KEY[4]=$(${DIALOG} --backtitle "Kwort Network Manager" --stdout --title "Networking" --inputbox "Insert SKEY" 0 0) - RETINGI=$? + ${DIALOG} --backtitle "Kwort Network Manager" --title "Networking" --inputbox "Insert SKEY" 0 0 fi + + RETINGI=$? + WLAN_KEY[4]=$(cat $TEMP) + if [ $RETINGI -ne 0 ]; then continue fi @@ -399,24 +431,24 @@ WLAN_ESSID[4]=${ESSIDS[${SUBINDIC}]} HWADDR[4]=${MACS[${SUBINDIC}]} if [ "${USE_DIALOG}" = "1" ]; then - DHCP=$(${DIALOG} --default-item 1 --backtitle "Kwort Network Manager" --stdout --title "Networking" \ - --menu "Do you want to use ${WIFI_CONF} with:" 10 40 2 `conf_card_opts`) + ${DIALOG} --default-item 1 --backtitle "Kwort Network Manager" --title "Networking" \ + --menu "Do you want to use ${WIFI_CONF} with:" 10 40 2 `conf_card_opts` 2>$TEMP else - DHCP=$(${DIALOG} --default-item 1 --backtitle "Kwort Network Manager" --stdout --title "Networking" \ - --menu "Do you want to use ${WIFI_CONF} with:" 0 0 3 `conf_card_opts`) + ${DIALOG} --default-item 1 --backtitle "Kwort Network Manager" --title "Networking" \ + --menu "Do you want to use ${WIFI_CONF} with:" 0 0 3 `conf_card_opts` 2>$TEMP fi + DHCP=$(cat $TEMP) if [ "${DHCP}" = "2" ]; then while true; do if [ "${USE_DIALOG}" = "1" ]; then - OUTPUT=$(${DIALOG} --stdout --title "Networking" --ok-label Accept --extra-label Edit --cancel-label Cancel ${FORM2} \ - "Change the settings ${IFNAME[4]}" `if [ ${USE_DIALOG} -eq 1 ]; then echo 13; fi` 60 6 "IP address:" " " "Netmask:" " " \ - ) + ${DIALOG} --title "Networking" --ok-label Accept --extra-label Edit --cancel-label Cancel ${FORM2} \ + "Change the settings ${IFNAME[4]}" `if [ ${USE_DIALOG} -eq 1 ]; then echo 13; fi` 60 6 "IP address:" " " "Netmask:" " " 2>$TEMP else - OUTPUT=$(${DIALOG} --stdout --title "Networking" --ok-label Accept --cancel-label Cancel ${FORM2} \ - "Change the settings ${IFNAME[4]}" 0 0 "IP address:" " " "Netmask:" " " \ - ) + ${DIALOG} --title "Networking" --ok-label Accept --cancel-label Cancel ${FORM2} \ + "Change the settings ${IFNAME[4]}" 0 0 "IP address:" " " "Netmask:" " " 2>$TEMP fi RETVAL=$? + OUTPUT=$(cat $TEMP) if [ "${RETVAL}" = "0" ]; then if [ "${USE_DIALOG}" = "0" ]; then IFS='/' @@ -465,45 +497,52 @@ # elif [ "${TODO}" = "3" ]; then if [ "${USE_DIALOG}" = "1" ]; then - GATEWAY=$(${DIALOG} --stdout --title "Networking" --backtitle "Kwort Network Manager" --inputbox "Set your internet gateway" 8 30 ${GATEWAY}) + ${DIALOG} --title "Networking" --backtitle "Kwort Network Manager" --inputbox "Set your internet gateway" 8 30 ${GATEWAY} 2>$TEMP else - GATEWAY=$(${DIALOG} --stdout --title "Networking" --backtitle "Kwort Network Manager" --inputbox "Set your internet gateway" 0 0 ${GATEWAY}) + ${DIALOG} --title "Networking" --backtitle "Kwort Network Manager" --inputbox "Set your internet gateway" 0 0 ${GATEWAY} 2>$TEMP fi + GATEWAY=$(cat $TEMP) elif [ "${TODO}" = "4" ]; then while true; do if [ "${TOTAL_DNS}" = "-1" ]; then if [ "${USE_DIALOG}" = "1" ]; then - DNS_ARRAY[0]=$(${DIALOG} --stdout --title "Networking" --backtitle "Kwort Network Manager" --inputbox \ - "Insert you new DNS server" 8 60 ) - RETVAL_NEW=$? + ${DIALOG} --title "Networking" --backtitle "Kwort Network Manager" --inputbox \ + "Insert you new DNS server" 8 60 2>$TEMP else - DNS_ARRAY[0]=$(${DIALOG} --stdout --title "Networking" --backtitle "Kwort Network Manager" --inputbox \ - "Insert you new DNS server" 0 0 ) - RETVAL_NEW=$? + ${DIALOG} --title "Networking" --backtitle "Kwort Network Manager" --inputbox \ + "Insert you new DNS server" 0 0 2>$TEMP fi + + RETVAL_NEW=$? + DNS_ARRAY[0]=$(cat $TEMP) + if [ ${RETVAL_NEW} -eq 0 ]; then TOTAL_DNS=0 fi fi + if [ "${USE_DIALOG}" = "1" ]; then - DNS_CONF=$(${DIALOG} --backtitle "Kwort Network Manager" --cancel-label "Back" --stdout --title "Networking" --extra-button \ - --extra-label "Add new" --menu "DNS Editor" 10 40 ${TOTAL_DNS} `say_dns`) - RETVAL=$? + + ${DIALOG} --backtitle "Kwort Network Manager" --cancel-label "Back" --title "Networking" --extra-button \ + --extra-label "Add new" --menu "DNS Editor" 10 40 ${TOTAL_DNS} `say_dns` 2>$TEMP else - DNS_CONF=$(${DIALOG} --backtitle "Kwort Network Manager" --cancel-label "Back" --stdout --title "Networking" --extra-button \ - --extra-label "Add new" --menu "DNS Editor" 0 0 $((${TOTAL_DNS} + 1)) `say_dns`) - RETVAL=$? + ${DIALOG} --backtitle "Kwort Network Manager" --cancel-label "Back" --title "Networking" --extra-button \ + --extra-label "Add new" --menu "DNS Editor" 0 0 $((${TOTAL_DNS} + 1)) `say_dns` 2>$TEMP fi + + RETVAL=$? + DNS_CONF=$(cat $TEMP) + if [ "${RETVAL}" = "3" ]; then if [ "${USE_DIALOG}" = "1" ]; then - GET_NEW_DNS=$(${DIALOG} --stdout --title "Networking" --backtitle "Kwort Network Manager" --inputbox \ - "Insert you new DNS server" 8 60 ) - RETVAL_NEW=$? + ${DIALOG} --title "Networking" --backtitle "Kwort Network Manager" --inputbox \ + "Insert you new DNS server" 8 60 2>$TEMP else - GET_NEW_DNS=$(${DIALOG} --stdout --title "Networking" --backtitle "Kwort Network Manager" --inputbox \ - "Insert you new DNS server" 0 0 ) - RETVAL_NEW=$? + ${DIALOG} --title "Networking" --backtitle "Kwort Network Manager" --inputbox \ + "Insert you new DNS server" 0 0 2>$TEMP fi + RETVAL_NEW=$? + GET_NEW_DNS=$(cat $TEMP) if [ ${RETVAL_NEW} -eq 0 -a "${GET_NEW_DNS}" != "" ]; then TOTAL_DNS=$((${TOTAL_DNS} + 1)) DNS_ARRAY[${TOTAL_DNS}]="${GET_NEW_DNS}" @@ -514,14 +553,14 @@ fi if [ ${RETVAL} -eq 0 ]; then if [ "${USE_DIALOG}" = "1" ]; then - GET_NEW_DNS=$(${DIALOG} --stdout --title "Networking" --backtitle "Kwort Network Manager" --inputbox \ - "DNS Editor" 8 60 ${DNS_ARRAY[${DNS_CONF}]} ) - RETVAL=$? + ${DIALOG} --title "Networking" --backtitle "Kwort Network Manager" --inputbox \ + "DNS Editor" 8 60 ${DNS_ARRAY[${DNS_CONF}]} 2>$TEMP else - GET_NEW_DNS=$(${DIALOG} --stdout --title "Networking" --backtitle "Kwort Network Manager" --inputbox \ - "DNS Editor" 0 0 ${DNS_ARRAY[${DNS_CONF}]} ) - RETVAL=$? + ${DIALOG} --title "Networking" --backtitle "Kwort Network Manager" --inputbox \ + "DNS Editor" 0 0 ${DNS_ARRAY[${DNS_CONF}]} 2>$TEMP fi + RETVAL=$? + GET_NEW_DNS=$(cat $TEMP) if [ ${RETVAL} -eq 0 -a "${DNS_ARRAY[${DNS_CONF}]}" != "" ]; then DNS_ARRAY[${DNS_CONF}]="${GET_NEW_DNS}" fi @@ -531,10 +570,11 @@ elif [ "${TODO}" = "5" ]; then ACTUAL_HOST=`cat /etc/HOSTNAME` if [ "${USE_DIALOG}" = "1" ]; then - HOSTNAM=$(${DIALOG} --stdout --title "Networking" --backtitle "Kwort Network Manager" --inputbox "Set your machine's name" 8 40 ${ACTUAL_HOST}) + ${DIALOG} --title "Networking" --backtitle "Kwort Network Manager" --inputbox "Set your machine's name" 8 40 ${ACTUAL_HOST} 2>$TEMP else - HOSTNAM=$(${DIALOG} --stdout --title "Networking" --backtitle "Kwort Network Manager" --inputbox "Set your machine's name" 0 0 ${ACTUAL_HOST}) + ${DIALOG} --title "Networking" --backtitle "Kwort Network Manager" --inputbox "Set your machine's name" 0 0 ${ACTUAL_HOST} 2>$TEMP fi + HOSTNAM=$(cat $TEMP) elif [ "${TODO}" = "6" ]; then if [ ! -e /proc/net/wireless ]; then if [ "${USE_DIALOG}" = "1" ]; then @@ -542,7 +582,7 @@ else ${DIALOG} --backtitle "Kwort Network Manager" --title "Networking" --msgbox "It seems like you don't have a wireless card" 0 0 fi - break + continue fi miniloop=1 while [ "${miniloop}" = "1" ]; do @@ -561,13 +601,14 @@ DATA=() say_essids ${WI_IF} if [ "${USE_DIALOG}" = "1" ]; then - WIFI_CONF=$(${DIALOG} --backtitle "Kwort Network Manager" --cancel-label "Back" --stdout --title "Networking" --ok-label "CONNECT" \ - --extra-button --extra-label "Rescan Networks" --menu "Choose which wireless network do you want to associate" 10 58 ${HOWMUCHESSIDS} "${DATA[@]}") + ${DIALOG} --backtitle "Kwort Network Manager" --cancel-label "Back" --title "Networking" --ok-label "CONNECT" \ + --extra-button --extra-label "Rescan Networks" --menu "Choose which wireless network do you want to associate" 10 58 ${HOWMUCHESSIDS} "${DATA[@]}" 2>$TEMP else - WIFI_CONF=$(${DIALOG} --backtitle "Kwort Network Manager" --cancel-label "Back" --stdout --title "Networking" --ok-label "CONNECT" \ - "Rescan Networks" --menu "Choose which wireless network do you want to associate" 0 0 $((${HOWMUCHESSIDS} + 1)) "${DATA[@]}") + ${DIALOG} --backtitle "Kwort Network Manager" --cancel-label "Back" --title "Networking" --ok-label "CONNECT" \ + "Rescan Networks" --menu "Choose which wireless network do you want to associate" 0 0 $((${HOWMUCHESSIDS} + 1)) "${DATA[@]}" 2>$TEMP fi RETVAL=$? + WIFI_CONF=$(cat $TEMP) if [ -z "${WIFI_CONF}" ]; then break fi @@ -575,10 +616,11 @@ continue fi if [ "${USE_DIALOG}" = "1" ]; then - SSKEY=$(${DIALOG} --backtitle "Kwort Network Manager" --stdout --title "Networking" --inputbox "Insert SKEY" 8 40) + ${DIALOG} --backtitle "Kwort Network Manager" --title "Networking" --inputbox "Insert SKEY" 8 40 2>$TEMP else - SSKEY=$(${DIALOG} --backtitle "Kwort Network Manager" --stdout --title "Networking" --inputbox "Insert SKEY" 0 0) + ${DIALOG} --backtitle "Kwort Network Manager" --title "Networking" --inputbox "Insert SKEY" 0 0 2>$TEMP fi + SSKEY=$(cat $TEMP) SUBINDIC=$((${WIFI_CONF/\)*/} - 1)) source ${TMP_VARS} rm -f ${TMP_VARS} @@ -594,23 +636,25 @@ exit else if [ "${USE_DIALOG}" = "1" ]; then - DHCP=$(${DIALOG} --backtitle "Kwort Network Manager" --stdout --title "Networking" \ - --menu "Do you want to use ${WIFI_CONF} with:" 10 40 2 `conf_card_opts`) + ${DIALOG} --backtitle "Kwort Network Manager" --title "Networking" \ + --menu "Do you want to use ${WIFI_CONF} with:" 10 40 2 `conf_card_opts` 2>$TEMP else - DHCP=$(${DIALOG} --backtitle "Kwort Network Manager" --stdout --title "Networking" \ - --menu "Do you want to use ${WIFI_CONF} with:" 0 0 3 `conf_card_opts`) + ${DIALOG} --backtitle "Kwort Network Manager" --title "Networking" \ + --menu "Do you want to use ${WIFI_CONF} with:" 0 0 3 `conf_card_opts` 2>$TEMP fi + DHCP=$(cat $TEMP) if [ "${DHCP}" = "2" ]; then miniloop=1 while [ "${miniloop}" = "1" ]; do if [ "${USE_DIALOG}" = "1" ]; then - OUTPUT=$(${DIALOG} --stdout --title "Networking" --ok-label Accept --extra-label Edit --cancel-label Cancel ${FORM2} \ - "Change the settings ${WI_IF}" `if [ ${USE_DIALOG} -eq 1 ]; then echo 13; fi` 60 6 "IP address:" " " "Gateway:" " ") + ${DIALOG} --title "Networking" --ok-label Accept --extra-label Edit --cancel-label Cancel ${FORM2} \ + "Change the settings ${WI_IF}" `if [ ${USE_DIALOG} -eq 1 ]; then echo 13; fi` 60 6 "IP address:" " " "Gateway:" " " 2>$TEMP else - OUTPUT=$(${DIALOG} --stdout --title "Networking" --cancel-label Cancel ${FORM2} \ - "Change the settings ${WI_IF}" 0 0 "IP address:" " " "Gateway:" " ") + ${DIALOG} --title "Networking" --cancel-label Cancel ${FORM2} \ + "Change the settings ${WI_IF}" 0 0 "IP address:" " " "Gateway:" " " 2>$TEMP fi RETVAL=$? + OUTPUT=$(cat $TEMP) if [ "${RETVAL}" = "0" ]; then if [ "${USE_DIALOG}" = "0" ]; then IFS='/'