1 | #!/bin/sh |
---|
2 | # $Id: import.sh,v 1.10 2005-03-19 22:18:38 ghudson Exp $ |
---|
3 | |
---|
4 | # import - Interactive scripts to do Athena imports conveniently and correctly |
---|
5 | # |
---|
6 | # Usage: import [-d repdir] [-n pkgname] [-o oldver] [-v pkgver] tarfile |
---|
7 | # |
---|
8 | # tarfile may be a .tar.gz or .tar.bz2 file. It must be an absolute |
---|
9 | # path. |
---|
10 | # pkgname and pkgver are extracted from the name of tarfile by |
---|
11 | # default; this only works if the tarfile name is |
---|
12 | # pkgname-pkgver.tar.{gz,bz2} and pkgver is composed entirely of |
---|
13 | # dots and digits. Otherwise, specify them by hand. |
---|
14 | # repdir defaults to third/pkgname. |
---|
15 | # oldver is deduced from the RCS files in the existing repository dir, |
---|
16 | # if it exists. If the package version numbers are not in X.Y.Z |
---|
17 | # form, specify the old version. "none" means no old version. |
---|
18 | # You will get a chance to confirm the parameters before things start. |
---|
19 | |
---|
20 | # Bomb out on any error. |
---|
21 | set -e |
---|
22 | |
---|
23 | echorun() { |
---|
24 | echo "" |
---|
25 | echo "$@" |
---|
26 | "$@" |
---|
27 | } |
---|
28 | |
---|
29 | confirmrun() { |
---|
30 | echo "" |
---|
31 | echo "$1 command:" |
---|
32 | shift |
---|
33 | echo " " "$@" |
---|
34 | echo "" |
---|
35 | printf "Please confirm:" |
---|
36 | read dummy |
---|
37 | "$@" |
---|
38 | } |
---|
39 | |
---|
40 | # Process arguments. |
---|
41 | unset repdir pkgname oldver pkgver |
---|
42 | usage="Usage: import [-d repdir] [-n pkgname] [-o oldver] [-v pkgver] tarfile" |
---|
43 | while getopts d:n:o:v: opt; do |
---|
44 | case "$opt" in |
---|
45 | d) |
---|
46 | repdir=$OPTARG |
---|
47 | ;; |
---|
48 | n) |
---|
49 | pkgname=$OPTARG |
---|
50 | ;; |
---|
51 | o) |
---|
52 | oldver=$OPTARG |
---|
53 | ;; |
---|
54 | v) |
---|
55 | pkgver=$OPTARG |
---|
56 | ;; |
---|
57 | \?) |
---|
58 | echo "$usage" >&2 |
---|
59 | exit 1 |
---|
60 | ;; |
---|
61 | esac |
---|
62 | done |
---|
63 | shift `expr $OPTIND - 1 || true` |
---|
64 | if [ $# -ne 1 ]; then |
---|
65 | echo "$usage" >&2 |
---|
66 | exit 1 |
---|
67 | fi |
---|
68 | tarfile=$1 |
---|
69 | |
---|
70 | # We handle either gzipped or bzip2-ed tarfiles; check which we got. |
---|
71 | case $tarfile in |
---|
72 | *.tar.gz) |
---|
73 | dcmd='gzip -cd' |
---|
74 | base=`basename "$tarfile" .tar.gz` |
---|
75 | ;; |
---|
76 | *.tgz) |
---|
77 | dcmd='gzip -cd' |
---|
78 | base=`basename "$tarfile" .tgz` |
---|
79 | ;; |
---|
80 | *.tar.bz2) |
---|
81 | dcmd='bzip2 -cd' |
---|
82 | base=`basename "$tarfile" .tar.bz2` |
---|
83 | ;; |
---|
84 | *) |
---|
85 | echo "Unrecognized tarfile extension for $tarfile." >&2; |
---|
86 | exit 1 |
---|
87 | ;; |
---|
88 | esac |
---|
89 | |
---|
90 | # Point CVS at the Athena repository. |
---|
91 | CVSROOT=/afs/dev.mit.edu/source/repository |
---|
92 | export CVSROOT |
---|
93 | |
---|
94 | # Compute package name, package version, tag, and repository directory. |
---|
95 | : ${pkgname=`expr "$base" : '\(.*\)-[0-9\.]*$'`} |
---|
96 | : ${pkgver=`expr "$base" : '.*-\([0-9\.]*\)$'`} |
---|
97 | : ${repdir=third/$pkgname} |
---|
98 | |
---|
99 | # Compute the old version if not specified. |
---|
100 | if [ "${oldver+set}" != set ]; then |
---|
101 | if [ ! -d "$CVSROOT/$repdir" ]; then |
---|
102 | oldver=none |
---|
103 | else |
---|
104 | oldver=`find $CVSROOT/$repdir -name "*,v" -exec rlog -h {} \; | |
---|
105 | perl -e ' |
---|
106 | sub vercmp { |
---|
107 | @a = split(/\./, shift @_); @b = split(/\./, shift @_); |
---|
108 | while (@a and @b) { |
---|
109 | return $a[0] <=> $b[0] if $a[0] != $b[0]; |
---|
110 | shift @a; shift @b; |
---|
111 | } |
---|
112 | return @a <=> @b; |
---|
113 | } |
---|
114 | $pkg = "'"$pkgname"'"; |
---|
115 | $maxver = "0"; |
---|
116 | while (<>) { |
---|
117 | if (/^\t$pkg-([\d_]+):/) { |
---|
118 | ($ver = $1) =~ s/_/./g; |
---|
119 | $maxver = $ver if (vercmp($ver, $maxver) == 1); |
---|
120 | } |
---|
121 | } |
---|
122 | print $maxver;'` |
---|
123 | fi |
---|
124 | fi |
---|
125 | |
---|
126 | tag=${pkgname}-`echo "$pkgver" | sed -e 's/\./_/g'` |
---|
127 | if [ none != "$oldver" ]; then |
---|
128 | oldtag=${pkgname}-`echo "$oldver" | sed -e 's/\./_/g'` |
---|
129 | fi |
---|
130 | |
---|
131 | # Figure out what this tarfile unpacks into. |
---|
132 | tardir=`$dcmd "$tarfile" | tar -tf - | sed -e 's|^\./||' -e 's|/.*$||' | uniq` |
---|
133 | if [ `echo "$tardir" | wc -l` -ne 1 ]; then |
---|
134 | printf "%s unpacks into multiple dirs:\n%s\n" "$tarfile" "$tardir" >&2 |
---|
135 | exit 1 |
---|
136 | fi |
---|
137 | |
---|
138 | # Confirm parameters. |
---|
139 | echo "Package name: $pkgname" |
---|
140 | echo "Package version: $pkgver" |
---|
141 | echo "Tarfile unpacks into: $tardir" |
---|
142 | echo "Repository directory: $repdir" |
---|
143 | echo "Release tag: $tag" |
---|
144 | echo "Old release tag: $oldtag" |
---|
145 | echo "" |
---|
146 | printf "Please confirm:" |
---|
147 | read dummy |
---|
148 | |
---|
149 | # Create temporary area and go there. |
---|
150 | tmpdir=/tmp/import.$$ |
---|
151 | mkdir "$tmpdir" |
---|
152 | cd "$tmpdir" |
---|
153 | |
---|
154 | # Extract the tarfile and massage it. |
---|
155 | $dcmd "$tarfile" | tar -xf - |
---|
156 | cd "$tardir" |
---|
157 | find . -name .cvsignore -exec rm {} \; |
---|
158 | find . -name CVS -type d -exec rm -rf {} \; -prune |
---|
159 | perl "$CVSROOT/CVSROOT/timestamps.pl" |
---|
160 | |
---|
161 | # Do the import. |
---|
162 | confirmrun "Import" \ |
---|
163 | cvs import -d -I ! -m "Import $pkgname $pkgver." "$repdir" vendor "$tag" \ |
---|
164 | || true # Exits with status 1 on many non-fatal errors. |
---|
165 | |
---|
166 | # If there's no old version to merge with, that's it. |
---|
167 | if [ -z "$oldtag" ]; then |
---|
168 | cd "$HOME" |
---|
169 | rm -rf "$tmpdir" |
---|
170 | exit |
---|
171 | fi |
---|
172 | |
---|
173 | # Delete removed files on the vendor branch. |
---|
174 | cd "$tmpdir" |
---|
175 | echorun cvs co -r vendor "$repdir" |
---|
176 | cd "$repdir" |
---|
177 | echorun cvs update -j "$oldtag" -j "$tag" |
---|
178 | echorun cvs -q update |
---|
179 | confirmrun "Commit" cvs ci -m "Not present in $pkgname $pkgver." |
---|
180 | |
---|
181 | # Do the merge. |
---|
182 | cvs update -A |
---|
183 | echorun cvs update -d -P |
---|
184 | echorun cvs update -j "$oldtag" -j "$tag" |
---|
185 | echorun cvs -q update || true # Exits with status 1 if there are conflicts. |
---|
186 | echo "" |
---|
187 | echo "Resolve conflicts in $tmpdir/$repdir before confirming commit command." |
---|
188 | confirmrun "Commit" cvs ci -m "Merge with $pkgname $pkgver." |
---|
189 | |
---|
190 | # Clean up the temporary area. |
---|
191 | cd "$HOME" |
---|
192 | rm -rf "$tmpdir" |
---|