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 to adjust CVS/Root afterwards, in each working directory
8 cvs-repomove automatically update **/CVS/Root
12 # We do things in the following order:
14 # 0. Check things @/..moving-to none/..moved-to
15 # 1. Rename src repo to prevent commits etc. ..moving-to none/..moved-to
16 # 2. Make temporary copy at destination ..moving-to ..tmp
17 # 3. Install temporary copy at destination ..moving-to @
18 # 4. Move aside src repo ..moved-to @
20 fail () { echo >&2 "error: $1"; exit 8; }
21 bad_usage () { echo >&2 "bad usage: $1"; print_usage >&2; exit 12; }
25 while [ $# -gt 0 ]; do
28 --help) print_usage; exit 0 ;;
30 -*) bad_usage "unknown option $1" ;;
41 "moving a module with \`..' in its name is not supported" ;;
43 "moving a subdirectory is not supported" ;;
45 "moving a module whose name starts with \`-' is not supported" ;;
49 check_remote_host () {
51 /*|.*|-*) fail "bad hostname $dsthost" ;;
55 check_remote_path () {
57 *[^0-9a-zA-Z/._+,-]*) fail \
58 "remote pathname may not contain metacharacters, sorry" ;;
64 check_remote_host "$dsthost"
65 check_remote_path "$dstrepo/$module"
69 *) bad_usage "destination repo path must be absolute" ;;
72 printf "moving module %s from %s to %s:%s\n" \
73 "$module" "$srcrepo" "$dsthost" "$dstrepo"
75 mn "checking existing repository"
76 ls -d -- "$srcrepo/CVSROOT" >/dev/null
78 dstrepotrans="$(printf "%s" "$dstrepo" | tr / :)"
79 movingto="moving-to-$dsthost:$dstrepotrans"
80 if test -d "$srcrepo/$module..$movingto"; then
81 echo " resuming previous attempt at a move"
83 if test -d "$srcrepo/$module"; then
84 fail "but $srcrepo/$module exists too"
88 ls -d -- "$srcrepo/$module" >/dev/null
92 previously="$(ls -d -- "$srcrepo/$module..moved-to-"* 2>/dev/null)"
94 if [ "x$previously" != x ]; then
95 echo " btw, module was once before moved away from here"
97 "${previously/..moved-to-/..previously-$(date +%s)-moved-to-}"
100 mn "checking dst repository"
101 "$CVS_RSH" "$dsthost" bash -ec "'
103 ls -d CVSROOT >/dev/null
104 if test -d $dstrepo/$module; then
105 echo >&2 module already exists in destination repo
108 for f in $module..*; do
110 *..moved-to-*) echo \" btw, module was previously at destn repo\" ;;
112 *..tmp-*) echo \" nb: possibly-stale temp/partial copy \$f\" ;;
114 *) echo >&2 \"error: found unexpected subdir \$f\"; exit 8;;
120 mv -- "$srcrepo/$module" "$srcrepo/$module..$movingto"
123 mn "transferring repo data"
124 tmpid="tmp-$(uname -n).$(date +%s)"
125 tar -c -C "$srcrepo/$module..$movingto" -f - . | \
126 "$CVS_RSH" "$dsthost" bash -ec "'
128 mkdir $module..$tmpid
130 tar --no-same-owner -xf -
132 test "${PIPESTATUS[*]}" = "0 0"
134 mn "confirming move at destination repo"
135 "$CVS_RSH" "$dsthost" bash -ec "'
137 mv $module..$tmpid $module
140 mn "confirming move at local repo"
141 mv -- "$srcrepo/$module..$movingto" \
142 "$srcrepo/$module..moved-to-$dsthost:$dstrepotrans"
143 echo "module moved successfully"
146 compute_fqdn_data () {
147 fqdn_data="$(adnshost -s - "$1" 2>/dev/null || true)"
151 module="$(cat CVS/Repository)"
152 oldroot="$(cat CVS/Root)"
155 printf "checking/updating repo for %s\n" "$module"
156 compute_fqdn_data "$(uname -n)"
157 our_fqdn_data="$fqdn_data"
160 mn "chasing geese at $goose"
163 remotehost="${goose%%:*}"
165 check_remote_host "$remotehost"
166 check_remote_path "$remotepath/$module"
168 compute_fqdn_data "$remotehost"
169 if [ "x$fqdn_data" = "x$our_fqdn_data" -a \
170 "x$fqdn_data" != x ]; then
176 fail "unknown remote repository string $goose"
183 fail "unknown repository string $goose"
188 if test -d $module; then echo good; exit 0; fi
189 if ls -d $module..moved-to-* 2>/dev/null; then exit 0; fi
193 new_goose_info="$("$CVS_RSH" "$remotehost" \
194 bash -ec "'$check'")"
196 new_goose_info="$( bash -ec "$check")"
198 case "$new_goose_info" in
203 echo >&2 "trail went cold at $goose"
207 goose="$(printf "%s" \
208 "${new_goose_info#*..moved-to-}" | \
209 tr : / | sed -e 's,/,:,')"
213 if [ "x$goose" = "x$oldroot" ]; then
214 echo 'repo has not moved - nothing to do'
217 mn "found new repo, adjusting working tree"
218 cvs-adjustroot "$oldroot" "$goose"
219 echo 'working tree adjustment completed'
223 [ "$#" = 4 ] || bad_usage "--move needs hostname and path"
224 srcrepo="$1"; module="$2"; dsthost="$3"; dstrepo="$4"
227 [ "$#" = 0 ] || bad_usage "without --move, give no arguments"