From e352b98ed255880460f137cd2304602c51e74f38 Mon Sep 17 00:00:00 2001 From: gobo72 Date: Fri, 11 Mar 2011 21:22:47 +0000 Subject: [PATCH] Modification et ameliorations script ifup pour mode wireless (static et dhcp supportes pour chaque reseau SSID) --- stage2/bootscripts/ifup | 145 ++++++++++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 52 deletions(-) diff --git a/stage2/bootscripts/ifup b/stage2/bootscripts/ifup index b363046..e31fd43 100755 --- a/stage2/bootscripts/ifup +++ b/stage2/bootscripts/ifup @@ -23,33 +23,76 @@ check_brctl() fi } -# Make sure interface is available -if ! ip link show ${DEVICE} > /dev/null 2>&1; then - echo "Interface ${1} not found" - exit ${EXIT_CODE_WARNING} -fi - -# Determining if the interface is a bridge: -if [ "x${BRIDGE}" = "xyes" ]; then - check_brctl - cmd_run_log ${BRCTL} addbr ${DEVICE} && - cmd_run_log ${BRCTL} stp ${DEVICE} off || exit 1 -fi - -# Determining if the interface is part of a bridge: -if [ -n "${BRIDGE_TO}" ]; then - check_brctl - cmd_run_log ${BRCTL} addif ${BRIDGE_TO} ${DEVICE} || exit 1 -fi - -if [ "x${BOOTPROTO}" = "xwifi" ]; then - # Bring interface up +# Bring interface up +bring_if_up() +{ link_status=$(ip link show ${DEVICE}) if [ -n "${link_status}" ]; then if ! echo "${link_status}" | grep -q UP; then cmd_run_log ip link set ${DEVICE} up fi fi +} + +# Static IP address protocol +proto_static() +{ + cmd_run_log ip addr add ${IPADDR}/${PREFIX_LENGTH} dev ${DEVICE} brd + ${IFSCOPE} && + bring_if_up + + if [ -n "${GATEWAY}" ]; then + if ip route | grep -q default; then + msg_log "Gateway already setup; skipping." + else + cmd_run_log_box "Adding default route to gateway ${GATEWAY}" \ + ip route add default via ${GATEWAY} dev ${DEVICE} + fi + fi +} + +# Obtain IP address from DHCP +proto_dhcp() +{ + # Load DHCP client parameters + source /etc/sysconfig/network/dhcp-client + + # Make sure no file named `/var/run/dhclient.pid' remains. + if [ -f "/var/run/dhclient.pid" ]; then + rm -f /var/run/dhclient.pid + fi + + if [ ! -x "${DHCP_PROG}" ]; then + echo "Program \"${DHCP_PROG}\" is not executable." + exit ${EXIT_CODE_FAILURE} + fi + + cmd_run_log ${DHCP_PROG} ${DHCP_START} ${DEVICE} +} + +proto_wireless() +{ + # Bring interface up + bring_if_up + + if [ ! -d /etc/sysconfig/network/ssid ]; then + echo "Missing \"/etc/sysconfig/network/ssid\" directory" + exit ${EXIT_CODE_WARNING} + fi + + # Spaces will be converted to underscores in ESSID field + for wnet in $(iwlist ${DEVICE} scan | grep ESSID | + sed -e "s!.*SSID:\"\(.*\)\"!\1!" -e "s!\ !_!g"); do + if [ -f "/etc/sysconfig/network/ssid/${wnet}" ]; then + ESSID=${wnet} + source "/etc/sysconfig/network/ssid/${wnet}" + break + fi + done + + if [ -z "${ESSID}" ]; then + echo "No known wifi networks" + exit ${EXIT_CODE_WARNING} + fi if [ -f /var/run/wpa_supplicant/${DEVICE} ]; then echo "Stopping previous wpa_supplicant" @@ -57,9 +100,9 @@ if [ "x${BOOTPROTO}" = "xwifi" ]; then rm /var/run/wpa_supplicant/${DEVICE} fi - wpa_supplicant -B -c /etc/wpa_supplicant.conf -i wlan0 + wpa_supplicant -B -c /etc/wpa_supplicant.conf -i ${DEVICE} count=0 - while ! wpa_cli -i wlan0 status | grep "wpa_state=COMPLETED"; do + while ! wpa_cli -i ${DEVICE} status | grep "wpa_state=COMPLETED"; do echo "Waiting for wpa_supplicant to complete" sleep 1 @@ -69,44 +112,42 @@ if [ "x${BOOTPROTO}" = "xwifi" ]; then exit ${EXIT_CODE_WARNING} fi done +} - BOOTPROTO=dhcp +# Make sure interface is available +if ! ip link show ${DEVICE} > /dev/null 2>&1; then + echo "Interface ${1} not found" + exit ${EXIT_CODE_WARNING} fi -if [ "x${BOOTPROTO}" = "xdhcp" ]; then - # DHCP configuration - - # Load DHCP client parameters - source /etc/sysconfig/network/dhcp-client - - # Make sure no file named `/var/run/dhclient.pid' remains. - if [ -f "/var/run/dhclient.pid" ]; then - rm -f /var/run/dhclient.pid - fi +# Determining if the interface is a bridge: +if [ "x${BRIDGE}" = "xyes" ]; then + check_brctl + cmd_run_log ${BRCTL} addbr ${DEVICE} && + cmd_run_log ${BRCTL} stp ${DEVICE} off || exit 1 +fi - if [ ! -x "${DHCP_PROG}" ]; then - echo "Program \"${DHCP_PROG}\" is not executable." - exit ${EXIT_CODE_FAILURE} - fi +# Determining if the interface is part of a bridge: +if [ -n "${BRIDGE_TO}" ]; then + check_brctl + cmd_run_log ${BRCTL} addif ${BRIDGE_TO} ${DEVICE} || exit 1 +fi - cmd_run_log ${DHCP_PROG} ${DHCP_START} ${DEVICE} -elif [ x${BOOTPROTO} = "xstatic" ]; then - # Static configuration - cmd_run_log ip addr add ${IPADDR}/${PREFIX_LENGTH} dev ${DEVICE} brd + ${IFSCOPE} && - cmd_run_log ip link set ${DEVICE} up +if [ "x${BOOTPROTO}" = "xwifi" ]; then + proto_wireless + # At this point, the SSID script has been sourced, and its + # BOOTPROTO variable will contain either "static" or "dhcp", + # so configuration will continue below. +fi - if [ -n "${GATEWAY}" ]; then - if ip route | grep -q default; then - msg_log "Gateway already setup; skipping." - else - cmd_run_log_box "Adding default route to gateway ${GATEWAY}" \ - ip route add default via ${GATEWAY} dev ${DEVICE} - fi - fi +if [ "x${BOOTPROTO}" = "xdhcp" ]; then + proto_dhcp +elif [ "x${BOOTPROTO}" = "xstatic" ]; then + proto_static elif [ x${BOOTPROTO} = "xpppoe" ]; then - # PPPoE configuration cmd_run_log pppoe-start else + echo "Invalid or absent BOOTPROTO variable" exit 1 fi -- 2.20.1