postplug/postplug.d/20network

122 lines
2.5 KiB
Bash

#!/bin/bash
#
# network - network plugin for postplug
#
# Copyright (c) 2004-2007 by Davide Madrisan <davide.madrisan@qilinux.it>
# Copyright (c) 2009-2013 by Silvan Calarco <silvan.calarco@mambasoft.it>
#
if [ $UID != 0 ]; then
echo "$0: must be superuser." >&2
exit 1
fi
me="network"
. /etc/postplug/postplug.defs
postplugnew_file=$postplugnewdir/network
rm -f $postplugnew_file
[ -r /etc/sysconfig/postplug ] && . /etc/sysconfig/postplug
[ -r /etc/sysconfig/rc ] && . /etc/sysconfig/rc
[ -r $rc_networkfunctions ] && . $rc_networkfunctions
resolv_conf=/etc/resolv.conf
sysconf_network=/etc/sysconfig/network
function wlan_config_auto() {
local wlan_interface="$1"
cat > $network_devices/ifcfg-${wlan_interface} << _EOF
DEVICE=${wlan_interface}
BOOTPROTO=dhcp
ONBOOT=yes
#NM_CONTROLLED=no
#WIRELESS_ESSID=""
#WIRELESS_MODE=managed
#WIRELESS_ENC=s:ENCRYPTIONKEY
#WIRELESS_NWID=
#WIRELESS_FREQ=
_EOF
}
function eth_config_auto() {
local eth_interface="$1"
cat > $network_devices/ifcfg-${eth_interface} << _EOF
DEVICE=${eth_interface}
BOOTPROTO=dhcp
ONBOOT=yes
#NM_CONTROLLED=no
_EOF
}
# FIXME
DEST_GATEWAY_ZONE=local
wlan_ints=()
for wlan_int in $(cat /proc/net/wireless 2>/dev/null | sed -n '/[a-z]*[0-9]*:/{s,:.*,,;p}'); do
# checks for existing physical interfaces
/sbin/ifconfig $wlan_int >/dev/null 2>&1 || continue
# found interface already configured
[ -e $network_devices/ifcfg-$wlan_int ] && continue
wlan_ints[${#wlan_ints[*]}]="$wlan_int"
echo "$wlan_int" >> $postplugnew_file 2>/dev/null
done
eth_ints=()
for eth_int in $(cat /proc/net/dev | sed -n '/eth[0-9]*:/{s,:.*,,;p}'); do
# checks for existing physical interfaces
/sbin/ifconfig $eth_int >/dev/null 2>&1 || continue
# found interface already configured
[ -e $network_devices/ifcfg-$eth_int ] && continue
eth_ints[${#eth_ints[*]}]="$eth_int"
echo "$eth_int" >> $postplugnew_file 2>/dev/null
done
# how many interface have been configured?
let "int_newconf = 0"
if [ ${#eth_ints[*]} -gt 0 ]; then
case "$NETWORK_NEWDEVICE" in
"auto")
for eth_int in ${eth_ints[*]}; do
eth_config_auto $eth_int
let "int_newconf += 1"
done
exit
;;
"off"|"")
exit
;;
*) logmsg "$me" "error: "$"\
illegal value for NETWORK_NEWDEVICE ($NETWORK_NEWDEVICE)"
exit 1
;;
esac
fi
if [ ${#wlan_ints[*]} -gt 0 ]; then
case "$NETWORK_NEWDEVICE" in
"auto")
for wlan_int in ${wlan_ints[*]}; do
wlan_config_auto $wlan_int
let "int_newconf += 1"
done
exit
;;
esac
fi
exit 0