| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
set -e |
| 4 |
|
| 5 |
usage () { echo >&2 'usage: cvs-adjustroot OLD NEW'; exit 1; } |
| 6 |
|
| 7 |
case "$#.$1" in |
| 8 |
4.--reinvoke) reinvoke=true; shift ;; |
| 9 |
*.-*) usage ;; |
| 10 |
2.*) reinvoke=false ;; |
| 11 |
1.*) usage ;; |
| 12 |
0.*) usage ;; |
| 13 |
*) usage ;; |
| 14 |
esac |
| 15 |
|
| 16 |
# Copyright 2004 Ian Jackson <[email protected]> |
| 17 |
# |
| 18 |
# This script and its documentation (if any) are free software; you |
| 19 |
# can redistribute it and/or modify them under the terms of the GNU |
| 20 |
# General Public License as published by the Free Software Foundation; |
| 21 |
# either version 3, or (at your option) any later version. |
| 22 |
# |
| 23 |
# chiark-named-conf and its manpage are distributed in the hope that |
| 24 |
# it will be useful, but WITHOUT ANY WARRANTY; without even the |
| 25 |
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 26 |
# PURPOSE. See the GNU General Public License for more details. |
| 27 |
# |
| 28 |
# You should have received a copy of the GNU General Public License along |
| 29 |
# with this program; if not, consult the Free Software Foundation's |
| 30 |
# website at www.fsf.org, or the GNU Project website at www.gnu.org. |
| 31 |
|
| 32 |
|
| 33 |
old="$1"; shift |
| 34 |
new="$1"; shift |
| 35 |
|
| 36 |
if $reinvoke; then |
| 37 |
filename="$1"; |
| 38 |
if cmp -- "$filename" <(printf "%s\n" "$new"); then exit 0; fi |
| 39 |
cmp -- "$filename" <(printf "%s\n" "$old") |
| 40 |
printf "%s\n" "$new" >"$filename".new |
| 41 |
mv -f -- "$filename".new "$filename" |
| 42 |
exit 0 |
| 43 |
fi |
| 44 |
|
| 45 |
# GNU find provides + exec variants which set exit status and pass |
| 46 |
# multiple arguments, or \; variants which pass one argument but do |
| 47 |
# not set exit status. So use a separate -exec false + to arrange for |
| 48 |
# nonzero exit status when appropriate. |
| 49 |
|
| 50 |
find -path '*/CVS/Root' \ |
| 51 |
\( -exec "$0" --reinvoke "$old" "$new" '{}' ';' \ |
| 52 |
-o -exec false '{}' + \ |
| 53 |
\) |