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