source: trunk/CVSROOT/import.sh @ 19288

Revision 19288, 3.8 KB checked in by ghudson, 21 years ago (diff)
Cope if the tarfile unpacks into ./foo.
  • Property svn:executable set to *
Line 
1#!/bin/sh
2# $Id: import.sh,v 1.7 2003-05-03 15:21:01 ghudson Exp $
3
4# import - Interactive scripts to do Athena imports conveniently and correctly
5#
6# Usage: import [-d repdir] [-n pkgname] [-v pkgver] tarfile oldver
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# If this is the first import, specify an empty oldver ("" on the
16#  command line).
17# You will get a chance to confirm the parameters before things start.
18
19# Bomb out on any error.
20set -e
21
22echorun() {
23  echo ""
24  echo "$@"
25  "$@"
26}
27
28confirmrun() {
29  echo ""
30  echo "$1 command:"
31  shift
32  echo " " "$@"
33  echo ""
34  printf "Please confirm:"
35  read dummy
36  "$@"
37}
38
39# Process arguments.
40while getopts d:n:v: opt; do
41  case "$opt" in
42  d)
43    repdir=$OPTARG
44    ;;
45  n)
46    pkgname=$OPTARG
47    ;;
48  v)
49    pkgver=$OPTARG
50    ;;
51  \?)
52    echo "$usage"
53    exit 1
54    ;;
55  esac
56done
57shift `expr $OPTIND - 1 || true`
58if [ $# -ne 2 ]; then
59  echo "Usage: import [-d repdir] [-n pkgname] [-v pkgver] tarfile oldver" >&2
60  exit 1
61fi
62tarfile=$1
63oldver=$2
64
65# We handle either gzipped or bzip2-ed tarfiles; check which we got.
66case $tarfile in
67*.tar.gz)
68  dcmd='gzip -cd'
69  base=`basename "$tarfile" .tar.gz`
70  ;;
71*.tgz)
72  dcmd='gzip -cd'
73  base=`basename "$tarfile" .tgz`
74  ;;
75*.tar.bz2)
76  dcmd='bzip2 -cd'
77  base=`basename "$tarfile" .tar.bz2`
78  ;;
79*)
80  echo "Unrecognized tarfile extension for $tarfile." >&2;
81  exit 1
82  ;;
83esac
84
85# Compute package name, package version, tag, and repository directory.
86: ${pkgname=`expr "$base" : '\(.*\)-[0-9\.]*$'`}
87: ${pkgver=`expr "$base" : '.*-\([0-9\.]*\)$'`}
88: ${repdir=third/$pkgname}
89tag=${pkgname}-`echo "$pkgver" | sed -e 's/\./_/g'`
90if [ -n "$oldver" ]; then
91  oldtag=${pkgname}-`echo "$oldver" | sed -e 's/\./_/g'`
92fi
93
94# Figure out what this tarfile unpacks into.
95tardir=`$dcmd "$tarfile" | tar -tf - | sed -e 's|^\./||' -e 's|/.*$||' | uniq`
96if [ `echo "$tardir" | wc -l` -ne 1 ]; then
97  printf "%s unpacks into multiple dirs:\n%s\n" "$tarfile" "$tardir" >&2
98  exit 1
99fi
100
101# Confirm parameters.
102echo "Package name:         $pkgname"
103echo "Package version:      $pkgver"
104echo "Tarfile unpacks into: $tardir"
105echo "Repository directory: $repdir"
106echo "Release tag:          $tag"
107echo "Old release tag:      $oldtag"
108echo ""
109printf "Please confirm:"
110read dummy
111
112# Point CVS at the Athena repository.
113CVSROOT=/afs/dev.mit.edu/source/repository
114export CVSROOT
115
116# Create temporary area and go there.
117tmpdir=/tmp/import.$$
118mkdir "$tmpdir"
119cd "$tmpdir"
120
121# Extract the tarfile and massage it.
122$dcmd "$tarfile" | tar -xf -
123cd "$tardir"
124find . -name .cvsignore -exec rm {} \;
125find . -name CVS -type d -exec rm -rf {} \; -prune
126perl "$CVSROOT/CVSROOT/timestamps.pl"
127
128# Do the import.
129confirmrun "Import" \
130  cvs import -d -I ! -m "Import $pkgname $pkgver." "$repdir" vendor "$tag" \
131  || true   # Exits with status 1 on many non-fatal errors.
132
133# If there's no old version to merge with, that's it.
134if [ -z "$oldtag" ]; then
135  exit
136fi
137
138# Delete removed files on the vendor branch.
139cd "$tmpdir"
140echorun cvs co -r vendor "$repdir"
141cd "$repdir"
142echorun cvs update -j "$oldtag" -j "$tag"
143echorun cvs -q update
144confirmrun "Commit" cvs ci -m "Not present in $pkgname $pkgver."
145
146# Do the merge.
147cvs update -A
148echorun cvs update -d -P
149echorun cvs update -j "$oldtag" -j "$tag"
150echorun cvs -q update || true   # Exits with status 1 if there are conflicts.
151echo ""
152echo "Resolve conflicts in $tmpdir/$repdir before confirming commit command."
153confirmrun "Commit" cvs ci -m "Merge with $pkgname $pkgver."
154
155# Clean up the temporary area.
156cd "$HOME"
157rm -rf "$tmpdir"
Note: See TracBrowser for help on using the repository browser.