-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreconfig
More file actions
executable file
·223 lines (199 loc) · 6 KB
/
reconfig
File metadata and controls
executable file
·223 lines (199 loc) · 6 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
:
#
# Usage: reconfig [file]
#
# This replaces the program paths (e.g. /bin/awk) in COPS with an
# alternate path that is found in the file "file.paths". Alternately,
# you can specify a single file to reconfig.
# All programs are renamed "name.old", and the new version replaces
# the original name. It then uses sed to replace all occurances of
# the target strings.
# Basically, the program looks through all directories listed in
# $all_dirs for the list of programs in $all_commands and when it finds
# them, puts them in a sed source file. It then goes to all of the
# shell files COPS uses ($shell_scripts) and replaces all occurances of
# the variables found with the new value. It goes through some
# contortions trying to look for test (it has to find test without
# using test), and does some other not so smart things, but it seems
# to get the job done.
# shell is always here, isn't it?
SH=/bin/sh
# need these later
TEST=
AWK=
SED=
TR=
# various types of awks; I'd really like to get gawk or mawk,
# but even nawk would be great. In order:
all_awks="gawk mawk nawk awk"
# Potential directories to find commands:
all_dirs='/usr/ccs/bin /bin /usr/bin /usr/ucb /usr/local/bin /usr/bsd /usr/ucb/bin'
# First things first; are test and echo built-in shell commands?
# Theory. If test is executed correctly and not found in the path
# I set, then they should be built into the shell, right?
PATH=/bin:/usr/bin
for dir in $all_dirs
do
if test -f $dir/test
then
TEST=$dir/test
break
fi
done
# if not set, then set to default
if test -z "$TEST"
then
TEST=test
fi
for dir in $all_dirs
do
if $TEST -f "$dir/echo"
then
ECHO=$dir/echo
break
fi
done
# if not set, then set to default
if $TEST -z "$ECHO"
then
ECHO=echo
fi
# The sed filter file
location=./file.paths
# Target shell scripts in question:
if $TEST $# -ne 0 ; then
shell_scripts="$*"
else
doc_make=docs/makefile
bug_stuff="bug.chk bug.chk.aix bug.chk.apollo bug.chk.dec \
bug.chk.next bug.chk.sgi bug.chk.sun bug.chk.svr4 bug_cmp"
shell_scripts="makefile $doc_make chk_strings cops crc.chk \
misc.chk dev.chk ftp.chk is_able.chk cron.chk group.chk \
passwd.chk rc.chk root.chk suid.chk kuang init_kuang \
res_diff pass_diff.chk yp_pass.chk $bug_stuff"
fi
# Target commands in question, sans those checked above:
all_commands='cc nroff cat chmod cmp comm cp date diff egrep expr find grep ls mail mkdir mv rm sed sh sort tftp touch uniq uudecode ypcat strings'
$ECHO checking to make sure all the target\(s\) are here...
# make sure everything is here:
for i in $shell_scripts
do
if $TEST ! -s $i
then
$ECHO ERROR -- $i not found!
exit
fi
done
# This finds the paths to any program used in COPS, then prints out
# a sed filter to the file "file.paths" that is used by this shell
# script to change all occurances of that command in the COPS system.
#
# For example, if sed is in /usr/bin, it will create a line that looks
# like this:
#
# s.SED=*$.SED=/usr/bin/sed.
#
# This corresponds to the sed command substitute ("-" is used as a
# delineator instead of "/" because the strings will be containing
# "/"'s) /usr/bin/sed in place of whatever was to the right of the
# equal sign. This works because all commands are accessed by the
# variable "$XYZ", where "XYZ" corresponds to the lowercase command
# "xyz". And, of course, all command variables are set at the top
# of each command file.
#
# First we need awk and sed if this shell script will work....
for dir in $all_dirs ; do
if $TEST -f $dir/sed ; then
SED=$dir/sed
fi
for awk in $all_awks ; do
if $TEST -z "$AWK" ; then
if $TEST -s "$dir/$awk" ; then
AWK=$dir/$awk
break
fi
fi
done
if $TEST -f $dir/tr ; then
TR=$dir/tr
fi
done
if $TEST -z "$AWK" ; then
$ECHO "Cannot find awk; awk is needed to run this shell script"
exit 1
fi
if $TEST -z "$SED" ; then
$ECHO "Cannot find sed; sed is needed to run this shell script"
exit 1
fi
if $TEST -z "$TR" ; then
$ECHO "Cannot find tr; tr is needed to run this shell script"
exit 1
fi
# zero out the file, then put in the real locations...
$ECHO > $location
$ECHO So far so good...
$ECHO Looking for all the commands now...
for command in $all_commands ; do
found=false
for dir in $all_dirs ; do
# if find the command in one of the directories, print string
if $TEST -f $dir/$command ; then
# this converts to upper case
upper=`$ECHO $command | $TR '[a-z]' '[A-Z]'`
$ECHO "s-^$upper=.*\$-$upper=$dir/$command-" >> $location
found=true
break
fi
done
if $TEST "$found" = "false" ; then
if $TEST $command = "strings" ; then
$ECHO Warning! $command not found! chk_strings will not work as planned.
elif $TEST $command = tftp ; then
$ECHO Warning! $command not found! misc.chk will not work as planned.
elif $TEST $command = uudecode ; then
$ECHO Warning! $command not found! misc.chk will not work as planned.
elif $TEST $command = ypcat ; then
:
elif $TEST $command = nroff ; then
$ECHO Warning! $command not found! docs cannot be formatted.
else
$ECHO ERROR! $command not found! Change or delete command!
exit
fi
fi
done
$ECHO "s-^AWK=.*\$-AWK=$AWK-" >> $location
$ECHO "s-^ECHO=.*\$-ECHO=$ECHO-" >> $location
$ECHO "s-^TEST=.*\$-TEST=$TEST-" >> $location
# almost forgot -- we need chmod & mv to make this reconfig work, too:
for dir in $all_dirs
do
if $TEST -f $dir/mv ; then
MV=$dir/mv
fi
if $TEST -f $dir/chmod ; then
CHMOD=$dir/chmod
fi
if $TEST -f $dir/ls ; then
LS=$dir/ls
res=`$LS -dgl / | $AWK '{print NF}'`
if $TEST "9" = "$res" ; then
# $ECHO "looks bsd-ish, use -g option with ls"
$ECHO "s-^LS_OPTS2=.*\$-LS_OPTS2=g-" >> $location
else
# $ECHO "sysV looking -- don't use -g option with ls"
$ECHO "s-^LS_OPTS2=.*\$-LS_OPTS2=-" >> $location
fi
fi
done
$ECHO Ok, now doing substitutions on the shell scripts...
for i in $shell_scripts
do
$ECHO "Changing paths in $i..."
$SED -f $location $i > $i.new
$MV $i $i.old
$MV $i.new $i
# finally, make sure everything is back to executable status
$CHMOD u+x $i
done