#!/bin/bash REPO_DIR_ANON="" REPO_DIR_DEVEL="autopackage" REPO_SERVER="plan99.net" REPO_PROTOCOL_DEVEL="svn+ssh" REPO_PROTOCOL_ANON="svn" DEFAULT_MODULES="apbuild binreloc display-tool foobar frontend lzma main" ALL_MODULES="apbuild binreloc display-tool foobar frontend gladecompat lzma main mkapspec visual-ldd" function normal() { echo -en "\033[0m"; } function red() { echo -en "\033[1;31m"; } function blue() { echo -en "\033[1;34m"; } function green() { echo -en "\033[1;32m"; } function bold() { echo -en "\033[1m"; } subdir="trunk" list_modules=false; all_modules=false; while [ -n "$1" ]; do case $1 in --branch) branch="$2" subdir="branches/$2" shift ;; --branch=*) branch=$(echo $1 | cut -d= -f2) subdir="branches/$branch" ;; --tag) tag=$2 subdir="tags/$tag" shift ;; --tag=*) tag=$(echo $1 | cut -d= -f2) subdir="tags/$tag" ;; --user) user="$2" shift ;; --user=*) user=$(echo $1 | cut -d= -f2) ;; --list-modules) list_modules=true ;; --all|--all-modules) all_modules=true; ;; --help) echo "Usage: checkout [OPTIONS] [module1 [module2...]]" echo echo "This script will checkout the autopackage source code from subversion to the current directory. Code will be checked out from 'trunk' if no branch or tag is explicitly specified." echo echo "If no modules are specified, the following modules will be checked out:" echo " `bold`$DEFAULT_MODULES`normal`" echo echo "Options" echo -e " --branch=BRANCHNAME\tCheck out code from the branch \"BRANCHNAME\" instead of the trunk" echo -e " --tag=TAGNAME\t\tCheck out code from the tag \"TAGNAME\" instead of the trunk" echo -e " --user=USERNAME\tAccess the repository using ssh account USERNAME on the server (developers only)" echo -e " --list-modules\tList the available modules" echo -e " --all\t\tCheckout all modules in svn" echo -e " --all-modules\tSynonymous to --all" echo exit 1 ;; -*) echo "Unknown option: $1" echo "Usage: checkout-from-svn [OPTIONS] [module1 [module2...]]" echo "Try '--help' to see more detailed information" exit 2 ;; *) modules="$modules $1" ;; esac shift done # Set the repository if [ "$user" ]; then REPO_PROTOCOL=$REPO_PROTOCOL_DEVEL REPO_DIR=$REPO_DIR_DEVEL REPO_SERVER="$user@$REPO_SERVER" else REPO_PROTOCOL=$REPO_PROTOCOL_ANON REPO_DIR=$REPO_DIR_ANON fi REPO_URL="$REPO_PROTOCOL://$REPO_SERVER/$REPO_DIR" if $list_modules; then echo svn ls "$REPO_URL" svn ls "$REPO_URL" exit 0 fi # Determine which modules to check out if $all_modules; then modules="$ALL_MODULES" elif [ -z "$modules" ]; then modules="$DEFAULT_MODULES" fi ## Remove duplicates and sort the modules modules=$(echo $modules | tr ' ' '\n' | sort | uniq | tr '\n' ' ') modulecount=$(echo $modules | wc -w) ## Sanity checks before proceeding: Don't do checkouts if one or more ## of the modules already exists in the current directory. dirExists=false for module in $modules; do if [ -e "$module" ]; then dirExists=true existingDirs="$existingDirs $module" fi done if $dirExists; then echo "`red`Warning:`normal` The following module(s) already exist in this directory:" echo "`blue` $existingDirs`normal`" echo "Aborting checkout!" exit 1; fi ## Just a quick confirmation from the user before we proceed... echo "* The following `bold`$modulecount`normal` module(s) will be checked out from Subversion:" echo " `blue`$modules`normal`" if [ "$user" ]; then echo "* Repository will be accessed using ssh for user `green`$user`normal` (developer read/write)." else echo "* Repository will be accessed anonymously (read only)"; fi if [ "$tag" ]; then echo "* Code will be checked out from the tag `green`\"$tag\"`normal`." elif [ "$branch" ]; then echo "* Code will be checked out from the `green`\"$branch\"`normal` branch." else echo "* Code will be checked out from svn `bold`HEAD`normal`." fi # It seems some versions of bash (dapper for instance) does not # give the script a real stdin when the script is piped to it. if tty -s; then echo echo "Press [Enter] to continue, or CTRL-C to bail out" read fi for module in $modules; do echo "`bold`* Checking out \"`blue`$module`normal;bold`\"...`normal`" echo "svn co $REPO_URL/$module/$subdir $module" svn co "$REPO_URL/$module/$subdir" $module done