Deleted Added
full compact
mergemaster.sh (94196) mergemaster.sh (96045)
1#!/bin/sh
2
3# mergemaster
4
5# Compare files created by /usr/src/etc/Makefile (or the directory
6# the user specifies) with the currently installed copies.
7
8# Copyright 1998-2002 Douglas Barton
9# DougB@FreeBSD.org
10
1#!/bin/sh
2
3# mergemaster
4
5# Compare files created by /usr/src/etc/Makefile (or the directory
6# the user specifies) with the currently installed copies.
7
8# Copyright 1998-2002 Douglas Barton
9# DougB@FreeBSD.org
10
11# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 94196 2002-04-08 10:30:44Z dougb $
11# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 96045 2002-05-04 22:45:12Z dougb $
12
13PATH=/bin:/usr/bin:/usr/sbin
14
15display_usage () {
16 VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4`
17 echo "mergemaster version ${VERSION_NUMBER}"
18 echo 'Usage: mergemaster [-scrvahipC] [-m /path]'
19 echo ' [-t /path] [-d] [-u N] [-w N] [-D /path]'
20 echo "Options:"
21 echo " -s Strict comparison (diff every pair of files)"
22 echo " -c Use context diff instead of unified diff"
23 echo " -r Re-run on a previously cleaned directory (skip temproot creation)"
24 echo " -v Be more verbose about the process, include additional checks"
25 echo " -a Leave all files that differ to merge by hand"
26 echo " -h Display more complete help"
27 echo ' -i Automatically install files that do not exist in destination directory'
28 echo ' -p Pre-buildworld mode, only compares crucial files'
29 echo ' -C Compare local rc.conf variables to the defaults'
30 echo " -m /path/directory Specify location of source to do the make in"
31 echo " -t /path/directory Specify temp root directory"
32 echo " -d Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)"
33 echo " -u N Specify a numeric umask"
34 echo " -w N Specify a screen width in columns to sdiff"
35 echo ' -D /path/directory Specify the destination directory to install files to'
36 echo ''
37}
38
39display_help () {
40 echo "* To specify a directory other than /var/tmp/temproot for the"
41 echo " temporary root environment, use -t /path/to/temp/root"
42 echo "* The -w option takes a number as an argument for the column width"
43 echo " of the screen. The default is 80."
44 echo '* The -a option causes mergemaster to run without prompting.'
45}
46
47# Loop allowing the user to use sdiff to merge files and display the merged
48# file.
49merge_loop () {
50 case "${VERBOSE}" in
51 '') ;;
52 *)
53 echo " *** Type h at the sdiff prompt (%) to get usage help"
54 ;;
55 esac
56 echo ''
57 MERGE_AGAIN=yes
58 while [ "${MERGE_AGAIN}" = "yes" ]; do
59 # Prime file.merged so we don't blat the owner/group id's
60 cp -p "${COMPFILE}" "${COMPFILE}.merged"
61 sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \
62 --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
63 INSTALL_MERGED=V
64 while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do
65 echo ''
66 echo " Use 'i' to install merged file"
67 echo " Use 'r' to re-do the merge"
68 echo " Use 'v' to view the merged file"
69 echo " Default is to leave the temporary file to deal with by hand"
70 echo ''
71 echo -n " *** How should I deal with the merged file? [Leave it for later] "
72 read INSTALL_MERGED
73
74 case "${INSTALL_MERGED}" in
75 [iI])
76 mv "${COMPFILE}.merged" "${COMPFILE}"
77 echo ''
78 if mm_install "${COMPFILE}"; then
79 echo " *** Merged version of ${COMPFILE} installed successfully"
80 else
81 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later"
82 fi
83 unset MERGE_AGAIN
84 ;;
85 [rR])
86 rm "${COMPFILE}.merged"
87 ;;
88 [vV])
89 ${PAGER} "${COMPFILE}.merged"
90 ;;
91 '')
92 echo " *** ${COMPFILE} will remain for your consideration"
93 unset MERGE_AGAIN
94 ;;
95 *)
96 echo "invalid choice: ${INSTALL_MERGED}"
97 INSTALL_MERGED=V
98 ;;
99 esac
100 done
101 done
102}
103
104# Loop showing user differences between files, allow merge, skip or install
105# options
106diff_loop () {
107
108 HANDLE_COMPFILE=v
109
110 while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \
111 "${HANDLE_COMPFILE}" = "NOT V" ]; do
112 if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then
113 if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then
114 echo ''
115 echo ' ====================================================================== '
116 echo ''
117 (
118 echo ''
119 echo " *** Displaying differences between ${COMPFILE} and installed version:"
120 echo ''
121 diff "${DIFF_FLAG}" "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
122 ) | ${PAGER}
123 echo ''
124 fi
125 else
126 echo ''
127 echo " *** There is no installed version of ${COMPFILE}"
128 echo ''
129 case "${AUTO_INSTALL}" in
130 [Yy][Ee][Ss])
131 echo ''
132 if mm_install "${COMPFILE}"; then
133 echo " *** ${COMPFILE} installed successfully"
134 echo ''
135 # Make the list print one file per line
136 AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.}
137"
138 else
139 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand"
140 fi
141 return
142 ;;
143 *)
144 NO_INSTALLED=yes
145 ;;
146 esac
147 fi
148
149 echo " Use 'd' to delete the temporary ${COMPFILE}"
150 echo " Use 'i' to install the temporary ${COMPFILE}"
151 case "${NO_INSTALLED}" in
152 '')
153 echo " Use 'm' to merge the temporary and installed versions"
154 echo " Use 'v' to view the diff results again"
155 ;;
156 esac
157 echo ''
158 echo " Default is to leave the temporary file to deal with by hand"
159 echo ''
160 echo -n "How should I deal with this? [Leave it for later] "
161 read HANDLE_COMPFILE
162
163 case "${HANDLE_COMPFILE}" in
164 [dD])
165 rm "${COMPFILE}"
166 echo ''
167 echo " *** Deleting ${COMPFILE}"
168 ;;
169 [iI])
170 echo ''
171 if mm_install "${COMPFILE}"; then
172 echo " *** ${COMPFILE} installed successfully"
173 else
174 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand"
175 fi
176 ;;
177 [mM])
178 case "${NO_INSTALLED}" in
179 '')
180 # interact with user to merge files
181 merge_loop
182 ;;
183 *)
184 echo ''
185 echo " *** There is no installed version of ${COMPFILE}"
186 echo ''
187 HANDLE_COMPFILE="NOT V"
188 ;;
189 esac # End of "No installed version of file but user selected merge" test
190 ;;
191 [vV])
192 continue
193 ;;
194 '')
195 echo ''
196 echo " *** ${COMPFILE} will remain for your consideration"
197 ;;
198 *)
199 # invalid choice, show menu again.
200 echo "invalid choice: ${HANDLE_COMPFILE}"
201 echo ''
202 HANDLE_COMPFILE="NOT V"
203 continue
204 ;;
205 esac # End of "How to handle files that are different"
206 done
207 unset NO_INSTALLED
208 echo ''
209 case "${VERBOSE}" in
210 '') ;;
211 *)
212 sleep 3
213 ;;
214 esac
215}
216
217# Set the default path for the temporary root environment
218#
219TEMPROOT='/var/tmp/temproot'
220
221# Read /etc/mergemaster.rc first so the one in $HOME can override
222#
223if [ -r /etc/mergemaster.rc ]; then
224 . /etc/mergemaster.rc
225fi
226
227# Read .mergemasterrc before command line so CLI can override
228#
229if [ -r "$HOME/.mergemasterrc" ]; then
230 . "$HOME/.mergemasterrc"
231fi
232
233# Check the command line options
234#
235while getopts ":ascrvhipCm:t:du:w:D:" COMMAND_LINE_ARGUMENT ; do
236 case "${COMMAND_LINE_ARGUMENT}" in
237 s)
238 STRICT=yes
239 ;;
240 c)
241 DIFF_FLAG='-c'
242 ;;
243 r)
244 RERUN=yes
245 ;;
246 v)
247 case "${AUTO_RUN}" in
248 '') VERBOSE=yes ;;
249 esac
250 ;;
251 a)
252 AUTO_RUN=yes
253 unset VERBOSE
254 ;;
255 h)
256 display_usage
257 display_help
258 exit 0
259 ;;
260 i)
261 AUTO_INSTALL=yes
262 ;;
12
13PATH=/bin:/usr/bin:/usr/sbin
14
15display_usage () {
16 VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4`
17 echo "mergemaster version ${VERSION_NUMBER}"
18 echo 'Usage: mergemaster [-scrvahipC] [-m /path]'
19 echo ' [-t /path] [-d] [-u N] [-w N] [-D /path]'
20 echo "Options:"
21 echo " -s Strict comparison (diff every pair of files)"
22 echo " -c Use context diff instead of unified diff"
23 echo " -r Re-run on a previously cleaned directory (skip temproot creation)"
24 echo " -v Be more verbose about the process, include additional checks"
25 echo " -a Leave all files that differ to merge by hand"
26 echo " -h Display more complete help"
27 echo ' -i Automatically install files that do not exist in destination directory'
28 echo ' -p Pre-buildworld mode, only compares crucial files'
29 echo ' -C Compare local rc.conf variables to the defaults'
30 echo " -m /path/directory Specify location of source to do the make in"
31 echo " -t /path/directory Specify temp root directory"
32 echo " -d Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)"
33 echo " -u N Specify a numeric umask"
34 echo " -w N Specify a screen width in columns to sdiff"
35 echo ' -D /path/directory Specify the destination directory to install files to'
36 echo ''
37}
38
39display_help () {
40 echo "* To specify a directory other than /var/tmp/temproot for the"
41 echo " temporary root environment, use -t /path/to/temp/root"
42 echo "* The -w option takes a number as an argument for the column width"
43 echo " of the screen. The default is 80."
44 echo '* The -a option causes mergemaster to run without prompting.'
45}
46
47# Loop allowing the user to use sdiff to merge files and display the merged
48# file.
49merge_loop () {
50 case "${VERBOSE}" in
51 '') ;;
52 *)
53 echo " *** Type h at the sdiff prompt (%) to get usage help"
54 ;;
55 esac
56 echo ''
57 MERGE_AGAIN=yes
58 while [ "${MERGE_AGAIN}" = "yes" ]; do
59 # Prime file.merged so we don't blat the owner/group id's
60 cp -p "${COMPFILE}" "${COMPFILE}.merged"
61 sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \
62 --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
63 INSTALL_MERGED=V
64 while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do
65 echo ''
66 echo " Use 'i' to install merged file"
67 echo " Use 'r' to re-do the merge"
68 echo " Use 'v' to view the merged file"
69 echo " Default is to leave the temporary file to deal with by hand"
70 echo ''
71 echo -n " *** How should I deal with the merged file? [Leave it for later] "
72 read INSTALL_MERGED
73
74 case "${INSTALL_MERGED}" in
75 [iI])
76 mv "${COMPFILE}.merged" "${COMPFILE}"
77 echo ''
78 if mm_install "${COMPFILE}"; then
79 echo " *** Merged version of ${COMPFILE} installed successfully"
80 else
81 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later"
82 fi
83 unset MERGE_AGAIN
84 ;;
85 [rR])
86 rm "${COMPFILE}.merged"
87 ;;
88 [vV])
89 ${PAGER} "${COMPFILE}.merged"
90 ;;
91 '')
92 echo " *** ${COMPFILE} will remain for your consideration"
93 unset MERGE_AGAIN
94 ;;
95 *)
96 echo "invalid choice: ${INSTALL_MERGED}"
97 INSTALL_MERGED=V
98 ;;
99 esac
100 done
101 done
102}
103
104# Loop showing user differences between files, allow merge, skip or install
105# options
106diff_loop () {
107
108 HANDLE_COMPFILE=v
109
110 while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \
111 "${HANDLE_COMPFILE}" = "NOT V" ]; do
112 if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then
113 if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then
114 echo ''
115 echo ' ====================================================================== '
116 echo ''
117 (
118 echo ''
119 echo " *** Displaying differences between ${COMPFILE} and installed version:"
120 echo ''
121 diff "${DIFF_FLAG}" "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
122 ) | ${PAGER}
123 echo ''
124 fi
125 else
126 echo ''
127 echo " *** There is no installed version of ${COMPFILE}"
128 echo ''
129 case "${AUTO_INSTALL}" in
130 [Yy][Ee][Ss])
131 echo ''
132 if mm_install "${COMPFILE}"; then
133 echo " *** ${COMPFILE} installed successfully"
134 echo ''
135 # Make the list print one file per line
136 AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.}
137"
138 else
139 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand"
140 fi
141 return
142 ;;
143 *)
144 NO_INSTALLED=yes
145 ;;
146 esac
147 fi
148
149 echo " Use 'd' to delete the temporary ${COMPFILE}"
150 echo " Use 'i' to install the temporary ${COMPFILE}"
151 case "${NO_INSTALLED}" in
152 '')
153 echo " Use 'm' to merge the temporary and installed versions"
154 echo " Use 'v' to view the diff results again"
155 ;;
156 esac
157 echo ''
158 echo " Default is to leave the temporary file to deal with by hand"
159 echo ''
160 echo -n "How should I deal with this? [Leave it for later] "
161 read HANDLE_COMPFILE
162
163 case "${HANDLE_COMPFILE}" in
164 [dD])
165 rm "${COMPFILE}"
166 echo ''
167 echo " *** Deleting ${COMPFILE}"
168 ;;
169 [iI])
170 echo ''
171 if mm_install "${COMPFILE}"; then
172 echo " *** ${COMPFILE} installed successfully"
173 else
174 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand"
175 fi
176 ;;
177 [mM])
178 case "${NO_INSTALLED}" in
179 '')
180 # interact with user to merge files
181 merge_loop
182 ;;
183 *)
184 echo ''
185 echo " *** There is no installed version of ${COMPFILE}"
186 echo ''
187 HANDLE_COMPFILE="NOT V"
188 ;;
189 esac # End of "No installed version of file but user selected merge" test
190 ;;
191 [vV])
192 continue
193 ;;
194 '')
195 echo ''
196 echo " *** ${COMPFILE} will remain for your consideration"
197 ;;
198 *)
199 # invalid choice, show menu again.
200 echo "invalid choice: ${HANDLE_COMPFILE}"
201 echo ''
202 HANDLE_COMPFILE="NOT V"
203 continue
204 ;;
205 esac # End of "How to handle files that are different"
206 done
207 unset NO_INSTALLED
208 echo ''
209 case "${VERBOSE}" in
210 '') ;;
211 *)
212 sleep 3
213 ;;
214 esac
215}
216
217# Set the default path for the temporary root environment
218#
219TEMPROOT='/var/tmp/temproot'
220
221# Read /etc/mergemaster.rc first so the one in $HOME can override
222#
223if [ -r /etc/mergemaster.rc ]; then
224 . /etc/mergemaster.rc
225fi
226
227# Read .mergemasterrc before command line so CLI can override
228#
229if [ -r "$HOME/.mergemasterrc" ]; then
230 . "$HOME/.mergemasterrc"
231fi
232
233# Check the command line options
234#
235while getopts ":ascrvhipCm:t:du:w:D:" COMMAND_LINE_ARGUMENT ; do
236 case "${COMMAND_LINE_ARGUMENT}" in
237 s)
238 STRICT=yes
239 ;;
240 c)
241 DIFF_FLAG='-c'
242 ;;
243 r)
244 RERUN=yes
245 ;;
246 v)
247 case "${AUTO_RUN}" in
248 '') VERBOSE=yes ;;
249 esac
250 ;;
251 a)
252 AUTO_RUN=yes
253 unset VERBOSE
254 ;;
255 h)
256 display_usage
257 display_help
258 exit 0
259 ;;
260 i)
261 AUTO_INSTALL=yes
262 ;;
263 p)
264 PRE_WORLD=yes
265 ;;
266 C)
267 COMP_CONFS=yes
268 ;;
263 C)
264 COMP_CONFS=yes
265 ;;
266 p)
267 PRE_WORLD=yes
268 unset COMP_CONFS
269 unset AUTO_RUN
270 ;;
269 m)
270 SOURCEDIR=${OPTARG}
271 ;;
272 t)
273 TEMPROOT=${OPTARG}
274 ;;
275 d)
276 TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M`
277 ;;
278 u)
279 NEW_UMASK=${OPTARG}
280 ;;
281 w)
282 SCREEN_WIDTH=${OPTARG}
283 ;;
284 D)
285 DESTDIR=${OPTARG}
286 ;;
287 *)
288 display_usage
289 exit 1
290 ;;
291 esac
292done
293
294echo ''
295
296# If the user has a pager defined, make sure we can run it
297#
298case "${DONT_CHECK_PAGER}" in
299'')
300 while ! type "${PAGER%% *}" >/dev/null && [ -n "${PAGER}" ]; do
301 echo " *** Your PAGER environment variable specifies '${PAGER}', but"
302 echo " due to the limited PATH that I use for security reasons,"
303 echo " I cannot execute it. So, what would you like to do?"
304 echo ''
305 echo " Use 'e' to exit mergemaster and fix your PAGER variable"
306 if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then
307 echo " Use 'l' to set PAGER to 'less' for this run"
308 fi
309 echo " Use 'm' to use plain old 'more' as your PAGER for this run"
310 echo ''
311 echo " Default is to use plain old 'more' "
312 echo ''
313 echo -n "What should I do? [Use 'more'] "
314 read FIXPAGER
315
316 case "${FIXPAGER}" in
317 [eE])
318 exit 0
319 ;;
320 [lL])
321 if [ -x /usr/bin/less ]; then
322 PAGER=/usr/bin/less
323 elif [ -x /usr/local/bin/less ]; then
324 PAGER=/usr/local/bin/less
325 else
326 echo ''
327 echo " *** Fatal Error:"
328 echo " You asked to use 'less' as your pager, but I can't"
329 echo " find it in /usr/bin or /usr/local/bin"
330 exit 1
331 fi
332 ;;
333 [mM]|'')
334 PAGER=more
335 ;;
336 *)
337 echo ''
338 echo "invalid choice: ${FIXPAGER}"
339 esac
340 echo ''
341 done
342 ;;
343esac
344
345# If user has a pager defined, or got assigned one above, use it.
346# If not, use more.
347#
348PAGER=${PAGER:-more}
349
350if [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then
351 echo " *** You have ${PAGER} defined as your pager so we will use that"
352 echo ''
353 sleep 3
354fi
355
356# Assign the diff flag once so we will not have to keep testing it
357#
358DIFF_FLAG=${DIFF_FLAG:--u}
359
360# Assign the source directory
361#
362SOURCEDIR=${SOURCEDIR:-/usr/src/etc}
363
271 m)
272 SOURCEDIR=${OPTARG}
273 ;;
274 t)
275 TEMPROOT=${OPTARG}
276 ;;
277 d)
278 TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M`
279 ;;
280 u)
281 NEW_UMASK=${OPTARG}
282 ;;
283 w)
284 SCREEN_WIDTH=${OPTARG}
285 ;;
286 D)
287 DESTDIR=${OPTARG}
288 ;;
289 *)
290 display_usage
291 exit 1
292 ;;
293 esac
294done
295
296echo ''
297
298# If the user has a pager defined, make sure we can run it
299#
300case "${DONT_CHECK_PAGER}" in
301'')
302 while ! type "${PAGER%% *}" >/dev/null && [ -n "${PAGER}" ]; do
303 echo " *** Your PAGER environment variable specifies '${PAGER}', but"
304 echo " due to the limited PATH that I use for security reasons,"
305 echo " I cannot execute it. So, what would you like to do?"
306 echo ''
307 echo " Use 'e' to exit mergemaster and fix your PAGER variable"
308 if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then
309 echo " Use 'l' to set PAGER to 'less' for this run"
310 fi
311 echo " Use 'm' to use plain old 'more' as your PAGER for this run"
312 echo ''
313 echo " Default is to use plain old 'more' "
314 echo ''
315 echo -n "What should I do? [Use 'more'] "
316 read FIXPAGER
317
318 case "${FIXPAGER}" in
319 [eE])
320 exit 0
321 ;;
322 [lL])
323 if [ -x /usr/bin/less ]; then
324 PAGER=/usr/bin/less
325 elif [ -x /usr/local/bin/less ]; then
326 PAGER=/usr/local/bin/less
327 else
328 echo ''
329 echo " *** Fatal Error:"
330 echo " You asked to use 'less' as your pager, but I can't"
331 echo " find it in /usr/bin or /usr/local/bin"
332 exit 1
333 fi
334 ;;
335 [mM]|'')
336 PAGER=more
337 ;;
338 *)
339 echo ''
340 echo "invalid choice: ${FIXPAGER}"
341 esac
342 echo ''
343 done
344 ;;
345esac
346
347# If user has a pager defined, or got assigned one above, use it.
348# If not, use more.
349#
350PAGER=${PAGER:-more}
351
352if [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then
353 echo " *** You have ${PAGER} defined as your pager so we will use that"
354 echo ''
355 sleep 3
356fi
357
358# Assign the diff flag once so we will not have to keep testing it
359#
360DIFF_FLAG=${DIFF_FLAG:--u}
361
362# Assign the source directory
363#
364SOURCEDIR=${SOURCEDIR:-/usr/src/etc}
365
366# Check the width of the user's terminal
367#
368if [ -t 0 ]; then
369 w=$(stty -a | sed -ne 's/.* \([0-9][0-9]*\) columns.*/\1/p')
370 case "${w}" in
371 0|'') ;; # No-op, since the input is not valid
372 *)
373 case "${SCREEN_WIDTH}" in
374 '') SCREEN_WIDTH="${w}" ;;
375 "${w}") ;; # No-op, since they are the same
376 *)
377 echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty "
378 echo "thinks it is ${w}."
379 echo ''
380 echo -n "What would you like to use? [${w}] "
381 read SCREEN_WIDTH
382 ;;
383 esac
384 esac
385fi
386
364# Define what CVS $Id tag to look for to aid portability.
365#
366CVS_ID_TAG=FreeBSD
367
368case "${RERUN}" in
369'')
370 # Set up the loop to test for the existence of the
371 # temp root directory.
372 #
373 TEST_TEMP_ROOT=yes
374 while [ "${TEST_TEMP_ROOT}" = "yes" ]; do
375 if [ -d "${TEMPROOT}" ]; then
376 echo "*** The directory specified for the temporary root environment,"
377 echo " ${TEMPROOT}, exists. This can be a security risk if untrusted"
378 echo " users have access to the system."
379 echo ''
380 case "${AUTO_RUN}" in
381 '')
382 echo " Use 'd' to delete the old ${TEMPROOT} and continue"
383 echo " Use 't' to select a new temporary root directory"
384 echo " Use 'e' to exit mergemaster"
385 echo ''
386 echo " Default is to use ${TEMPROOT} as is"
387 echo ''
388 echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] "
389 read DELORNOT
390
391 case "${DELORNOT}" in
392 [dD])
393 echo ''
394 echo " *** Deleting the old ${TEMPROOT}"
395 echo ''
396 rm -rf "${TEMPROOT}"
397 unset TEST_TEMP_ROOT
398 ;;
399 [tT])
400 echo " *** Enter new directory name for temporary root environment"
401 read TEMPROOT
402 ;;
403 [eE])
404 exit 0
405 ;;
406 '')
407 echo ''
408 echo " *** Leaving ${TEMPROOT} intact"
409 echo ''
410 unset TEST_TEMP_ROOT
411 ;;
412 *)
413 echo ''
414 echo "invalid choice: ${DELORNOT}"
415 echo ''
416 ;;
417 esac
418 ;;
419 *)
420 # If this is an auto-run, try a hopefully safe alternative then
421 # re-test anyway.
422 TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S`
423 ;;
424 esac
425 else
426 unset TEST_TEMP_ROOT
427 fi
428 done
429
430 echo "*** Creating the temporary root environment in ${TEMPROOT}"
431
432 if mkdir -p "${TEMPROOT}"; then
433 echo " *** ${TEMPROOT} ready for use"
434 fi
435
436 if [ ! -d "${TEMPROOT}" ]; then
437 echo ''
438 echo " *** FATAL ERROR: Cannot create ${TEMPROOT}"
439 echo ''
440 exit 1
441 fi
442
443 echo " *** Creating and populating directory structure in ${TEMPROOT}"
444 echo ''
445
446 case "${VERBOSE}" in
447 '') ;;
448 *)
449 echo " *** Press [Enter] or [Return] key to continue"
450 read ANY_KEY
451 unset ANY_KEY
452 ;;
453 esac
454
455 case "${PRE_WORLD}" in
456 '')
457 { cd ${SOURCEDIR} &&
458 case "${DESTDIR}" in
459 '') ;;
460 *)
461 make DESTDIR=${DESTDIR} distrib-dirs
462 ;;
463 esac
464 make DESTDIR=${TEMPROOT} distrib-dirs &&
465 make MAKEOBJDIRPREFIX=${TEMPROOT}/usr/obj obj &&
466 make MAKEOBJDIRPREFIX=${TEMPROOT}/usr/obj DESTDIR=${TEMPROOT} \
467 -DNO_MAKEDEV_RUN distribution;} ||
468 { echo '';
469 echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
470 echo " the temproot environment";
471 echo '';
472 exit 1;}
473 ;;
474 *)
475 # Only set up files that are crucial to {build|install}world
476 { mkdir -p ${TEMPROOT}/etc &&
477 cp -p ${SOURCEDIR}/master.passwd ${TEMPROOT}/etc &&
478 cp -p ${SOURCEDIR}/group ${TEMPROOT}/etc;} ||
479 { echo '';
480 echo ' *** FATAL ERROR: Cannot copy files to the temproot environment';
481 echo '';
482 exit 1;}
483 ;;
484 esac
485
486 # Doing the inventory and removing files that we don't want to compare only
487 # makes sense if we are not doing a rerun, since we have no way of knowing
488 # what happened to the files during previous incarnations.
489 case "${VERBOSE}" in
490 '') ;;
491 *)
492 echo ''
493 echo ' *** The following files exist only in the installed version of'
494 echo " ${DESTDIR}/etc. In the vast majority of cases these files"
495 echo ' are necessary parts of the system and should not be deleted.'
496 echo ' However because these files are not updated by this process you'
497 echo ' might want to verify their status before rebooting your system.'
498 echo ''
499 echo ' *** Press [Enter] or [Return] key to continue'
500 read ANY_KEY
501 unset ANY_KEY
502 diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in /etc" | ${PAGER}
503 echo ''
504 echo ' *** Press [Enter] or [Return] key to continue'
505 read ANY_KEY
506 unset ANY_KEY
507 ;;
508 esac
509
510 # Avoid comparing the motd if the user specifies it in .mergemasterrc
511 case "${IGNORE_MOTD}" in
512 '') ;;
387# Define what CVS $Id tag to look for to aid portability.
388#
389CVS_ID_TAG=FreeBSD
390
391case "${RERUN}" in
392'')
393 # Set up the loop to test for the existence of the
394 # temp root directory.
395 #
396 TEST_TEMP_ROOT=yes
397 while [ "${TEST_TEMP_ROOT}" = "yes" ]; do
398 if [ -d "${TEMPROOT}" ]; then
399 echo "*** The directory specified for the temporary root environment,"
400 echo " ${TEMPROOT}, exists. This can be a security risk if untrusted"
401 echo " users have access to the system."
402 echo ''
403 case "${AUTO_RUN}" in
404 '')
405 echo " Use 'd' to delete the old ${TEMPROOT} and continue"
406 echo " Use 't' to select a new temporary root directory"
407 echo " Use 'e' to exit mergemaster"
408 echo ''
409 echo " Default is to use ${TEMPROOT} as is"
410 echo ''
411 echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] "
412 read DELORNOT
413
414 case "${DELORNOT}" in
415 [dD])
416 echo ''
417 echo " *** Deleting the old ${TEMPROOT}"
418 echo ''
419 rm -rf "${TEMPROOT}"
420 unset TEST_TEMP_ROOT
421 ;;
422 [tT])
423 echo " *** Enter new directory name for temporary root environment"
424 read TEMPROOT
425 ;;
426 [eE])
427 exit 0
428 ;;
429 '')
430 echo ''
431 echo " *** Leaving ${TEMPROOT} intact"
432 echo ''
433 unset TEST_TEMP_ROOT
434 ;;
435 *)
436 echo ''
437 echo "invalid choice: ${DELORNOT}"
438 echo ''
439 ;;
440 esac
441 ;;
442 *)
443 # If this is an auto-run, try a hopefully safe alternative then
444 # re-test anyway.
445 TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S`
446 ;;
447 esac
448 else
449 unset TEST_TEMP_ROOT
450 fi
451 done
452
453 echo "*** Creating the temporary root environment in ${TEMPROOT}"
454
455 if mkdir -p "${TEMPROOT}"; then
456 echo " *** ${TEMPROOT} ready for use"
457 fi
458
459 if [ ! -d "${TEMPROOT}" ]; then
460 echo ''
461 echo " *** FATAL ERROR: Cannot create ${TEMPROOT}"
462 echo ''
463 exit 1
464 fi
465
466 echo " *** Creating and populating directory structure in ${TEMPROOT}"
467 echo ''
468
469 case "${VERBOSE}" in
470 '') ;;
471 *)
472 echo " *** Press [Enter] or [Return] key to continue"
473 read ANY_KEY
474 unset ANY_KEY
475 ;;
476 esac
477
478 case "${PRE_WORLD}" in
479 '')
480 { cd ${SOURCEDIR} &&
481 case "${DESTDIR}" in
482 '') ;;
483 *)
484 make DESTDIR=${DESTDIR} distrib-dirs
485 ;;
486 esac
487 make DESTDIR=${TEMPROOT} distrib-dirs &&
488 make MAKEOBJDIRPREFIX=${TEMPROOT}/usr/obj obj &&
489 make MAKEOBJDIRPREFIX=${TEMPROOT}/usr/obj DESTDIR=${TEMPROOT} \
490 -DNO_MAKEDEV_RUN distribution;} ||
491 { echo '';
492 echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
493 echo " the temproot environment";
494 echo '';
495 exit 1;}
496 ;;
497 *)
498 # Only set up files that are crucial to {build|install}world
499 { mkdir -p ${TEMPROOT}/etc &&
500 cp -p ${SOURCEDIR}/master.passwd ${TEMPROOT}/etc &&
501 cp -p ${SOURCEDIR}/group ${TEMPROOT}/etc;} ||
502 { echo '';
503 echo ' *** FATAL ERROR: Cannot copy files to the temproot environment';
504 echo '';
505 exit 1;}
506 ;;
507 esac
508
509 # Doing the inventory and removing files that we don't want to compare only
510 # makes sense if we are not doing a rerun, since we have no way of knowing
511 # what happened to the files during previous incarnations.
512 case "${VERBOSE}" in
513 '') ;;
514 *)
515 echo ''
516 echo ' *** The following files exist only in the installed version of'
517 echo " ${DESTDIR}/etc. In the vast majority of cases these files"
518 echo ' are necessary parts of the system and should not be deleted.'
519 echo ' However because these files are not updated by this process you'
520 echo ' might want to verify their status before rebooting your system.'
521 echo ''
522 echo ' *** Press [Enter] or [Return] key to continue'
523 read ANY_KEY
524 unset ANY_KEY
525 diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in /etc" | ${PAGER}
526 echo ''
527 echo ' *** Press [Enter] or [Return] key to continue'
528 read ANY_KEY
529 unset ANY_KEY
530 ;;
531 esac
532
533 # Avoid comparing the motd if the user specifies it in .mergemasterrc
534 case "${IGNORE_MOTD}" in
535 '') ;;
513 *) rm ${TEMPROOT}/etc/motd
536 *) rm -f ${TEMPROOT}/etc/motd
514 ;;
515 esac
516
517 # Avoid trying to update MAKEDEV if /dev is on a devfs
518 if /sbin/sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
519 rm -f ${TEMPROOT}/dev/MAKEDEV ${TEMPROOT}/dev/MAKEDEV.local
520 fi
521
522 ;; # End of the "RERUN" test
523esac
524
525# We really don't want to have to deal with these files, since
526# master.passwd is the real file that should be compared, then
527# the user should run pwd_mkdb if necessary.
528#
529rm -f ${TEMPROOT}/etc/spwd.db ${TEMPROOT}/etc/passwd ${TEMPROOT}/etc/pwd.db
530
531# We only need to compare things like freebsd.cf once
537 ;;
538 esac
539
540 # Avoid trying to update MAKEDEV if /dev is on a devfs
541 if /sbin/sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
542 rm -f ${TEMPROOT}/dev/MAKEDEV ${TEMPROOT}/dev/MAKEDEV.local
543 fi
544
545 ;; # End of the "RERUN" test
546esac
547
548# We really don't want to have to deal with these files, since
549# master.passwd is the real file that should be compared, then
550# the user should run pwd_mkdb if necessary.
551#
552rm -f ${TEMPROOT}/etc/spwd.db ${TEMPROOT}/etc/passwd ${TEMPROOT}/etc/pwd.db
553
554# We only need to compare things like freebsd.cf once
532find ${TEMPROOT}/usr/obj -type f -delete
555find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
533
534# Get ready to start comparing files
535
536# Check umask if not specified on the command line,
537# and we are not doing an autorun
538#
539if [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then
540 USER_UMASK=`umask`
541 case "${USER_UMASK}" in
542 0022|022) ;;
543 *)
544 echo ''
545 echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script"
546 echo " installs all files with the same user, group and modes that"
547 echo " they are created with by ${SOURCEDIR}/Makefile, compared to"
548 echo " a umask of 022. This umask allows world read permission when"
549 echo " the file's default permissions have it."
550 echo " No world permissions can sometimes cause problems. A umask of"
551 echo " 022 will restore the default behavior, but is not mandatory."
552 echo " /etc/master.passwd is a special case. Its file permissions"
553 echo " will be 600 (rw-------) if installed."
554 echo ''
555 echo -n "What umask should I use? [${USER_UMASK}] "
556 read NEW_UMASK
557
558 NEW_UMASK="${NEW_UMASK:-$USER_UMASK}"
559 ;;
560 esac
561 echo ''
562fi
563
564CONFIRMED_UMASK=${NEW_UMASK:-0022}
565
566# Warn users who still have ${DESTDIR}/etc/sysconfig
567#
568if [ -e "${DESTDIR}/etc/sysconfig" ]; then
569 echo ''
570 echo " *** There is a sysconfig file on this system in ${DESTDIR}/etc/."
571 echo ''
572 echo ' Starting with FreeBSD version 2.2.2 those settings moved from'
573 echo ' /etc/sysconfig to /etc/rc.conf. If you are upgrading an older'
574 echo ' system make sure that you transfer your settings by hand from'
575 echo ' sysconfig to rc.conf and install the rc.conf file. If you'
576 echo ' have already made this transition, you should consider'
577 echo ' renaming or deleting the sysconfig file.'
578 echo ''
579 case "${AUTO_RUN}" in
580 '')
581 echo -n "Continue with the merge process? [yes] "
582 read CONT_OR_NOT
583
584 case "${CONT_OR_NOT}" in
585 [nN]*)
586 exit 0
587 ;;
588 *)
589 echo " *** Continuing"
590 echo ''
591 ;;
592 esac
593 ;;
594 *) ;;
595 esac
596fi
597
598# Use the umask/mode information to install the files
599# Create directories as needed
600#
601do_install_and_rm () {
602 install -m "${1}" "${2}" "${3}" &&
603 rm -f "${2}"
604}
605
606mm_install () {
607 local INSTALL_DIR
608 INSTALL_DIR=${1#.}
609 INSTALL_DIR=${INSTALL_DIR%/*}
610
611 case "${INSTALL_DIR}" in
612 '')
613 INSTALL_DIR=/
614 ;;
615 esac
616
617 if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then
618 DIR_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \
619 oct("$ARGV[1]"))' "${TEMPROOT}/${INSTALL_DIR}" "${CONFIRMED_UMASK}"`
620 install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}"
621 fi
622
623 FILE_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \
624 oct("$ARGV[1]"))' "${1}" "${CONFIRMED_UMASK}"`
625
626 if [ ! -x "${1}" ]; then
627 case "${1#.}" in
628 /etc/mail/aliases)
629 NEED_NEWALIASES=yes
630 ;;
631 /etc/login.conf)
632 NEED_CAP_MKDB=yes
633 ;;
634 /etc/master.passwd)
635 do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}"
636 NEED_PWD_MKDB=yes
637 DONT_INSTALL=yes
638 ;;
639 /.cshrc | /.profile)
640 case "${AUTO_INSTALL}" in
641 '')
642 case "${LINK_EXPLAINED}" in
643 '')
644 echo " *** Historically BSD derived systems have had a"
645 echo " hard link from /.cshrc and /.profile to"
646 echo " their namesakes in /root. Please indicate"
647 echo " your preference below for bringing your"
648 echo " installed files up to date."
649 echo ''
650 LINK_EXPLAINED=yes
651 ;;
652 esac
653
654 echo " Use 'd' to delete the temporary ${COMPFILE}"
655 echo " Use 'l' to delete the existing ${DESTDIR}${COMPFILE#.} and create the link"
656 echo ''
657 echo " Default is to leave the temporary file to deal with by hand"
658 echo ''
659 echo -n " How should I handle ${COMPFILE}? [Leave it to install later] "
660 read HANDLE_LINK
661 ;;
662 *) # Part of AUTO_INSTALL
663 HANDLE_LINK=l
664 ;;
665 esac
666
667 case "${HANDLE_LINK}" in
668 [dD]*)
669 rm "${COMPFILE}"
670 echo ''
671 echo " *** Deleting ${COMPFILE}"
672 ;;
673 [lL]*)
674 echo ''
675 rm -f "${DESTDIR}${COMPFILE#.}"
676 if ln "${DESTDIR}/root/${COMPFILE##*/}" "${DESTDIR}${COMPFILE#.}"; then
677 echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully"
678 rm "${COMPFILE}"
679 else
680 echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand"
681 fi
682 ;;
683 *)
684 echo " *** ${COMPFILE} will remain for your consideration"
685 ;;
686 esac
687 DONT_INSTALL=yes
688 ;;
689 esac
690
691 case "${DONT_INSTALL}" in
692 '')
693 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
694 ;;
695 *)
696 unset DONT_INSTALL
697 ;;
698 esac
699 else # File matched -x
700 case "${1#.}" in
701 /dev/MAKEDEV)
702 NEED_MAKEDEV=yes
703 ;;
704 esac
705 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
706 fi
707 return $?
708}
709
710echo ''
711echo "*** Beginning comparison"
712echo ''
713
714cd "${TEMPROOT}"
715
716if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then
717 . "${MM_PRE_COMPARE_SCRIPT}"
718fi
719
720# Using -size +0 avoids uselessly checking the empty log files created
721# by ${SOURCEDIR}/Makefile and the device entries in ./dev, but does
722# check the scripts in ./dev, as we'd like (assuming no devfs of course).
723#
724for COMPFILE in `find . -type f -size +0`; do
725
726 # First, check to see if the file exists in DESTDIR. If not, the
727 # diff_loop function knows how to handle it.
728 #
729 if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then
730 case "${AUTO_RUN}" in
731 '')
732 diff_loop
733 ;;
734 *)
735 case "${AUTO_INSTALL}" in
736 '')
737 # If this is an auto run, make it official
738 echo " *** ${COMPFILE} will remain for your consideration"
739 ;;
740 *)
741 diff_loop
742 ;;
743 esac
744 ;;
745 esac # Auto run test
746 continue
747 fi
748
749 case "${STRICT}" in
750 '' | [Nn][Oo])
751 # Compare CVS $Id's first so if the file hasn't been modified
752 # local changes will be ignored.
753 # If the files have the same $Id, delete the one in temproot so the
754 # user will have less to wade through if files are left to merge by hand.
755 #
756 CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null`
757 CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` || CVSID2=none
758
759 case "${CVSID2}" in
760 "${CVSID1}")
761 echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting"
762 rm "${COMPFILE}"
763 ;;
764 esac
765 ;;
766 esac
767
768 # If the file is still here either because the $Ids are different, the
769 # file doesn't have an $Id, or we're using STRICT mode; look at the diff.
770 #
771 if [ -f "${COMPFILE}" ]; then
772
773 # Do an absolute diff first to see if the files are actually different.
774 # If they're not different, delete the one in temproot.
775 #
776 if diff -q "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > /dev/null 2>&1; then
777 echo " *** Temp ${COMPFILE} and installed are the same, deleting"
778 rm "${COMPFILE}"
779 else
780 # Ok, the files are different, so show the user where they differ.
781 # Use user's choice of diff methods; and user's pager if they have one.
782 # Use more if not.
783 # Use unified diffs by default. Context diffs give me a headache. :)
784 #
785 case "${AUTO_RUN}" in
786 '')
787 # prompt user to install/delete/merge changes
788 diff_loop
789 ;;
790 *)
791 # If this is an auto run, make it official
792 echo " *** ${COMPFILE} will remain for your consideration"
793 ;;
794 esac # Auto run test
795 fi # Yes, the files are different
796 fi # Yes, the file still remains to be checked
797done # This is for the do way up there at the beginning of the comparison
798
799echo ''
800echo "*** Comparison complete"
801echo ''
802
803TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null`
804if [ -n "${TEST_FOR_FILES}" ]; then
805 echo "*** Files that remain for you to merge by hand:"
806 find "${TEMPROOT}" -type f -size +0
807 echo ''
808fi
809
810case "${AUTO_RUN}" in
811'')
812 echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] "
813 read DEL_TEMPROOT
814
815 case "${DEL_TEMPROOT}" in
816 [yY]*)
817 if rm -rf "${TEMPROOT}"; then
818 echo " *** ${TEMPROOT} has been deleted"
819 else
820 echo " *** Unable to delete ${TEMPROOT}"
821 fi
822 ;;
823 *)
824 echo " *** ${TEMPROOT} will remain"
825 ;;
826 esac
827 ;;
828*) ;;
829esac
830
831case "${AUTO_INSTALLED_FILES}" in
832'') ;;
833*)
834 case "${AUTO_RUN}" in
835 '')
836 (
837 echo ''
838 echo '*** You chose the automatic install option for files that did not'
839 echo ' exist on your system. The following were installed for you:'
840 echo "${AUTO_INSTALLED_FILES}"
841 ) | ${PAGER}
842 ;;
843 *)
844 echo ''
845 echo '*** You chose the automatic install option for files that did not'
846 echo ' exist on your system. The following were installed for you:'
847 echo "${AUTO_INSTALLED_FILES}"
848 ;;
849 esac
850 ;;
851esac
852
853run_it_now () {
854 case "${AUTO_RUN}" in
855 '')
856 unset YES_OR_NO
857 echo ''
858 echo -n ' Would you like to run it now? y or n [n] '
859 read YES_OR_NO
860
861 case "${YES_OR_NO}" in
862 y)
863 echo " Running ${1}"
864 echo ''
865 eval "${1}"
866 ;;
867 ''|n)
868 echo ''
869 echo " *** Cancelled"
870 echo ''
871 echo " Make sure to run ${1} yourself"
872 ;;
873 *)
874 echo ''
875 echo " *** Sorry, I do not understand your answer (${YES_OR_NO})"
876 echo ''
877 echo " Make sure to run ${1} yourself"
878 esac
879 ;;
880 *) ;;
881 esac
882}
883
884case "${NEED_MAKEDEV}" in
885'') ;;
886*)
887 echo ''
888 echo "*** You installed a new ${DESTDIR}/dev/MAKEDEV script, so make sure that you run"
889 echo " 'cd ${DESTDIR}/dev && /bin/sh MAKEDEV all' to rebuild your devices"
890 run_it_now "cd ${DESTDIR}/dev && /bin/sh MAKEDEV all"
891 ;;
892esac
893
894case "${NEED_NEWALIASES}" in
895'') ;;
896*)
897 echo ''
898 if [ -n "${DESTDIR}" ]; then
899 echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but"
900 echo " the newaliases command is limited to the directories configured"
901 echo " in sendmail.cf. Make sure to create your aliases database by"
902 echo " hand when your sendmail configuration is done."
903 else
904 echo "*** You installed a new aliases file, so make sure that you run"
905 echo " '/usr/bin/newaliases' to rebuild your aliases database"
906 run_it_now '/usr/bin/newaliases'
907 fi
908 ;;
909esac
910
911case "${NEED_CAP_MKDB}" in
912'') ;;
913*)
914 echo ''
915 echo "*** You installed a login.conf file, so make sure that you run"
916 echo " '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'"
917 echo " to rebuild your login.conf database"
918 run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf"
919 ;;
920esac
921
922case "${NEED_PWD_MKDB}" in
923'') ;;
924*)
925 echo ''
926 echo "*** You installed a new master.passwd file, so make sure that you run"
927 if [ -n "${DESTDIR}" ]; then
928 echo " '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'"
929 echo " to rebuild your password files"
930 run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd"
931 else
932 echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd'"
933 echo " to rebuild your password files"
934 run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd'
935 fi
936 ;;
937esac
938
939echo ''
940
941if [ -r "${MM_EXIT_SCRIPT}" ]; then
942 . "${MM_EXIT_SCRIPT}"
943fi
944
945case "${COMP_CONFS}" in
946'') ;;
947*)
948 . ${DESTDIR}/etc/defaults/rc.conf
949
950 (echo ''
951 echo "*** Comparing conf files: ${rc_conf_files}"
952
953 for CONF_FILE in ${rc_conf_files}; do
954 if [ -r "${DESTDIR}${CONF_FILE}" ]; then
955 echo ''
956 echo "*** From ${DESTDIR}${CONF_FILE}"
957 echo "*** From ${DESTDIR}/etc/defaults/rc.conf"
958
959 for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} |
960 cut -d '=' -f 1`; do
961 echo ''
962 grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE}
963 grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf ||
964 echo ' * No default variable with this name'
965 done
966 fi
967 done) | ${PAGER}
968 echo ''
969 ;;
970esac
971
972case "${PRE_WORLD}" in
973'') ;;
974*)
975 MAKE_CONF="${SOURCEDIR%etc}share/examples/etc/make.conf"
976
977 (echo ''
978 echo '*** Comparing make variables'
979 echo ''
980 echo "*** From ${DESTDIR}/etc/make.conf"
981 echo "*** From ${MAKE_CONF}"
982
983 for MAKE_VAR in `grep -i ^[a-z] /etc/make.conf | cut -d '=' -f 1`; do
984 echo ''
985 grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf
986 grep -w ^#${MAKE_VAR} ${MAKE_CONF} ||
987 echo ' * No example variable with this name'
988 done) | ${PAGER}
989 ;;
990esac
991
992exit 0
993
556
557# Get ready to start comparing files
558
559# Check umask if not specified on the command line,
560# and we are not doing an autorun
561#
562if [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then
563 USER_UMASK=`umask`
564 case "${USER_UMASK}" in
565 0022|022) ;;
566 *)
567 echo ''
568 echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script"
569 echo " installs all files with the same user, group and modes that"
570 echo " they are created with by ${SOURCEDIR}/Makefile, compared to"
571 echo " a umask of 022. This umask allows world read permission when"
572 echo " the file's default permissions have it."
573 echo " No world permissions can sometimes cause problems. A umask of"
574 echo " 022 will restore the default behavior, but is not mandatory."
575 echo " /etc/master.passwd is a special case. Its file permissions"
576 echo " will be 600 (rw-------) if installed."
577 echo ''
578 echo -n "What umask should I use? [${USER_UMASK}] "
579 read NEW_UMASK
580
581 NEW_UMASK="${NEW_UMASK:-$USER_UMASK}"
582 ;;
583 esac
584 echo ''
585fi
586
587CONFIRMED_UMASK=${NEW_UMASK:-0022}
588
589# Warn users who still have ${DESTDIR}/etc/sysconfig
590#
591if [ -e "${DESTDIR}/etc/sysconfig" ]; then
592 echo ''
593 echo " *** There is a sysconfig file on this system in ${DESTDIR}/etc/."
594 echo ''
595 echo ' Starting with FreeBSD version 2.2.2 those settings moved from'
596 echo ' /etc/sysconfig to /etc/rc.conf. If you are upgrading an older'
597 echo ' system make sure that you transfer your settings by hand from'
598 echo ' sysconfig to rc.conf and install the rc.conf file. If you'
599 echo ' have already made this transition, you should consider'
600 echo ' renaming or deleting the sysconfig file.'
601 echo ''
602 case "${AUTO_RUN}" in
603 '')
604 echo -n "Continue with the merge process? [yes] "
605 read CONT_OR_NOT
606
607 case "${CONT_OR_NOT}" in
608 [nN]*)
609 exit 0
610 ;;
611 *)
612 echo " *** Continuing"
613 echo ''
614 ;;
615 esac
616 ;;
617 *) ;;
618 esac
619fi
620
621# Use the umask/mode information to install the files
622# Create directories as needed
623#
624do_install_and_rm () {
625 install -m "${1}" "${2}" "${3}" &&
626 rm -f "${2}"
627}
628
629mm_install () {
630 local INSTALL_DIR
631 INSTALL_DIR=${1#.}
632 INSTALL_DIR=${INSTALL_DIR%/*}
633
634 case "${INSTALL_DIR}" in
635 '')
636 INSTALL_DIR=/
637 ;;
638 esac
639
640 if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then
641 DIR_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \
642 oct("$ARGV[1]"))' "${TEMPROOT}/${INSTALL_DIR}" "${CONFIRMED_UMASK}"`
643 install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}"
644 fi
645
646 FILE_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \
647 oct("$ARGV[1]"))' "${1}" "${CONFIRMED_UMASK}"`
648
649 if [ ! -x "${1}" ]; then
650 case "${1#.}" in
651 /etc/mail/aliases)
652 NEED_NEWALIASES=yes
653 ;;
654 /etc/login.conf)
655 NEED_CAP_MKDB=yes
656 ;;
657 /etc/master.passwd)
658 do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}"
659 NEED_PWD_MKDB=yes
660 DONT_INSTALL=yes
661 ;;
662 /.cshrc | /.profile)
663 case "${AUTO_INSTALL}" in
664 '')
665 case "${LINK_EXPLAINED}" in
666 '')
667 echo " *** Historically BSD derived systems have had a"
668 echo " hard link from /.cshrc and /.profile to"
669 echo " their namesakes in /root. Please indicate"
670 echo " your preference below for bringing your"
671 echo " installed files up to date."
672 echo ''
673 LINK_EXPLAINED=yes
674 ;;
675 esac
676
677 echo " Use 'd' to delete the temporary ${COMPFILE}"
678 echo " Use 'l' to delete the existing ${DESTDIR}${COMPFILE#.} and create the link"
679 echo ''
680 echo " Default is to leave the temporary file to deal with by hand"
681 echo ''
682 echo -n " How should I handle ${COMPFILE}? [Leave it to install later] "
683 read HANDLE_LINK
684 ;;
685 *) # Part of AUTO_INSTALL
686 HANDLE_LINK=l
687 ;;
688 esac
689
690 case "${HANDLE_LINK}" in
691 [dD]*)
692 rm "${COMPFILE}"
693 echo ''
694 echo " *** Deleting ${COMPFILE}"
695 ;;
696 [lL]*)
697 echo ''
698 rm -f "${DESTDIR}${COMPFILE#.}"
699 if ln "${DESTDIR}/root/${COMPFILE##*/}" "${DESTDIR}${COMPFILE#.}"; then
700 echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully"
701 rm "${COMPFILE}"
702 else
703 echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand"
704 fi
705 ;;
706 *)
707 echo " *** ${COMPFILE} will remain for your consideration"
708 ;;
709 esac
710 DONT_INSTALL=yes
711 ;;
712 esac
713
714 case "${DONT_INSTALL}" in
715 '')
716 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
717 ;;
718 *)
719 unset DONT_INSTALL
720 ;;
721 esac
722 else # File matched -x
723 case "${1#.}" in
724 /dev/MAKEDEV)
725 NEED_MAKEDEV=yes
726 ;;
727 esac
728 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
729 fi
730 return $?
731}
732
733echo ''
734echo "*** Beginning comparison"
735echo ''
736
737cd "${TEMPROOT}"
738
739if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then
740 . "${MM_PRE_COMPARE_SCRIPT}"
741fi
742
743# Using -size +0 avoids uselessly checking the empty log files created
744# by ${SOURCEDIR}/Makefile and the device entries in ./dev, but does
745# check the scripts in ./dev, as we'd like (assuming no devfs of course).
746#
747for COMPFILE in `find . -type f -size +0`; do
748
749 # First, check to see if the file exists in DESTDIR. If not, the
750 # diff_loop function knows how to handle it.
751 #
752 if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then
753 case "${AUTO_RUN}" in
754 '')
755 diff_loop
756 ;;
757 *)
758 case "${AUTO_INSTALL}" in
759 '')
760 # If this is an auto run, make it official
761 echo " *** ${COMPFILE} will remain for your consideration"
762 ;;
763 *)
764 diff_loop
765 ;;
766 esac
767 ;;
768 esac # Auto run test
769 continue
770 fi
771
772 case "${STRICT}" in
773 '' | [Nn][Oo])
774 # Compare CVS $Id's first so if the file hasn't been modified
775 # local changes will be ignored.
776 # If the files have the same $Id, delete the one in temproot so the
777 # user will have less to wade through if files are left to merge by hand.
778 #
779 CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null`
780 CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` || CVSID2=none
781
782 case "${CVSID2}" in
783 "${CVSID1}")
784 echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting"
785 rm "${COMPFILE}"
786 ;;
787 esac
788 ;;
789 esac
790
791 # If the file is still here either because the $Ids are different, the
792 # file doesn't have an $Id, or we're using STRICT mode; look at the diff.
793 #
794 if [ -f "${COMPFILE}" ]; then
795
796 # Do an absolute diff first to see if the files are actually different.
797 # If they're not different, delete the one in temproot.
798 #
799 if diff -q "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > /dev/null 2>&1; then
800 echo " *** Temp ${COMPFILE} and installed are the same, deleting"
801 rm "${COMPFILE}"
802 else
803 # Ok, the files are different, so show the user where they differ.
804 # Use user's choice of diff methods; and user's pager if they have one.
805 # Use more if not.
806 # Use unified diffs by default. Context diffs give me a headache. :)
807 #
808 case "${AUTO_RUN}" in
809 '')
810 # prompt user to install/delete/merge changes
811 diff_loop
812 ;;
813 *)
814 # If this is an auto run, make it official
815 echo " *** ${COMPFILE} will remain for your consideration"
816 ;;
817 esac # Auto run test
818 fi # Yes, the files are different
819 fi # Yes, the file still remains to be checked
820done # This is for the do way up there at the beginning of the comparison
821
822echo ''
823echo "*** Comparison complete"
824echo ''
825
826TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null`
827if [ -n "${TEST_FOR_FILES}" ]; then
828 echo "*** Files that remain for you to merge by hand:"
829 find "${TEMPROOT}" -type f -size +0
830 echo ''
831fi
832
833case "${AUTO_RUN}" in
834'')
835 echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] "
836 read DEL_TEMPROOT
837
838 case "${DEL_TEMPROOT}" in
839 [yY]*)
840 if rm -rf "${TEMPROOT}"; then
841 echo " *** ${TEMPROOT} has been deleted"
842 else
843 echo " *** Unable to delete ${TEMPROOT}"
844 fi
845 ;;
846 *)
847 echo " *** ${TEMPROOT} will remain"
848 ;;
849 esac
850 ;;
851*) ;;
852esac
853
854case "${AUTO_INSTALLED_FILES}" in
855'') ;;
856*)
857 case "${AUTO_RUN}" in
858 '')
859 (
860 echo ''
861 echo '*** You chose the automatic install option for files that did not'
862 echo ' exist on your system. The following were installed for you:'
863 echo "${AUTO_INSTALLED_FILES}"
864 ) | ${PAGER}
865 ;;
866 *)
867 echo ''
868 echo '*** You chose the automatic install option for files that did not'
869 echo ' exist on your system. The following were installed for you:'
870 echo "${AUTO_INSTALLED_FILES}"
871 ;;
872 esac
873 ;;
874esac
875
876run_it_now () {
877 case "${AUTO_RUN}" in
878 '')
879 unset YES_OR_NO
880 echo ''
881 echo -n ' Would you like to run it now? y or n [n] '
882 read YES_OR_NO
883
884 case "${YES_OR_NO}" in
885 y)
886 echo " Running ${1}"
887 echo ''
888 eval "${1}"
889 ;;
890 ''|n)
891 echo ''
892 echo " *** Cancelled"
893 echo ''
894 echo " Make sure to run ${1} yourself"
895 ;;
896 *)
897 echo ''
898 echo " *** Sorry, I do not understand your answer (${YES_OR_NO})"
899 echo ''
900 echo " Make sure to run ${1} yourself"
901 esac
902 ;;
903 *) ;;
904 esac
905}
906
907case "${NEED_MAKEDEV}" in
908'') ;;
909*)
910 echo ''
911 echo "*** You installed a new ${DESTDIR}/dev/MAKEDEV script, so make sure that you run"
912 echo " 'cd ${DESTDIR}/dev && /bin/sh MAKEDEV all' to rebuild your devices"
913 run_it_now "cd ${DESTDIR}/dev && /bin/sh MAKEDEV all"
914 ;;
915esac
916
917case "${NEED_NEWALIASES}" in
918'') ;;
919*)
920 echo ''
921 if [ -n "${DESTDIR}" ]; then
922 echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but"
923 echo " the newaliases command is limited to the directories configured"
924 echo " in sendmail.cf. Make sure to create your aliases database by"
925 echo " hand when your sendmail configuration is done."
926 else
927 echo "*** You installed a new aliases file, so make sure that you run"
928 echo " '/usr/bin/newaliases' to rebuild your aliases database"
929 run_it_now '/usr/bin/newaliases'
930 fi
931 ;;
932esac
933
934case "${NEED_CAP_MKDB}" in
935'') ;;
936*)
937 echo ''
938 echo "*** You installed a login.conf file, so make sure that you run"
939 echo " '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'"
940 echo " to rebuild your login.conf database"
941 run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf"
942 ;;
943esac
944
945case "${NEED_PWD_MKDB}" in
946'') ;;
947*)
948 echo ''
949 echo "*** You installed a new master.passwd file, so make sure that you run"
950 if [ -n "${DESTDIR}" ]; then
951 echo " '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'"
952 echo " to rebuild your password files"
953 run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd"
954 else
955 echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd'"
956 echo " to rebuild your password files"
957 run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd'
958 fi
959 ;;
960esac
961
962echo ''
963
964if [ -r "${MM_EXIT_SCRIPT}" ]; then
965 . "${MM_EXIT_SCRIPT}"
966fi
967
968case "${COMP_CONFS}" in
969'') ;;
970*)
971 . ${DESTDIR}/etc/defaults/rc.conf
972
973 (echo ''
974 echo "*** Comparing conf files: ${rc_conf_files}"
975
976 for CONF_FILE in ${rc_conf_files}; do
977 if [ -r "${DESTDIR}${CONF_FILE}" ]; then
978 echo ''
979 echo "*** From ${DESTDIR}${CONF_FILE}"
980 echo "*** From ${DESTDIR}/etc/defaults/rc.conf"
981
982 for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} |
983 cut -d '=' -f 1`; do
984 echo ''
985 grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE}
986 grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf ||
987 echo ' * No default variable with this name'
988 done
989 fi
990 done) | ${PAGER}
991 echo ''
992 ;;
993esac
994
995case "${PRE_WORLD}" in
996'') ;;
997*)
998 MAKE_CONF="${SOURCEDIR%etc}share/examples/etc/make.conf"
999
1000 (echo ''
1001 echo '*** Comparing make variables'
1002 echo ''
1003 echo "*** From ${DESTDIR}/etc/make.conf"
1004 echo "*** From ${MAKE_CONF}"
1005
1006 for MAKE_VAR in `grep -i ^[a-z] /etc/make.conf | cut -d '=' -f 1`; do
1007 echo ''
1008 grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf
1009 grep -w ^#${MAKE_VAR} ${MAKE_CONF} ||
1010 echo ' * No example variable with this name'
1011 done) | ${PAGER}
1012 ;;
1013esac
1014
1015exit 0
1016