Commit 76455c99 authored by Natanael Copa's avatar Natanael Copa

setup-interfaces: add -a option for auto setup

this option will configure dhcp on first interface found which is "up"
parent 36f07b2c
...@@ -549,11 +549,33 @@ prompt_for_interfaces() { ...@@ -549,11 +549,33 @@ prompt_for_interfaces() {
cp interfaces $ROOT/etc/network/ cp interfaces $ROOT/etc/network/
} }
auto_setup() {
local iface
local hostname=$(cat $ROOT/etc/hostname 2>/dev/null)
for iface in $(available_ifaces); do
if [ "$(cat /sys/class/net/$iface/operstate)" = "up" ]; then
break
fi
done
[ -z "$iface" ] && return 0
cat >$ROOT/etc/network/interfaces <<-EOF
auto lo
iface lo inet loopback
auto $iface
iface $iface inet dhcp
EOF
if [ -n "$hostname" ]; then
echo -e "\thostname $hostname" >> $ROOT/etc/network/interfaces
fi
}
ask_bridge= ask_bridge=
is_xen_dom0 && ask_bridge=1 is_xen_dom0 && ask_bridge=1
while getopts "bhip:" opt; do while getopts "abhip:" opt; do
case $opt in case $opt in
a) auto=1;;
b) ask_bridge=1;; b) ask_bridge=1;;
h) usage;; h) usage;;
i) STDINPUT=1;; i) STDINPUT=1;;
...@@ -564,6 +586,8 @@ done ...@@ -564,6 +586,8 @@ done
mkdir -p $ROOT/etc/network mkdir -p $ROOT/etc/network
if [ "$STDINPUT" = "1" ]; then if [ "$STDINPUT" = "1" ]; then
cat > $ROOT/etc/network/interfaces cat > $ROOT/etc/network/interfaces
elif [ -n "$auto" ]; then
auto_setup
else else
prompt_for_interfaces prompt_for_interfaces
fi fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment