Changeset 5662 for trunk/scripts

Show
Ignore:
Timestamp:
10/22/07 05:56:42 (14 months ago)
Author:
erijo
Message:

Add command line options

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/scripts/create-licq-tarball.sh

    r5659 r5662  
    22# 
    33# Script to create a source tarball from Licq's svn repository. 
    4 #  
    5 # Author: Erik Johansson <erik@ejohansson.se> 
    64# Latest version: http://svn.licq.org/svn/trunk/scripts/ 
    7 #  
    8 # Usage: ./create-licq-tarball.sh [tardir] 
    9 #        [tardir] - optional directory to place tarball in; 
    10 #                   defaults to current directory 
     5# 
     6# Copyright (c) 2007 Erik Johansson <erijo@licq.org> 
     7# Distributed under the terms of the GNU GPL version 2. 
     8# 
    119 
    12 # Where to save the tarball(s) (default: first argument or current dir) 
    13 TARDIR="${1:-.}" 
     10### DEFAULT SETTINGS ### 
     11 
     12# Where to save the tarball(s) 
     13TARDIR="." 
    1414 
    1515# What to name the tarball (REV is replaced with the svn revision) 
     
    1919 
    2020# Archives to create (1 = create; 0 = don't create) 
    21 CREATE_GZ=1 
     21CREATE_GZ=0 
    2222CREATE_BZ2=0 
    2323 
    2424# Sign archives using default GPG key (1 = sign; 0 = don't sign) 
    2525SIGN=0 
    26  
    27 # What to name the directory in the tarball (REV is replaced with the svn revision) 
    28 DIRNAME="${TARNAME}" 
    2926 
    3027# What revision to export 
     
    4037### END SETTINGS ### 
    4138 
    42 #------------------------------------------------------------------# 
     39# Prints the usage 
     40function usage() 
     41{ 
     42    echo "Usage: $0 [-r rev] [-o dir] [-n name] [-g] [-b] [-s]" 
     43    echo "  -h, --help   This message" 
     44    echo "  -r rev       Create tarball from revision rev (default: ${LICQREV})" 
     45    echo "  -o dir       Save tarball in directory dir (default: ${TARDIR})" 
     46    echo "  -n name      Name the tarball name (default: ${TARNAME})" 
     47    echo "               REV is replaced with the svn revision" 
     48    echo "  -g, --gzip   Create a tar.gz archive" 
     49    echo "  -b, --bzip2  Create a tar.bz archive" 
     50    echo "  -s, --sign   Sign archive(s) with default GPG key" 
     51} 
     52 
     53if [ $# -eq 0 ]; then 
     54    echo "$0: Missing required argument (-g and/or -b)" 
     55    echo "Try \`$0 --help' for more information" 
     56    exit 2 
     57fi 
     58 
     59# Parse command line options 
     60args=$(getopt -n "$0" -o h,r:,o:,n:,g,b,s -l help -- $*) 
     61if [ $? -ne 0 ]; then 
     62    echo "" 
     63    usage 
     64    exit 1 
     65fi 
     66 
     67set -- $args 
     68while [ $# -gt 0 ]; do 
     69    case $1 in 
     70    -h|--help) usage; exit 0 ;; 
     71    -r) LICQREV=$(eval echo $2); shift ;; 
     72    -o) TARDIR=$(eval echo $2); shift ;; 
     73    -n) TARNAME=$(eval echo $2); shift ;; 
     74    -g|--gzip) CREATE_GZ=1 ;; 
     75    -b|--bzip2) CREATE_BZ2=1 ;; 
     76    -s|--sign) SIGN=1 ;; 
     77    --) ;; 
     78    *) echo "$0: unknown option '$1'"; exit 1 ;; 
     79    esac 
     80    shift 
     81done 
     82 
     83if [ $CREATE_GZ -eq 0 -a $CREATE_BZ2 -eq 0 ]; then 
     84    echo "$0: You must choose to create a gzip and/or bzip2 archive" 
     85    echo "" 
     86    usage 
     87    exit 1 
     88fi 
     89 
     90# Workdir 
     91TMPDIR=$(mktemp -d) || failed "mktemp -d" 
     92 
     93# Remove workdir 
     94function cleanup() 
     95{ 
     96   echo "Removing ${TMPDIR}" 
     97   rm -rf "${TMPDIR}" 
     98} 
     99 
    43100# Echos "$1 failed" or "failed" and then exits. 
    44 #------------------------------------------------------------------# 
    45101function failed() 
    46102{ 
     
    50106      echo "$1 failed" 
    51107   fi 
     108   cleanup 
    52109   exit 1 
    53110} 
     
    55112SVNREV=$(svn info -r"${LICQREV}" "${REPO}" | grep "^Revision:" | awk '{print $2}') || failed 
    56113 
    57 TMPDIR=$(mktemp -d) || failed "mktemp -d" 
    58 DIRNAME="${DIRNAME//REV/$SVNREV}" 
     114DIRNAME="${TARNAME//REV/$SVNREV}" 
    59115TARNAME="${TARNAME//REV/$SVNREV}" 
    60116LICQDIR="${TMPDIR}/${DIRNAME}" 
     
    77133function makecvs() 
    78134{ 
    79    echo "Running make -f $1/Makefile.cvs" 
     135   echo -n "Running make -f $1/Makefile.cvs... " 
    80136   make -C "${LICQDIR}/$1" -f "${LICQDIR}/$1/Makefile.cvs" > /dev/null 2>&1 || failed 
    81137   rm -rf "${LICQDIR}/$1/autom4te.cache" 
    82138   rm -f "${LICQDIR}/$1/Makefile.cvs" 
    83 } 
    84  
    85 function cleanup() 
    86 { 
    87    echo "Removing ${TMPDIR}" 
    88    rm -rf "${TMPDIR}" 
     139   echo "done" 
    89140} 
    90141