aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2018-06-13 15:30:49 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2018-06-13 15:32:35 +0200
commit76455c991a436b1cd248f1ac62a78f7a47e085bf (patch)
tree28440c77322896d0983598425c24e98b57e61a00
parent36f07b2cc8d50f3cf91bf6fc65651581f9cee4c5 (diff)
downloadalpine-conf-76455c991a436b1cd248f1ac62a78f7a47e085bf.tar.bz2
alpine-conf-76455c991a436b1cd248f1ac62a78f7a47e085bf.tar.xz
setup-interfaces: add -a option for auto setup
this option will configure dhcp on first interface found which is "up"
-rw-r--r--setup-interfaces.in26
1 files changed, 25 insertions, 1 deletions
diff --git a/setup-interfaces.in b/setup-interfaces.in
index b82f02f..d9265a8 100644
--- a/setup-interfaces.in
+++ b/setup-interfaces.in
@@ -549,11 +549,33 @@ prompt_for_interfaces() {
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=
is_xen_dom0 && ask_bridge=1
-while getopts "bhip:" opt; do
+while getopts "abhip:" opt; do
case $opt in
+ a) auto=1;;
b) ask_bridge=1;;
h) usage;;
i) STDINPUT=1;;
@@ -564,6 +586,8 @@ done
mkdir -p $ROOT/etc/network
if [ "$STDINPUT" = "1" ]; then
cat > $ROOT/etc/network/interfaces
+elif [ -n "$auto" ]; then
+ auto_setup
else
prompt_for_interfaces
fi