#!/bin/bash # # network - network plugin for postplug # # Copyright (c) 2004-2007 by Davide Madrisan # Copyright (c) 2009-2013 by Silvan Calarco # 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 } function cdc_usb() { local CDC_IPADDR=10.99.99.1 ifconfig usb0 &>/dev/null && { [ -e $network_devices/ifcng-usb0 ] || { [ "$NETWORK_CDC_IPADDR" ] && CDC_IPADDR=$NETWORK_CDC_IPADDR cat > $network_devices/ifcfg-usb0 << _EOF DEVICE=usb0 BOOTPROTO=none IPADDR=$CDC_IPADDR ONBOOT=yes NM_CONTROLLED=no _EOF } } } function android_usb() { local ANDROID_IPADDR=10.99.99.1 local ANDROID_ETHADDR=80:00:60:0F:E8:00 # FIXME: hardcoded values if [ -e /sys/class/android_usb/android0 ]; then [ "$NETWORK_ANDROID_ETHADDR" ] && ANDROID_ETHADDR=$NETWORK_ANDROID_ETHADDR echo 0 > /sys/class/android_usb/android0/enable echo rndis,acm > /sys/class/android_usb/android0/functions echo 2 > /sys/class/android_usb/android0/f_acm/instances echo $ANDROID_ETHADDR > /sys/class/android_usb/android0/f_rndis/ethaddr echo 2d01 > /sys/class/android_usb/android0/idProduct echo 1 > /sys/class/android_usb/android0/enable fi [ -e $network_devices/ifcfg-rndis0 ] || { [ "$NETWORK_ANDROID_IPADDR" ] && ANDROID_IPADDR=$NETWORK_ANDROID_IPADDR cat > $network_devices/ifcfg-rndis0 << _EOF DEVICE=rndis0 BOOTPROTO=none IPADDR=$ANDROID_IPADDR ONBOOT=yes NM_CONTROLLED=no _EOF } } [ "$NETWORK_CDC_DISABLE" = "1" ] || cdc_usb [ "$NETWORK_ANDROID_DISABLE" = "1" ] || android_usb 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