source: trunk/CVSROOT/import.sh @ 21611

Revision 21611, 4.6 KB checked in by ghudson, 19 years ago (diff)
Use find -exec instead of find | xargs when looking for the most recent release tag, to accomodate filenames containing spaces.
  • Property svn:executable set to *
RevLine 
[18846]1#!/bin/sh
[21611]2# $Id: import.sh,v 1.10 2005-03-19 22:18:38 ghudson Exp $
[18846]3
4# import - Interactive scripts to do Athena imports conveniently and correctly
5#
[20855]6# Usage: import [-d repdir] [-n pkgname] [-o oldver] [-v pkgver] tarfile
[18846]7#
[18847]8# tarfile may be a .tar.gz or .tar.bz2 file.  It must be an absolute
9#  path.
[18846]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.
[20855]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.
[18846]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.
[20855]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
[18846]44  case "$opt" in
45  d)
46    repdir=$OPTARG
47    ;;
48  n)
49    pkgname=$OPTARG
50    ;;
[20855]51  o)
52    oldver=$OPTARG
53    ;;
[18846]54  v)
55    pkgver=$OPTARG
56    ;;
57  \?)
[20855]58    echo "$usage" >&2
[18846]59    exit 1
60    ;;
61  esac
62done
63shift `expr $OPTIND - 1 || true`
[20855]64if [ $# -ne 1 ]; then
65  echo "$usage" >&2
[18846]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'
[18856]74  base=`basename "$tarfile" .tar.gz`
[18846]75  ;;
[18849]76*.tgz)
77  dcmd='gzip -cd'
[18856]78  base=`basename "$tarfile" .tgz`
[18849]79  ;;
[18846]80*.tar.bz2)
81  dcmd='bzip2 -cd'
[18856]82  base=`basename "$tarfile" .tar.bz2`
[18846]83  ;;
84*)
85  echo "Unrecognized tarfile extension for $tarfile." >&2;
86  exit 1
87  ;;
88esac
89
[20855]90# Point CVS at the Athena repository.
91CVSROOT=/afs/dev.mit.edu/source/repository
92export CVSROOT
93
[18846]94# Compute package name, package version, tag, and repository directory.
[18856]95: ${pkgname=`expr "$base" : '\(.*\)-[0-9\.]*$'`}
96: ${pkgver=`expr "$base" : '.*-\([0-9\.]*\)$'`}
[18846]97: ${repdir=third/$pkgname}
[20855]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
[21611]104    oldver=`find $CVSROOT/$repdir -name "*,v" -exec rlog -h {} \; |
[20855]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
[18846]126tag=${pkgname}-`echo "$pkgver" | sed -e 's/\./_/g'`
[20855]127if [ none != "$oldver" ]; then
[18849]128  oldtag=${pkgname}-`echo "$oldver" | sed -e 's/\./_/g'`
129fi
[18846]130
[18856]131# Figure out what this tarfile unpacks into.
[19288]132tardir=`$dcmd "$tarfile" | tar -tf - | sed -e 's|^\./||' -e 's|/.*$||' | uniq`
[18856]133if [ `echo "$tardir" | wc -l` -ne 1 ]; then
134  printf "%s unpacks into multiple dirs:\n%s\n" "$tarfile" "$tardir" >&2
[18926]135  exit 1
[18856]136fi
137
[18846]138# Confirm parameters.
139echo "Package name:         $pkgname"
140echo "Package version:      $pkgver"
[18856]141echo "Tarfile unpacks into: $tardir"
[18846]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 -
[18856]156cd "$tardir"
[18846]157find . -name .cvsignore -exec rm {} \;
[18856]158find . -name CVS -type d -exec rm -rf {} \; -prune
[18846]159perl "$CVSROOT/CVSROOT/timestamps.pl"
160
161# Do the import.
162confirmrun "Import" \
[18933]163  cvs import -d -I ! -m "Import $pkgname $pkgver." "$repdir" vendor "$tag" \
164  || true   # Exits with status 1 on many non-fatal errors.
[18846]165
166# If there's no old version to merge with, that's it.
167if [ -z "$oldtag" ]; then
[21141]168  cd "$HOME"
169  rm -rf "$tmpdir"
[18846]170  exit
171fi
172
173# Delete removed files on the vendor branch.
174cd "$tmpdir"
175echorun cvs co -r vendor "$repdir"
176cd "$repdir"
177echorun cvs update -j "$oldtag" -j "$tag"
178echorun cvs -q update
179confirmrun "Commit" cvs ci -m "Not present in $pkgname $pkgver."
180
181# Do the merge.
182cvs update -A
183echorun cvs update -d -P
184echorun cvs update -j "$oldtag" -j "$tag"
185echorun cvs -q update || true   # Exits with status 1 if there are conflicts.
186echo ""
187echo "Resolve conflicts in $tmpdir/$repdir before confirming commit command."
188confirmrun "Commit" cvs ci -m "Merge with $pkgname $pkgver."
189
190# Clean up the temporary area.
191cd "$HOME"
192rm -rf "$tmpdir"
Note: See TracBrowser for help on using the repository browser.