The return value of nameif was wrong
[platform/upstream/net-tools.git] / configure.sh
1 #!/usr/bin/env bash
2 #
3 # Configure.sh  Generates interactively a config.h from config.in
4 #
5 # net-tools     A collection of programs that form the base set of the
6 #               NET-3 Networking Distribution for the LINUX operating
7 #               system.
8 #
9 # Usage:        Install.sh [--nobackup] [--test]
10 #
11 # Version:      Install.sh 1.65 (1996-01-12)
12 #
13 # Authors:      Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
14 #               Johannes Grosen, <grosen@argv.cs.ndsu.nodak.edu>
15 #               Copyright 1988-1993 MicroWalt Corporation
16 #
17 # Modified:
18 #        {1.65} Bernd eckes Eckenfels <net-tools@lina.inka.de>
19 #               some layout cleanups, slattach/plipconfig removed.
20 #               --test for testinstallations added.
21 #
22 #               This program is free software; you can redistribute it
23 #               and/or  modify it under  the terms of  the GNU General
24 #               Public  License as  published  by  the  Free  Software
25 #               Foundation;  either  version 2 of the License, or  (at
26 #               your option) any later version.
27 #
28 #
29 # Make sure we're really running bash.
30 #
31 # I would really have preferred to write this script in a language with
32 # better string handling, but alas, bash is the only scripting language
33 # that I can be reasonable sure everybody has on their Linux machine.
34 #
35
36 CONFIG=config.h
37 MAKECONFIG=config.make
38
39
40 [ -z "$BASH" ] && { echo "Configure requires bash" 1>&2; exit 1; }
41
42 cat <<EOF
43
44 ######################################################
45 Notice: ifconfig and route are now installed into /bin
46 ######################################################
47
48 EOF
49
50 # Disable filename globbing once and for all.
51 # Enable function cacheing.
52 set -f -h
53
54 # set up reading of config file
55 if [ "$#" != "1" ] || [ ! -f "$1" ]; then
56         echo "usage: $0 configfile" 1>&2
57         exit 1
58 fi
59 exec 7<$1
60 config_fd_redir='<&7'
61
62 #
63 # readln reads a line into $ans.
64 #
65 #       readln prompt default
66 #
67 function readln()
68 {
69   echo -n "$1"
70   IFS='@' read ans || exit 1
71   [ -z "$ans" ] && ans=$2
72 }
73
74 # bool processes a boolean argument
75 #
76 #       bool tail
77 #
78 function bool()
79 {
80   # Slimier hack to get bash to rescan a line.
81   eval "set -- $1"
82   ans=""
83   while [ "$ans" != "y" -a "$ans" != "n" ]
84   do
85         readln "$1 ($2) [$3] " "$3"
86   done
87   if [ "$ans" = "y" ]; then
88         echo "#define $2 1" >>${CONFIG}
89         echo "$2=1" >>${MAKECONFIG}
90     else
91         echo "#define $2 0" >>${CONFIG}
92         echo "# $2=0" >> ${MAKECONFIG}
93   fi
94   raw_input_line="bool '$1' $2 $ans"
95   eval "$2=$ans"
96 }
97
98 # int processes an integer argument
99 #
100 #       int tail
101 #
102 function int()
103 {
104   # Slimier hack to get bash to rescan a line.
105   eval "set -- $1"
106   ans="x"
107   while [ $[$ans+0] != "$ans" ];
108   do
109         readln "$1 ($2) [$3] " "$3"
110   done
111   echo "#define $2 ($ans)" >>${CONFIG}
112   raw_input_line="int '$1' $2 $ans"
113   eval "$2=$ans"
114 }
115
116   #
117   # Make sure we start out with a clean slate.
118   #
119   > config.new
120   > ${CONFIG}
121   > ${MAKECONFIG}
122
123   stack=''
124   branch='t'
125
126   while IFS='@' eval read raw_input_line ${config_fd_redir}
127   do
128         # Slimy hack to get bash to rescan a line.
129         read cmd rest <<-END_OF_COMMAND
130                 $raw_input_line
131         END_OF_COMMAND
132
133         if [ "$cmd" = "*" ]; then
134                 if [ "$branch" = "t" ]; then
135                         echo "$raw_input_line"
136                         # echo "# $rest" >>$CONFIG
137                         if [ "$prevcmd" != "*" ]; then
138                                 echo >>${CONFIG}
139                                 echo "/* $rest" >>${CONFIG}
140                         else
141                                 echo " * $rest" >>${CONFIG}
142                         fi
143                         prevcmd="*"
144                 fi
145         else
146                 [ "$prevcmd" = "*" ] && echo " */" >>${CONFIG}
147                 prevcmd=""
148                 case "$cmd" in
149                 =)      [ "$branch" = "t" ] && echo "$rest" >>${CONFIG};;
150                 :)      [ "$branch" = "t" ] && echo "$raw_input_line" ;;
151                 int)    [ "$branch" = "t" ] && int "$rest" ;;
152                 bool)   [ "$branch" = "t" ] && bool "$rest" ;;
153                 exec)   [ "$branch" = "t" ] && ( sh -c "$rest" ) ;;
154                 if)     stack="$branch $stack"
155                         if [ "$branch" = "t" ] && eval "$rest"; then
156                                 branch=t
157                         else
158                                 branch=f
159                         fi ;;
160                 else)   if [ "$branch" = "t" ]; then
161                                 branch=f
162                         else
163                                 read branch rest <<-END_OF_STACK
164                                         $stack
165                                 END_OF_STACK
166                         fi ;;
167                 fi)     [ -z "$stack" ] && echo "Error!  Extra fi." 1>&2
168                         read branch stack <<-END_OF_STACK
169                                 $stack
170                         END_OF_STACK
171                         ;;
172                 esac
173         fi
174         echo "$raw_input_line" >>config.new
175   done
176   [ "$prevcmd" = "*" ] && echo " */" >>${CONFIG}
177
178   [ -z "$stack" ] || echo "Error!  Unterminated if." 1>&2
179
180   mv config.new config.status
181   exit 0