216 lines
6.0 KiB
Bash
216 lines
6.0 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
|
|
|
|
[ -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
|
|
local CDC_SUBNET=10.99.99.0
|
|
local CDC_RANGE_FROM=10.99.99.100
|
|
local CDC_RANGE_TO=10.99.99.199
|
|
local CDC_NETMASK=255.255.255.0
|
|
|
|
ifconfig usb0 &>/dev/null && {
|
|
[ "$NETWORK_CDC_NETMASK" ] && CDC_NETMASK=$NETWORK_CDC_NETMASK
|
|
[ -e $network_devices/ifcfg-usb0 ] || {
|
|
[ "$NETWORK_CDC_IPADDR" ] && CDC_IPADDR=$NETWORK_CDC_IPADDR
|
|
cat > $network_devices/ifcfg-usb0 << _EOF
|
|
DEVICE=usb0
|
|
BOOTPROTO=none
|
|
IPADDR=$CDC_IPADDR
|
|
NETMASK=$CDC_NETMASK
|
|
ONBOOT=yes
|
|
NM_CONTROLLED=no
|
|
_EOF
|
|
}
|
|
[ -e /etc/dhcpd-usb0.conf ] || {
|
|
[ "$NETWORK_CDC_SUBNET" ] && CDC_SUBNET=$NETWORK_CDC_SUBNET
|
|
[ "$NETWORK_CDC_RANGE_FROM" ] && CDC_RANGE_FROM=$NETWORK_CDC_RANGE_FROM
|
|
[ "$NETWORK_CDC_RANGE_TO" ] && CDC_RANGE_TO=$NETWORK_CDC_RANGE_TO
|
|
cat > /etc/dhcpd-usb0.conf << _EOF
|
|
# Created by postplug
|
|
subnet $NETWORK_CDC_SUBNET netmask $NETWORK_CDC_NETMASK {
|
|
range dynamic-bootp $NETWORK_CDC_RANGE_FROM $NETWORK_CDC_RANGE_TO;
|
|
}
|
|
_EOF
|
|
}
|
|
ifup usb0
|
|
touch /var/lib/dhcp/dhcpd-usb0.leases
|
|
/sbin/dhcpd -q usb0 -pf /run/dhcpd-usb0.pid -cf /etc/dhcpd-usb0.conf -lf /var/lib/dhcp/dhcpd-usb0.leases
|
|
}
|
|
}
|
|
|
|
function android_usb() {
|
|
local ANDROID_IPADDR=10.99.99.1
|
|
local ANDROID_ETHADDR=80:00:60:0F:E8:00
|
|
local ANDROID_SUBNET=10.99.99.0
|
|
local ANDROID_RANGE_FROM=10.99.99.100
|
|
local ANDROID_RANGE_TO=10.99.99.199
|
|
local ANDROID_NETMASK=255.255.255.0
|
|
|
|
# FIXME: hardcoded values
|
|
if [ -e /sys/class/android_usb/android0 ]; then
|
|
[ "$NETWORK_ANDROID_ETHADDR" ] && ANDROID_ETHADDR=$NETWORK_ANDROID_ETHADDR
|
|
[ "$NETWORK_ANDORID_NETMASK" ] && ANDORID_NETMASK=$NETWORK_ANDORID_NETMASK
|
|
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
|
|
|
|
[ -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
|
|
NETMASK=$ANDROID_NETMASK
|
|
ONBOOT=yes
|
|
NM_CONTROLLED=no
|
|
_EOF
|
|
}
|
|
|
|
[ -e /etc/dhcpd-rndis0.conf ] || {
|
|
[ "$NETWORK_ANDROID_SUBNET" ] && ANDROID_SUBNET=$NETWORK_ANDROID_SUBNET
|
|
[ "$NETWORK_ANDROID_RANGE_FROM" ] && ANDORID_RANGE_FROM=$NETWORK_ANDROID_RANGE_FROM
|
|
[ "$NETWORK_ANDROID_RANGE_TO" ] && ANDROID_RANGE_TO=$NETWORK_ANDROID_RANGE_TO
|
|
cat > /etc/dhcpd-rndis0.conf << _EOF
|
|
# Created by postplug
|
|
subnet $ANDROID_SUBNET netmask $ANDROID_NETMASK {
|
|
range dynamic-bootp $ANDROID_RANGE_FROM $ANDROID_RANGE_TO;
|
|
}
|
|
_EOF
|
|
}
|
|
|
|
for d in ttyGS0 ttyGS1; do
|
|
[ -e /etc/systemd/system/getty.target.wants/getty@$d.service ] ||
|
|
ln -s /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@$d.service
|
|
done
|
|
fi
|
|
}
|
|
|
|
[ "$NETWORK_CDC_DISABLE" = "1" ] || cdc_usb
|
|
[ "$NETWORK_ANDROID_DISABLE" = "1" ] || android_usb
|
|
|
|
# Disable p2p interface managed by NetworkManager
|
|
for net_int in $(cat /proc/net/dev | sed -n '/p2p[0-9]*:/{s,:.*,,;p}'); do
|
|
# found interface already configured
|
|
[ -e $network_devices/ifcfg-${net_int} ] && continue
|
|
|
|
if [ "${net_int:0:3}" = "p2p" ]; then
|
|
P2P_HWADDR=`ifconfig $net_int | grep HWaddr | sed "s|.* HWaddr ||"`
|
|
cat > $network_devices/ifcfg-${net_int} << _EOF
|
|
DEVICE=$net_int
|
|
HWADDR=${P2P_HWADDR:0:17}
|
|
ONBOOT=no
|
|
NM_CONTROLLED=no
|
|
_EOF
|
|
fi
|
|
done
|
|
|
|
# INFO: the following code is going obsolete
|
|
if [ "$NETWORK_NEWDEVICE" -a "$NETWORK_NEWDEVICE" != "off" ]; then
|
|
|
|
wlan_ints=()
|
|
for wlan_int in $(cat /proc/net/wireless 2>/dev/null | sed -n '/[a-z]*[0-9]*:/{s,:.*,,;p}'); do
|
|
# found interface already configured
|
|
[ -e $network_devices/ifcfg-$wlan_int ] && continue
|
|
wlan_ints[${#wlan_ints[*]}]="$wlan_int"
|
|
done
|
|
|
|
eth_ints=()
|
|
for eth_int in $(cat /proc/net/dev | sed -n '/eth[0-9]*:/{s,:.*,,;p}'); do
|
|
# found interface already configured
|
|
[ -e $network_devices/ifcfg-$eth_int ] && continue
|
|
eth_ints[${#eth_ints[*]}]="$eth_int"
|
|
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
|
|
fi
|
|
|
|
exit 0
|