Well, I think your program goes in the right direction. However I feel it should be more user-friendly regarding two things: a) presenting the user a nice interface (not just read in console) b) going through user input and checking errors.
I don't have time to help you with a) but I can surely help with a). My proposal (and attached diff) is you use 'dialog' as an interface when available. That way all config apps have the same "feel", and also, when in X the more nice gdialog is used (if available). Feel free to use my patch as you will. I have also changed the code enough so I could make these changes. Regards Javi
--- net Sun May 16 20:47:45 1999 +++ net.dialog Tue May 18 03:40:11 1999 @@ -20,6 +20,21 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. +# This sets up the DIALOG variable in order to show information +# and receive input in a more user-friendly way, or at least show-off. +# Only used when configuring the devices. +# Jfs - mar may 18 03:39:51 CEST 1999 +GDIALOG="/usr/bin/gdialog" +DIALOG="/usr/bin/dialog" +if [ -x $GDIALOG ]; then + DIALOG=$GDIALOG +fi +if [ ! -x $DIALOG ]; then + DIALOG="" +fi + + + function usage() { local p=${0##*/} echo "Usage: $p [start|stop|restart|status [interfaces...]]" @@ -187,17 +202,28 @@ } function ask_var() { +# More error checking should be done in order to get useful +# values (maybe when this script becomes a C program?) local prompt="$1" && shift local varname="$1" && shift local default="${!varname}" local default="${default:-$3}" - echo -ne "$prompt [$default]: "; read val - case "$val" in + if [ -z $DIALOG ]; then + echo -ne "$prompt [$default]: "; read val + else + # If DIALOG is available it will show it in a more + # user-friendly way + local tmp=`tempfile` + $DIALOG --inputbox "$prompt" 10 30 2>$tmp + val=`cat $tmp` + rm $tmp + fi + case "$val" in -|NONE) val="" ;; "") val="$default" ;; - esac - eval "$varname"="$val" + esac + eval "$varname"="$val" } function config_interface() { @@ -272,29 +298,33 @@ CONFIG="${CONFIG:-$INTERFACE}" CONFIG="/etc/network/${CONFIG##*/}" + STRING="" + STRING="\nINTERFACE=$INTERFACE\n" + STRING="${STRING}IPADDR=$IPADDR\n" + if [ "$NETWORK" ]; then + STRING="${STRING}NETWORK=$NETWORK\n" + STRING="${STRING}NETMASK=$NETMASK\n" + STRING="${STRING}BROADCAST=$BROADCAST\n" + elif [ "$POINTOPOINT" ]; then + STRING="${STRING}POINTOPOINT=$POINTOPOINT\n" + fi + if [ "$GATEWAY" ]; then + STRING="${STRING}GATEWAY=$GATEWAY\n" + fi + if [ "$ARGS" ]; then + STRING="${STRING}ARGS=\"$ARGS\"\n" + fi + if [ "$NOAUTO" ]; then + STRING="${STRING}NOAUTO=true\n" + fi + if [ -z $DIALOG ]; then { - echo - echo "INTERFACE=$INTERFACE" - echo "IPADDR=$IPADDR" - if [ "$NETWORK" ]; then - echo "NETWORK=$NETWORK" - echo "NETMASK=$NETMASK" - echo "BROADCAST=$BROADCAST" - elif [ "$POINTOPOINT" ]; then - echo "POINTOPOINT=$POINTOPOINT" - fi - if [ "$GATEWAY" ]; then - echo "GATEWAY=$GATEWAY" - fi - if [ "$ARGS" ]; then - echo "ARGS=\"$ARGS\"" - fi - if [ "$NOAUTO" ]; then - echo "NOAUTO=true" - fi - echo - } - echo -n "Write file $CONFIG (y/N)? "; read x + echo -e $STRING + echo -n "Write file $CONFIG (y/N)? "; read x + } + else + $DIALOG --yesno "$STRING\nSave file $CONFIG?" 20 40 && x="y" + fi if [ ! "$x" -o "$x" != "y" ]; then echo "Configuration not saved" return