Commit e489e81f authored by Jeff Bilyk's avatar Jeff Bilyk
Browse files

setup-interfaces: add an option to read custom /etc/network/interfaces from stdin

parent cd085f2e
...@@ -99,69 +99,94 @@ config_iface() { ...@@ -99,69 +99,94 @@ config_iface() {
rm $iface.noconf rm $iface.noconf
} }
init_tmpdir TMP usage() {
cat <<__EOF__
usage: setup-interfaces [-h] [-i read custom /etc/network/interfaces from stdin]
cd $TMP Setup network interfaces
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` options:
echon "Which one do you want to initialize? (or 'done') [$firstif] " -h Show this help
default_read iface "$firstif" -i Read new contents of /etc/network/interfaces from stdin
__EOF__
[ "$iface" = "done" ] && break exit 1
[ -f $iface.noconf ] || continue }
config_iface $iface $(printf "%.3d~" $index)
index=$(( $index + 1 ))
done
echo "type=loopback" > 000~lo.conf while getopts "hi" opt; do
echo "" > interface case $opt in
hostname=$(cat /etc/hostname 2>/dev/null) h) usage;;
i) STDINPUT=1;;
for i in *.conf ; do esac
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 done
while [ "$answer" != "yes" ] && [ "$answer" != "no" ] ; do if [ "$STDINPUT" != "1" ]; then
echon "Do you want to do any manual network configuration? [no] " init_tmpdir TMP
default_read answer no
done 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 if [ "$answer" = "yes" ]; then
case "$EDITOR" in case "$EDITOR" in
nano) pkg_inst nano;; nano) pkg_inst nano;;
vim) pkg_inst vim;; vim) pkg_inst vim;;
esac esac
${EDITOR:-vi} interfaces ${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 fi
mkdir -p $ROOT/etc/network
cp interfaces $ROOT/etc/network/
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