allow multiple nics to be configured via cmdline
This commit is contained in:
parent
f9781c659b
commit
e4804115e2
@ -39,27 +39,46 @@ create_certs() {
|
|||||||
-days 365 -subj "$subject" 2>/dev/null
|
-days 365 -subj "$subject" 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
# expects kernel param in this format: detee_net=192.168.122.140_24_192.168.122.1_1.1.1.1
|
setup_network_device() {
|
||||||
setup_network() {
|
local device="$1" settings="$2" ip_addr='' mask='' cidr='' gateway=''
|
||||||
local settings='' ip_addr='' mask='' cidr='' gateway='' nameserver=''
|
|
||||||
settings=$(cat /proc/cmdline | grep -oE 'detee_net=[0-9a-z\_\:\.]+' | cut -d '=' -f2)
|
|
||||||
# TODO: replace with exit 0 when you are ready to force a kernel panic
|
|
||||||
[[ -z "$settings" ]] && return 0
|
[[ -z "$settings" ]] && return 0
|
||||||
settings="${settings#detee_net=}"
|
ip_addr="$( echo ${settings} | cut -d '_' -f1 )"
|
||||||
ip_addr="$( echo ${settings} | cut -d'_' -f1 )"
|
mask="$( echo ${settings} | cut -d '_' -f2 )"
|
||||||
mask="$( echo ${settings} | cut -d'_' -f2 )"
|
|
||||||
cidr="${ip_addr}/${mask}"
|
cidr="${ip_addr}/${mask}"
|
||||||
gateway="$( echo ${settings} | cut -d'_' -f3 )"
|
gateway="$( echo ${settings} | cut -d '_' -f3 )"
|
||||||
nameserver="$( echo ${settings} | cut -d'_' -f4 )"
|
|
||||||
|
|
||||||
ip addr add $cidr dev eth0
|
ip addr add $cidr dev $device
|
||||||
ip link set eth0 up
|
ip link set $device up
|
||||||
ip route add default via $gateway
|
ip route add default via $gateway
|
||||||
echo nameserver $nameserver > /etc/resolv.conf
|
|
||||||
sleep 2
|
sleep 2
|
||||||
ping -c 2 $gateway
|
ping -c 2 $gateway
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Expects kernel param in this format: detee_net=192.168.122.140_24_192.168.122.1_1.1.1.1
|
||||||
|
# In case the interface name is not specified, it defaults to eth0
|
||||||
|
# Supports manual device, for example: detee_net_eth1
|
||||||
|
# TODO: test if it is required to specify mac instead of device name
|
||||||
|
setup_network() {
|
||||||
|
local device_eth0_cfg='' device_cfg='' device_configs=''
|
||||||
|
|
||||||
|
# handle the default: detee_net=...
|
||||||
|
device_eth0_cfg=$(cat /proc/cmdline | grep -oE "detee_net=[0-9a-f\_\:\.]+" | cut -d '=' -f2)
|
||||||
|
[[ -z "$device_eth0_cfg" ]] || setup_network_device eth0 $device_eth0_cfg
|
||||||
|
|
||||||
|
# handle extra devices: detee_net_eth1=...
|
||||||
|
device_configs=$(cat /proc/cmdline| grep -oE "detee_net_[a-z0-9]*=[0-9a-f\_\:\.]+")
|
||||||
|
while read -r device_cfg; do
|
||||||
|
setup_network_device \
|
||||||
|
$(echo $device_cfg | cut -d '=' -f1 | cut -d '_' -f3) \
|
||||||
|
$(echo $device_cfg | cut -d '=' -f2)
|
||||||
|
done <<< "$( echo "$device_configs" )"
|
||||||
|
|
||||||
|
echo nameserver 1.1.1.1 >> /etc/resolv.conf
|
||||||
|
echo nameserver 1.0.0.1 >> /etc/resolv.conf
|
||||||
|
echo nameserver 2606:4700:4700::1111 >> /etc/resolv.conf
|
||||||
|
echo nameserver 2606:4700:4700::1001 >> /etc/resolv.conf
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# detee_ghu stands for GitHub user and expects format detee_ghu=ghe0
|
# detee_ghu stands for GitHub user and expects format detee_ghu=ghe0
|
||||||
github_ssh_key() {
|
github_ssh_key() {
|
||||||
|
Loading…
Reference in New Issue
Block a user