source: trunk/CVSROOT/import.sh @ 20855

Revision 20855, 4.6 KB checked in by ghudson, 20 years ago (diff)
Add automatic detection of the old version number based on the RCS files in the existing repository directory.
  • Property svn:executable set to *
Line 
1#!/bin/sh
2# $Id: import.sh,v 1.8 2004-09-25 05:36:17 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.
21set -e
22
23echorun() {
24  echo ""
25  echo "$@"
26  "$@"
27}
28
29confirmrun() {
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.
41unset repdir pkgname oldver pkgver
42usage="Usage: import [-d repdir] [-n pkgname] [-o oldver] [-v pkgver] tarfile"
43while 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
62done
63shift `expr $OPTIND - 1 || true`
64if [ $# -ne 1 ]; then
65  echo "$usage" >&2
66  exit 1
67fi
68tarfile=$1
69
70# We handle either gzipped or bzip2-ed tarfiles; check which we got.
71case $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  ;;
88esac
89
90# Point CVS at the Athena repository.
91CVSROOT=/afs/dev.mit.edu/source/repository
92export 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.
100if [ "${oldver+set}" != set ]; then
101  if [ ! -d "$CVSROOT/$repdir" ]; then
102    oldver=none
103  else
104    oldver=`find $CVSROOT/$repdir -name "*,v" -print | xargs 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
124fi
125
126tag=${pkgname}-`echo "$pkgver" | sed -e 's/\./_/g'`
127if [ none != "$oldver" ]; then
128  oldtag=${pkgname}-`echo "$oldver" | sed -e 's/\./_/g'`
129fi
130
131# Figure out what this tarfile unpacks into.
132tardir=`$dcmd "$tarfile" | tar -tf - | sed -e 's|^\./||' -e 's|/.*$||' | uniq`
133if [ `echo "$tardir" | wc -l` -ne 1 ]; then
134  printf "%s unpacks into multiple dirs:\n%s\n" "$tarfile" "$tardir" >&2
135  exit 1
136fi
137
138# Confirm parameters.
139echo "Package name:         $pkgname"
140echo "Package version:      $pkgver"
141echo "Tarfile unpacks into: $tardir"
142echo "Repository directory: $repdir"
143echo "Release tag:          $tag"
144echo "Old release tag:      $oldtag"
145echo ""
146printf "Please confirm:"
147read dummy
148
149# Create temporary area and go there.
150tmpdir=/tmp/import.$$
151mkdir "$tmpdir"
152cd "$tmpdir"
153
154# Extract the tarfile and massage it.
155$dcmd "$tarfile" | tar -xf -
156cd "$tardir"
157find . -name .cvsignore -exec rm {} \;
158find . -name CVS -type d -exec rm -rf {} \; -prune
159perl "$CVSROOT/CVSROOT/timestamps.pl"
160
161# Do the import.
162confirmrun "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.
167if [ -z "$oldtag" ]; then
168  exit
169fi
170
171# Delete removed files on the vendor branch.
172cd "$tmpdir"
173echorun cvs co -r vendor "$repdir"
174cd "$repdir"
175echorun cvs update -j "$oldtag" -j "$tag"
176echorun cvs -q update
177confirmrun "Commit" cvs ci -m "Not present in $pkgname $pkgver."
178
179# Do the merge.
180cvs update -A
181echorun cvs update -d -P
182echorun cvs update -j "$oldtag" -j "$tag"
183echorun cvs -q update || true   # Exits with status 1 if there are conflicts.
184echo ""
185echo "Resolve conflicts in $tmpdir/$repdir before confirming commit command."
186confirmrun "Commit" cvs ci -m "Merge with $pkgname $pkgver."
187
188# Clean up the temporary area.
189cd "$HOME"
190rm -rf "$tmpdir"
Note: See TracBrowser for help on using the repository browser.