[18846] | 1 | #!/bin/sh |
---|
[19288] | 2 | # $Id: import.sh,v 1.7 2003-05-03 15:21:01 ghudson Exp $ |
---|
[18846] | 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 | # |
---|
[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. |
---|
| 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. |
---|
| 20 | set -e |
---|
| 21 | |
---|
| 22 | echorun() { |
---|
| 23 | echo "" |
---|
| 24 | echo "$@" |
---|
| 25 | "$@" |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | confirmrun() { |
---|
| 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. |
---|
| 40 | while 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 |
---|
| 56 | done |
---|
| 57 | shift `expr $OPTIND - 1 || true` |
---|
| 58 | if [ $# -ne 2 ]; then |
---|
| 59 | echo "Usage: import [-d repdir] [-n pkgname] [-v pkgver] tarfile oldver" >&2 |
---|
| 60 | exit 1 |
---|
| 61 | fi |
---|
| 62 | tarfile=$1 |
---|
| 63 | oldver=$2 |
---|
| 64 | |
---|
| 65 | # We handle either gzipped or bzip2-ed tarfiles; check which we got. |
---|
| 66 | case $tarfile in |
---|
| 67 | *.tar.gz) |
---|
| 68 | dcmd='gzip -cd' |
---|
[18856] | 69 | base=`basename "$tarfile" .tar.gz` |
---|
[18846] | 70 | ;; |
---|
[18849] | 71 | *.tgz) |
---|
| 72 | dcmd='gzip -cd' |
---|
[18856] | 73 | base=`basename "$tarfile" .tgz` |
---|
[18849] | 74 | ;; |
---|
[18846] | 75 | *.tar.bz2) |
---|
| 76 | dcmd='bzip2 -cd' |
---|
[18856] | 77 | base=`basename "$tarfile" .tar.bz2` |
---|
[18846] | 78 | ;; |
---|
| 79 | *) |
---|
| 80 | echo "Unrecognized tarfile extension for $tarfile." >&2; |
---|
| 81 | exit 1 |
---|
| 82 | ;; |
---|
| 83 | esac |
---|
| 84 | |
---|
| 85 | # Compute package name, package version, tag, and repository directory. |
---|
[18856] | 86 | : ${pkgname=`expr "$base" : '\(.*\)-[0-9\.]*$'`} |
---|
| 87 | : ${pkgver=`expr "$base" : '.*-\([0-9\.]*\)$'`} |
---|
[18846] | 88 | : ${repdir=third/$pkgname} |
---|
| 89 | tag=${pkgname}-`echo "$pkgver" | sed -e 's/\./_/g'` |
---|
[18849] | 90 | if [ -n "$oldver" ]; then |
---|
| 91 | oldtag=${pkgname}-`echo "$oldver" | sed -e 's/\./_/g'` |
---|
| 92 | fi |
---|
[18846] | 93 | |
---|
[18856] | 94 | # Figure out what this tarfile unpacks into. |
---|
[19288] | 95 | tardir=`$dcmd "$tarfile" | tar -tf - | sed -e 's|^\./||' -e 's|/.*$||' | uniq` |
---|
[18856] | 96 | if [ `echo "$tardir" | wc -l` -ne 1 ]; then |
---|
| 97 | printf "%s unpacks into multiple dirs:\n%s\n" "$tarfile" "$tardir" >&2 |
---|
[18926] | 98 | exit 1 |
---|
[18856] | 99 | fi |
---|
| 100 | |
---|
[18846] | 101 | # Confirm parameters. |
---|
| 102 | echo "Package name: $pkgname" |
---|
| 103 | echo "Package version: $pkgver" |
---|
[18856] | 104 | echo "Tarfile unpacks into: $tardir" |
---|
[18846] | 105 | echo "Repository directory: $repdir" |
---|
| 106 | echo "Release tag: $tag" |
---|
| 107 | echo "Old release tag: $oldtag" |
---|
| 108 | echo "" |
---|
| 109 | printf "Please confirm:" |
---|
| 110 | read dummy |
---|
| 111 | |
---|
| 112 | # Point CVS at the Athena repository. |
---|
| 113 | CVSROOT=/afs/dev.mit.edu/source/repository |
---|
| 114 | export CVSROOT |
---|
| 115 | |
---|
| 116 | # Create temporary area and go there. |
---|
| 117 | tmpdir=/tmp/import.$$ |
---|
| 118 | mkdir "$tmpdir" |
---|
| 119 | cd "$tmpdir" |
---|
| 120 | |
---|
| 121 | # Extract the tarfile and massage it. |
---|
| 122 | $dcmd "$tarfile" | tar -xf - |
---|
[18856] | 123 | cd "$tardir" |
---|
[18846] | 124 | find . -name .cvsignore -exec rm {} \; |
---|
[18856] | 125 | find . -name CVS -type d -exec rm -rf {} \; -prune |
---|
[18846] | 126 | perl "$CVSROOT/CVSROOT/timestamps.pl" |
---|
| 127 | |
---|
| 128 | # Do the import. |
---|
| 129 | confirmrun "Import" \ |
---|
[18933] | 130 | cvs import -d -I ! -m "Import $pkgname $pkgver." "$repdir" vendor "$tag" \ |
---|
| 131 | || true # Exits with status 1 on many non-fatal errors. |
---|
[18846] | 132 | |
---|
| 133 | # If there's no old version to merge with, that's it. |
---|
| 134 | if [ -z "$oldtag" ]; then |
---|
| 135 | exit |
---|
| 136 | fi |
---|
| 137 | |
---|
| 138 | # Delete removed files on the vendor branch. |
---|
| 139 | cd "$tmpdir" |
---|
| 140 | echorun cvs co -r vendor "$repdir" |
---|
| 141 | cd "$repdir" |
---|
| 142 | echorun cvs update -j "$oldtag" -j "$tag" |
---|
| 143 | echorun cvs -q update |
---|
| 144 | confirmrun "Commit" cvs ci -m "Not present in $pkgname $pkgver." |
---|
| 145 | |
---|
| 146 | # Do the merge. |
---|
| 147 | cvs update -A |
---|
| 148 | echorun cvs update -d -P |
---|
| 149 | echorun cvs update -j "$oldtag" -j "$tag" |
---|
| 150 | echorun cvs -q update || true # Exits with status 1 if there are conflicts. |
---|
| 151 | echo "" |
---|
| 152 | echo "Resolve conflicts in $tmpdir/$repdir before confirming commit command." |
---|
| 153 | confirmrun "Commit" cvs ci -m "Merge with $pkgname $pkgver." |
---|
| 154 | |
---|
| 155 | # Clean up the temporary area. |
---|
| 156 | cd "$HOME" |
---|
| 157 | rm -rf "$tmpdir" |
---|