source: rtems-testing/release-helpers/cut_release @ 85c521d

4.11
Last change on this file since 85c521d was 85c521d, checked in by Joel Sherrill <joel.sherrill@…>, on May 2, 2014 at 2:14:18 PM

rtems-testing: Use eval bash instead of full path

  • Property mode set to 100755
File size: 9.8 KB
Line 
1#! /bin/sh
2#
3#  Cut a snapshot of a module in CVS
4#
5#  Example Invocations:
6#
7#  TBD
8#
9
10usage()
11{
12  echo "$0 [options]"
13  echo "  options:"
14  echo "    -c release      -- current release         (required)"
15  echo "    -p release      -- previous release        (NA == none)"
16  echo "    -m module       -- CVS module name         (required)"
17  echo "    -r release_name -- base of release image name"
18  echo "    -d directory    -- release directory       (required)"
19  echo "    -z              -- use gzip not bzip2 for archives"
20  echo "    -V              -- generate file Version report"
21  echo "    -v              -- be verbose"
22  echo
23  echo "Must be run from top level directory of checked out source."
24  echo
25  exit 1
26}
27
28fatal()
29{
30  echo $*
31  usage
32}
33
34previous=NA
35current=NOT_SET
36reldir_base=NOT_SET
37module_name=NOT_SET
38release_name=NOT_SET
39verbose=no
40zipper=bzip2
41unzipper=bunzip2
42zext=bz2
43do_version_report=no
44
45while test $# -ge 1; do
46  case $1 in
47    -c) shift ; current=$1 ;;
48    -p) shift ; previous=$1 ;;
49    -m) shift ; module_name=$1 ;;
50    -r) shift ; release_name=$1 ;;
51    -d) shift ; reldir_base=$1 ;;
52    -z) zipper=gzip ; unzipper=gunzip ; zext=gz ;;
53    -V) do_version_report=yes ;;
54    -v) verbose=yes ;;
55    *)
56      fatal "invalid option $1"
57      ;;
58  esac
59  shift
60done
61
62if test ${module_name} = NOT_SET ; then
63  grep "/" CVS/Repository >/dev/null
64  if test $? -eq 0 ; then
65    fatal "Module name not specified."
66  fi
67  module_name=`cat CVS/Repository`
68fi
69
70if test ${reldir_base} = NOT_SET ; then
71  reldir_base=/home/releases/${module_name}
72  if test ! -d ${reldir_base} ; then
73    fatal "Release directory not specified and ${reldir_base} does not exist."
74  fi
75  module_name=`cat CVS/Repository`
76else
77  if test ! -d ${reldir_base} ; then
78    fatal "Release directory (${reldir_base}) does not exist."
79  fi
80fi
81
82if test ${verbose} = yes ; then
83  echo "==========================================="
84  echo "Current Release         :" ${current}
85  echo "Previous Release        :" ${previous}
86  echo "Module Name             :" ${module_name}
87  echo "Release Base Name       :" ${release_name}
88  echo "Release Directory       :" ${reldir_base}
89  echo "Compression             :" ${zipper} ${unzipper} ${zext}
90  echo "Generate Version Report :" ${do_version_report}
91  echo "==========================================="
92  exit 0
93fi
94
95# Now check the arguments
96
97if test ${current} = NOT_SET ; then
98  fatal "Current release not specified."
99fi
100
101if test ${release_name} = NOT_SET ; then
102  echo "Using module_name (${module_name}) as release name.".
103  release_name=${module_name}
104fi
105
106##### setup some directory assumptions
107reldir_prev=${reldir_base}/${previous}
108reldir_curr=${reldir_base}/${current}
109export_dir=${reldir_base}/export
110base=`pwd`
111cvs_root=`cat ${base}/CVS/Root`
112cvs_repository=`cat ${base}/CVS/Repository`
113cvs_module=`basename ${cvs_repository}`
114
115# Make sure we are at the top of a checked out tree
116if [ "${cvs_module}"X != "${module_name}"X ] ; then
117   echo You do not appear to be in the top level of a checked out ${module_name} tree
118   exit 1
119fi
120
121#  Test if we generate diffs and the old release is there.
122if [ ${previous} != "NA" ] ; then
123  if [ ! -d ${reldir_prev} ] ; then
124    echo Previous release ${previous} not found
125    exit 1
126  fi
127fi
128
129# Check that the export directory exists
130test -d ${export_dir} || mkdir ${export_dir}
131
132#  turn the version string into a valid cvs tag
133mk_version_tag()
134{
135  echo ${release_name}-${1} | tr "." "-"
136}
137
138current_tag=`mk_version_tag ${current}`
139previous_tag=`mk_version_tag ${previous}`
140
141if [ ${previous} != "NA" ] ; then
142  echo Using $previous_tag as the tag for the previous version
143else
144  echo No previous version
145fi
146echo Using $current_tag as the tag for the current version
147
148# Changing the version string
149
150cd ${base}
151Pname=${module}
152if test -x ${base}/release_support ; then
153  Pname=`${base}/release_support name`
154  test $? -ne 0 && (echo "release support (name) script failed." ; exit 1)
155fi
156
157# make sure certain special files are there prior to a release
158if [ ! -r VERSION -o ! -r SUPPORT ] ; then
159  echo Error unable to find VERSION or SUPPORT in the working tree.
160  exit 1
161fi
162
163# We often need to know who is cutting the release
164if test "X${LOGNAME}" = "X" ; then
165  echo "LOGNAME not set"
166  usage
167fi
168
169user_name=`grep ^$LOGNAME /etc/passwd | cut -d':' -f5 | cut -d',' -f1`
170# If you don't have user information, then we won't commit anything.
171if test "X${user_name}" = "X" ; then
172  echo "User information not set"
173  usage
174fi
175
176# before we tag anything make sure it hasn't previously been exported
177if [ -d ${export_dir}/${release_name}-${current} ] ; then
178  echo You must have run this before.
179  echo Removing ${release_name}-${current}
180  rm -rf ${export_dir}/${release_name}-${current}
181fi
182
183# This is where the module has the opportunity to do actions before we tag.
184if test -x ${base}/release_support ; then
185  ${base}/release_support pretag ${release_name} ${current}
186  test $? -ne 0 && (echo "release support (pretag) script failed." ; exit 1)
187fi
188
189#
190#  Whether or not there were special considerations, there might be a
191#  version file.
192#
193version_file=VERSION
194if [ -r ${version_file} ] ; then
195    if test "X${user_name}" = "X" ; then
196      echo "ERROR: User information not set in password file"
197      usage
198    fi
199    ( echo "#" ;
200      echo "#  This file is automatically generated -- DO NOT EDIT!!!" ;
201      echo "#" ;
202      echo "#  \$Id\$" ;
203      echo "#" ;
204      echo ;
205      echo ${Pname} "Version ${current}" ) >$version_file
206      ( echo `date +"%Y-%m-%d"`"        ${user_name}" ;
207        echo ;
208        echo "  * ${version_file}: Updated to ${release_name}-${current}." ;
209        echo ) >YYY
210      if [ -r ChangeLog ] ; then
211        cat YYY ChangeLog >XXX
212        mv XXX ChangeLog
213        cvs -d ${cvs_root} commit -F YYY ChangeLog ${version_file}
214        rm -f YYY
215      else
216        cvs -d ${cvs_root} commit -m \
217               "changed version to ${current}" ${version_file}
218      fi
219fi
220
221# tag the current source
222cd ${base}
223cvs -d ${cvs_root} tag ${current_tag} `grep -v "^D$" CVS/Entries | cut -d'/' -f2`
224if test $? -ne 0 ;  then
225  echo Unable to tag source
226  exit 1
227fi
228
229# export the current source
230cd ${export_dir}
231cvs -d ${cvs_root} export -r ${current_tag} -d ${release_name}-${current} ${module_name}
232if test $? -ne 0 ;  then
233  echo Unable to export source
234  exit 1
235fi
236
237# Now start dealing with the exported source
238cd ${release_name}-${current}
239#if [ ! -r VERSION -o ! -r SUPPORT ] ; then
240#  echo Error unable to find VERSION or SUPPORT in the exported tree.
241#  exit 1
242#fi
243
244# This is where the module has the opportunity to do actions after we export.
245if test -x ${base}/release_support ; then
246  ${base}/release_support postexport
247  test $? -ne 0 && (echo "release support (postexport) script failed." ; exit 1)
248fi
249
250# cut the release files
251test -d ${reldir_curr} || mkdir ${reldir_curr}
252
253# Generate tar and compress it.
254cd ..
255tar cf ${reldir_curr}/${release_name}-${current}.tar ${release_name}-${current}
256${zipper} ${reldir_curr}/${release_name}-${current}.tar
257
258
259# generate diffs if requested
260if [ ${previous} != "NA" ] ; then
261  if [ -r ${reldir_prev}/${release_name}-${previous}.tgz ] ; then
262    tar xzf ${reldir_prev}/${release_name}-${previous}.tgz
263  fi
264  if [ -r ${reldir_prev}/${release_name}-${previous}.tar.gz ] ; then
265    tar xzf ${reldir_prev}/${release_name}-${previous}.tar.gz
266  fi
267  if [ -r ${reldir_prev}/${release_name}-${previous}.tar.bz2 ] ; then
268    bzcat ${reldir_prev}/${release_name}-${previous}.tar.bz2 | tar xf -
269  fi
270
271  diff -N -P -r -u ${release_name}-${previous} ${release_name}-${current} \
272     >${reldir_curr}/${release_name}-${previous}-${current}.diff
273
274  ls -l ${reldir_curr}/${release_name}-${previous}-${current}.diff
275
276  ${zipper} ${reldir_curr}/${release_name}-${previous}-${current}.diff
277
278  ls -l ${reldir_curr}/${release_name}-${previous}-${current}.diff.${zext}
279
280fi
281
282# This is where the module has the opportunity to do actions after
283# the tarball is made.  This can be used to capture host information,
284# sign the tarball, etc.
285#
286#  NOTE: The contents are virgin before this is executed and it is OK
287#        if the script generates files in the tree.  This is commonly
288#        where documentation might be automatically generated.
289cd ${release_name}-${current}
290if test -x ${base}/release_support ; then
291  ${base}/release_support after_tar ${current} ${reldir_curr}
292fi
293
294# generate a ChangeLog difference
295#
296# NOTE:  Removes ALL files not named ChangeLog.  Export directory is
297#        useless past this point.
298cd ..
299if [ ${previous} != "NA" ] ; then
300  if [ -r ${release_name}-${current}/ChangeLog ] ; then
301    find ${release_name}-${previous} ${release_name}-${current} -type f | \
302      grep -v ChangeLog | xargs -e rm -rf
303
304    diff -N -P -r -c ${release_name}-${previous} ${release_name}-${current} \
305       >${reldir_curr}/${release_name}-ChangeLog-${previous}-${current}.diff
306  fi
307fi
308
309# generate the version report
310cd ${base}
311if [ ${do_version_report} = yes ] ; then
312  # trace output from here down is EXTREMEMLY noisy
313  set +x
314  find . -type d -name "CVS" | while read d
315  do
316    D=`dirname $d`
317    cat $d/Entries | grep -v ^D | while read entry
318    do
319      # echo $entry
320      file=`echo $entry |  cut -d'/' -f2`
321      ffile=`echo $D/$file | sed -e 's/^\.\///'`
322      version=`echo $entry |  cut -d'/' -f3`
323      modified=`echo $entry |  cut -d'/' -f4`
324      # printf "%s\t%s\t%s\n" $D/$file $version "$modified"
325      printf "%s\t%s\t%s\n" $version "$modified" $ffile
326    done
327  done >${reldir_curr}/${release_name}-${current}-FILES
328fi
329
330# generate md5 checksums
331cd ${reldir_curr}
332find `pwd` -type d | while read d
333do
334  cd $d
335  rm -f md5sum.txt
336  files=`find . -maxdepth 1 -type f | wc -l`
337  if [ ${files} -eq 0 ] ; then
338    echo $d is empty so no checksum generated
339  else
340    echo Checksum generated for $d
341    md5sum `find . -maxdepth 1 -type f` >md5sum.txt
342  fi
343done
344
345# remove the exported source to save space
346rm -rf ${export_dir}
347
348echo ${reldir_curr}/${release_name}-${current}.tar*
349
350exit 0
351
Note: See TracBrowser for help on using the repository browser.