3 print_usage () { cat <<'END'
5 to move repository directory, cd to anywhere and
6 cvs-repomove --move local-repo module hostname remote-repo
7 cvs-repomove --move src-hostname src-repo module dst-hostname dst-repo
8 to adjust CVS/Root afterwards, in each working directory
9 cvs-repomove automatically update **/CVS/Root
13 # We do things in the following order:
15 # 0. Check things @/..moving-to none/..moved-to
16 # 1. Rename src repo to prevent commits etc. ..moving-to none/..moved-to
17 # 2. Make temporary copy at destination ..moving-to ..tmp
18 # 3. Install temporary copy at destination ..moving-to @
19 # 4. Move aside src repo ..moved-to @
21 fail () { echo >&2 "error: $1"; exit 8; }
22 bad_usage () { echo >&2 "bad usage: $1"; print_usage >&2; exit 12; }
26 while [ $# -gt 0 ]; do
29 --help) print_usage; exit 0 ;;
31 -*) bad_usage "unknown option $1" ;;
42 "moving a module with \`..' in its name is not supported" ;;
44 "moving a subdirectory is not supported" ;;
46 "moving a module whose name starts with \`-' is not supported" ;;
52 /*|.*|-*) fail "bad hostname $dsthost" ;;
56 check_remote_path () {
58 *[^0-9a-zA-Z/._+,-]*) fail \
59 "pathname may not contain metacharacters, sorry" ;;
65 check_hostname "$srchost"
66 check_hostname "$dsthost"
67 check_remote_path "$srcrepo/$module"
68 check_remote_path "$dstrepo/$module"
72 *) bad_usage "destination repo path must be absolute" ;;
75 printf "moving module %s from %s:%s to %s:%s\n" \
76 "$module" "$srchost" "$srcrepo" "$dsthost" "$dstrepo"
78 mn "checking existing repository"
79 "$CVS_RSH" "$srchost" bash -ec "'
80 ls -d -- $srcrepo/CVSROOT >/dev/null
83 dstrepotrans="$(printf "%s" "$dstrepo" | tr / :)"
84 movingto="moving-to-$dsthost:$dstrepotrans"
85 resume="$("$CVS_RSH" "$srchost" bash -ec "'
86 if test -d $srcrepo/$module..$movingto; then
87 echo \" resuming previous attempt at a move\"
89 if test -d $srcrepo/$module; then
90 echo >&2 \"but $srcrepo/$module exists too\"
95 ls -d -- $srcrepo/$module >/dev/null
98 previously=\"$(ls -d -- $srcrepo/$module..moved-to-* 2>/dev/null)\"
100 if [ \"x$previously\" != x ]; then
101 echo \" btw, module was once before moved away from here\"
102 mv -- \"$previously\" \
103 \"${previously/..moved-to-/..previously-\$(date +%s)-moved-to-}\"
108 mn "checking dst repository"
109 "$CVS_RSH" "$dsthost" bash -ec "'
111 ls -d CVSROOT >/dev/null
112 if test -d $dstrepo/$module; then
113 echo >&2 module already exists in destination repo
116 for f in $module..*; do
118 *..moved-to-*) echo \" btw, module was previously at destn repo\" ;;
120 *..tmp-*) echo \" nb: possibly-stale temp/partial copy \$f\" ;;
122 *) echo >&2 \"error: found unexpected subdir \$f\"; exit 8;;
128 "$CVS_RSH" "$srchost" bash -ec "'
129 mv -- $srcrepo/$module $srcrepo/$module..$movingto
133 mn "transferring repo data"
134 tmpid="tmp-$(uname -n).$(date +%s)"
135 "$CVS_RSH" "$srchost" bash -ec "'
136 tar -c -C $srcrepo/$module..$movingto -f - .
137 '" | "$CVS_RSH" "$dsthost" bash -ec "'
139 mkdir $module..$tmpid
141 tar --no-same-owner -xf -
143 test "${PIPESTATUS[*]}" = "0 0"
145 mn "confirming move at destination repo"
146 "$CVS_RSH" "$dsthost" bash -ec "'
148 mv $module..$tmpid $module
151 mn "confirming move at source repo"
152 "$CVS_RSH" "$srchost" bash -ec "'
153 mv -- $srcrepo/$module..$movingto \
154 $srcrepo/$module..moved-to-$dsthost:$dstrepotrans
156 echo "module moved successfully"
159 compute_fqdn_data () {
160 fqdn_data="$(adnshost -s - "$1" 2>/dev/null || true)"
164 module="$(cat CVS/Repository)"
165 oldroot="$(cat CVS/Root)"
168 printf "checking/updating repo for %s\n" "$module"
169 compute_fqdn_data "$(uname -n)"
170 our_fqdn_data="$fqdn_data"
173 mn "chasing geese at $goose"
176 remotehost="${goose%%:*}"
178 check_hostname "$remotehost"
179 check_remote_path "$remotepath/$module"
181 compute_fqdn_data "$remotehost"
182 if [ "x$fqdn_data" = "x$our_fqdn_data" -a \
183 "x$fqdn_data" != x ]; then
189 fail "unknown remote repository string $goose"
196 fail "unknown repository string $goose"
201 if test -d $module; then echo good; exit 0; fi
202 if ls -d $module..moved-to-* 2>/dev/null; then exit 0; fi
206 new_goose_info="$("$CVS_RSH" "$remotehost" \
207 bash -ec "'$check'")"
209 new_goose_info="$( bash -ec "$check")"
211 case "$new_goose_info" in
216 echo >&2 "trail went cold at $goose"
220 goose="$(printf "%s" \
221 "${new_goose_info#*..moved-to-}" | \
222 tr : / | sed -e 's,/,:,')"
226 if [ "x$goose" = "x$oldroot" ]; then
227 echo 'repo has not moved - nothing to do'
230 mn "found new repo, adjusting working tree"
231 cvs-adjustroot "$oldroot" "$goose"
232 echo 'working tree adjustment completed'
237 srchost="$(hostname -f)"; srcrepo="$1"
239 dsthost="$3"; dstrepo="$4"
240 elif [ $# = 5 ]; then
241 srchost="$1"; srcrepo="$2"
243 dsthost="$4"; dstrepo="$5"
245 bad_usage "--move needs hostname(s) and paths"
249 [ "$#" = 0 ] || bad_usage "without --move, give no arguments"