summaryrefslogtreecommitdiffstats
path: root/setup-interfaces.in
diff options
context:
space:
mode:
authorJeff Bilyk <jbilyk@gmail.com>2011-08-07 11:07:36 -0400
committerJeff Bilyk <jbilyk@gmail.com>2011-08-07 11:07:36 -0400
commite489e81f7a9b37db7651941c8310d54016eeff22 (patch)
tree3cdd2d7a76204d5641dd600946a813cffe9708cc /setup-interfaces.in
parentcd085f2ea8c91326127ceadd9a3f2d4cc49482ae (diff)
downloadalpine-conf-e489e81f7a9b37db7651941c8310d54016eeff22.tar.bz2
alpine-conf-e489e81f7a9b37db7651941c8310d54016eeff22.tar.xz
setup-interfaces: add an option to read custom /etc/network/interfaces from stdin
Diffstat (limited to 'setup-interfaces.in')
-rwxr-xr-xsetup-interfaces.in143
1 files changed, 84 insertions, 59 deletions
diff --git a/setup-interfaces.in b/setup-interfaces.in
index e402742..2cde104 100755
--- a/setup-interfaces.in
+++ b/setup-interfaces.in
@@ -99,69 +99,94 @@ config_iface() {
rm $iface.noconf
}
-init_tmpdir TMP
+usage() {
+ cat <<__EOF__
+usage: setup-interfaces [-h] [-i read custom /etc/network/interfaces from stdin]
-cd $TMP
-for i in $(detect_interfaces); do
- touch $i.noconf
-done
-
-index=1
-while ls *.noconf > /dev/null 2>&1 ; do
- echon "Available interfaces are:"
- for i in *.noconf; do
- echon " `basename $i .noconf`"
- done
- echo "."
+Setup network interfaces
- firstif=`get_first_unconfigured`
- echon "Which one do you want to initialize? (or 'done') [$firstif] "
- default_read iface "$firstif"
-
- [ "$iface" = "done" ] && break
- [ -f $iface.noconf ] || continue
- config_iface $iface $(printf "%.3d~" $index)
- index=$(( $index + 1 ))
-done
+options:
+ -h Show this help
+ -i Read new contents of /etc/network/interfaces from stdin
+__EOF__
+ exit 1
+}
-echo "type=loopback" > 000~lo.conf
-echo "" > interface
-hostname=$(cat /etc/hostname 2>/dev/null)
-
-for i in *.conf ; do
- iface=`basename $i .conf`
- iface=${iface#[0-9]*~}
- . ./$i
- echo "auto $iface" >> interfaces
- echo "iface $iface inet $type" >> interfaces
- case $type in
- dhcp)
- [ -n "$hostname" ] \
- && echo -e "\thostname $hostname" >> interfaces
- ;;
- static)
- echo -e "\taddress $address" >> interfaces
- echo -e "\tnetmask $netmask" >> interfaces
- [ "$gateway" ] \
- && echo -e "\tgateway $gateway" >> interfaces
- ;;
- esac
- echo "" >> interfaces
+while getopts "hi" opt; do
+ case $opt in
+ h) usage;;
+ i) STDINPUT=1;;
+ esac
done
-while [ "$answer" != "yes" ] && [ "$answer" != "no" ] ; do
- echon "Do you want to do any manual network configuration? [no] "
- default_read answer no
-done
+if [ "$STDINPUT" != "1" ]; then
+ init_tmpdir TMP
+
+ cd $TMP
+ for i in $(detect_interfaces); do
+ touch $i.noconf
+ done
+
+ index=1
+ while ls *.noconf > /dev/null 2>&1 ; do
+ echon "Available interfaces are:"
+ for i in *.noconf; do
+ echon " `basename $i .noconf`"
+ done
+ echo "."
+
+ firstif=`get_first_unconfigured`
+ echon "Which one do you want to initialize? (or 'done') [$firstif] "
+ default_read iface "$firstif"
+
+ [ "$iface" = "done" ] && break
+ [ -f $iface.noconf ] || continue
+ config_iface $iface $(printf "%.3d~" $index)
+ index=$(( $index + 1 ))
+ done
+
+ echo "type=loopback" > 000~lo.conf
+ echo "" > interface
+ hostname=$(cat /etc/hostname 2>/dev/null)
+
+ for i in *.conf ; do
+ iface=`basename $i .conf`
+ iface=${iface#[0-9]*~}
+ . ./$i
+ echo "auto $iface" >> interfaces
+ echo "iface $iface inet $type" >> interfaces
+ case $type in
+ dhcp)
+ [ -n "$hostname" ] \
+ && echo -e "\thostname $hostname" >> interfaces
+ ;;
+ static)
+ echo -e "\taddress $address" >> interfaces
+ echo -e "\tnetmask $netmask" >> interfaces
+ [ "$gateway" ] \
+ && echo -e "\tgateway $gateway" >> interfaces
+ ;;
+ esac
+ echo "" >> interfaces
+ done
+
+ while [ "$answer" != "yes" ] && [ "$answer" != "no" ] ; do
+ echon "Do you want to do any manual network configuration? [no] "
+ default_read answer no
+ done
-if [ "$answer" = "yes" ]; then
- case "$EDITOR" in
- nano) pkg_inst nano;;
- vim) pkg_inst vim;;
- esac
- ${EDITOR:-vi} interfaces
+ if [ "$answer" = "yes" ]; then
+ case "$EDITOR" in
+ nano) pkg_inst nano;;
+ vim) pkg_inst vim;;
+ esac
+ ${EDITOR:-vi} interfaces
+ fi
+
+ mkdir -p $ROOT/etc/network
+ cp interfaces $ROOT/etc/network/
+else
+ cat /dev/stdin > interfaces
+ mkdir -p $ROOT/etc/network
+ cp interfaces $ROOT/etc/network
fi
-
-mkdir -p $ROOT/etc/network
-cp interfaces $ROOT/etc/network/
-