dev/provisioning/modules/puppi/files/scripts/svn.sh
changeset 28 b0b56e0f8c7f
equal deleted inserted replaced
27:a2342f26c9de 28:b0b56e0f8c7f
       
     1 #!/bin/bash
       
     2 # svn.sh - Made for Puppi
       
     3 
       
     4 # All variables are exported
       
     5 set -a 
       
     6 
       
     7 # Sources common header for Puppi scripts
       
     8 . $(dirname $0)/header || exit 10
       
     9 
       
    10 # Show help
       
    11 showhelp () {
       
    12     echo "This script performs the svn operations required by puppi::project::svn"
       
    13     echo "It integrates and uses variables provided by other core Puppi scripts"
       
    14     echo "It has the following options:"
       
    15     echo "-a <action> (Optional) What action to perform. Available options: deploy (default), rollback"
       
    16     echo "-s <source> (Required) Subversion source repo to use"
       
    17     echo "-d <destination> (Required) Directory where files are deployed"
       
    18     echo "-u <user> (Optional) User that performs the deploy operations. Default root"
       
    19     echo "-su <user> (Optional) Username for access to private svn repo"
       
    20     echo "-sp <password> (Optional) Password for access to private svn repo"
       
    21     echo "-gs <svn_subdir> (Optional) If only a specific subdir of the svnrepo has to be copied to the install destination"
       
    22     echo "-t <tag> (Optional) Tag to deploy"
       
    23     echo "-b <branch> (Optional) Branch to deploy"
       
    24     echo "-c <commit> (Optional) Commit to deploy"
       
    25     echo "-v <true|false> (Optional) If verbose"
       
    26     echo "-k <true|false> (Optional) If .svn dir is kept on deploy_root"
       
    27     echo "-e <true|false> (Optional) If use export instead of checkout for svn operations"
       
    28     echo 
       
    29     echo "Examples:"
       
    30     echo "svn.sh -a deploy -s $source -d $deploy_root -u $user -gs $svn_subdir -t $tag -b $branch -c $commit -v $bool_verbose -k $bool_keep_svndata"
       
    31 }
       
    32 
       
    33 verbose="true"
       
    34 
       
    35 # Check Arguments
       
    36 while [ $# -gt 0 ]; do
       
    37   case "$1" in
       
    38     -a)
       
    39       case $2 in
       
    40           rollback)
       
    41           action="rollback"
       
    42           ;;
       
    43           *)
       
    44           action="install"
       
    45           ;;
       
    46       esac 
       
    47       shift 2 ;;
       
    48     -s)
       
    49       if [ $source ] ; then
       
    50         source=$source
       
    51       else
       
    52         source=$2
       
    53       fi
       
    54       shift 2 ;;
       
    55     -d)
       
    56       if [ $deploy_root ] ; then
       
    57         deploy_root=$deploy_root
       
    58       else
       
    59         deploy_root=$2
       
    60       fi
       
    61       shift 2 ;;
       
    62     -u)
       
    63       if [ $user ] ; then
       
    64         deploy_user=$user
       
    65       else
       
    66         deploy_user=$2
       
    67       fi
       
    68       shift 2 ;;
       
    69     -gs)
       
    70       if [ $svn_subdir ] ; then
       
    71         svn_subdir=$svn_subdir
       
    72       else
       
    73         svn_subdir=$2
       
    74       fi
       
    75       shift 2 ;;
       
    76     -su)
       
    77       if [ $svn_user ] ; then
       
    78         svn_user=$svn_user
       
    79       else
       
    80         svn_user=$2
       
    81       fi
       
    82       shift 2 ;;
       
    83     -sp)
       
    84       if [ $svn_password ] ; then
       
    85         svn_password=$svn_password
       
    86       else
       
    87         svn_password=$2
       
    88       fi
       
    89       shift 2 ;;
       
    90     -t)
       
    91       if [ $svn_tag ] ; then
       
    92         svn_tag=$svn_tag
       
    93       else
       
    94         svn_tag=$2
       
    95       fi
       
    96       shift 2 ;;
       
    97     -b)
       
    98       if [ $branch ] ; then
       
    99         branch=$branch
       
   100       else
       
   101         branch=$2
       
   102       fi
       
   103       shift 2 ;;
       
   104     -c)
       
   105       if [ $commit ] ; then
       
   106         commit=$commit
       
   107       else
       
   108         commit=$2
       
   109       fi
       
   110       shift 2 ;;
       
   111     -v)
       
   112       if [ $verbose ] ; then
       
   113         verbose=$verbose
       
   114       else
       
   115         verbose=$2
       
   116       fi
       
   117       shift 2 ;;
       
   118     -k)
       
   119       if [ $keep_svndata ] ; then
       
   120         keep_svndata=$keep_svndata
       
   121       else
       
   122         keep_svndata=$2
       
   123       fi
       
   124       shift 2 ;;
       
   125     -e)
       
   126       if [ $svn_export ] ; then
       
   127         svn_export=$svn_export
       
   128       else
       
   129         svn_export=$2
       
   130       fi
       
   131       shift 2 ;;
       
   132     *)
       
   133       showhelp
       
   134       exit ;;
       
   135   esac
       
   136 done
       
   137 
       
   138 if [ "x$verbose" == "xtrue" ] ; then
       
   139   verbosity=""
       
   140 else
       
   141   verbosity="--quiet"
       
   142 fi
       
   143 
       
   144 cd /
       
   145 
       
   146 if [ "x$branch" == "xundefined" ] ; then
       
   147   branch="trunk"
       
   148 fi
       
   149 
       
   150 real_source="$source/$branch"
       
   151 
       
   152 if [ "x$svn_tag" != "xundefined" ] ; then
       
   153   real_source="$source/$svn_tag"
       
   154 fi
       
   155 
       
   156 if [ "x$svn_user" != "xundefined" ] && [ "x$svn_password" != "xundefined" ] ; then
       
   157   svn_auth="--username=$svn_user --password=$svn_password"
       
   158 else
       
   159   svn_auth=""
       
   160 fi
       
   161 
       
   162 svnsubdir=""
       
   163 svndir=$deploy_root
       
   164 
       
   165 
       
   166 do_install () {
       
   167   if [ "x$keep_svndata" != "xtrue" ] ; then
       
   168     if [ ! -d $archivedir/$project-svn ] ; then
       
   169       mkdir $archivedir/$project-svn
       
   170       chown -R $user:$user $archivedir/$project-svn
       
   171     fi
       
   172     svndir=$archivedir/$project-svn/svnrepo
       
   173   fi
       
   174   if [ "x$svn_subdir" != "xundefined" ] ; then
       
   175     if [ ! -d $archivedir/$project-svn ] ; then
       
   176       mkdir $archivedir/$project-svn
       
   177       chown -R $user:$user $archivedir/$project-svn
       
   178     fi
       
   179     svndir=$archivedir/$project-svn
       
   180     svnsubdir="$svn_subdir/"
       
   181   fi
       
   182 
       
   183   if [ -d $svndir/.svn ] ; then
       
   184     cd $svndir
       
   185     svn up $verbosity $svn_auth --non-interactive
       
   186   else
       
   187     svn co $verbosity $real_source $svndir $svn_auth --non-interactive
       
   188     cd $svndir
       
   189   fi
       
   190 
       
   191   if [ "x$svndir" == "x$archivedir/$project-svn/svnrepo" ] ; then
       
   192     rsync -a --exclude=".svn" $svndir/$svnsubdir $deploy_root/
       
   193   fi
       
   194 }
       
   195 
       
   196 do_export () {
       
   197   svn export $verbosity $svn_auth --force --non-interactive $real_source/$svn_subdir $deploy_root
       
   198 }
       
   199 
       
   200 do_rollback () {
       
   201   echo "Rollback not yet supported"
       
   202 }
       
   203 
       
   204 # Action!
       
   205 case "$action" in
       
   206     install) 
       
   207       if [ "x$svn_export" == "xtrue" ] ; then
       
   208         export -f do_export ; su $user -c do_export
       
   209       else
       
   210         export -f do_install ; su $user -c do_install
       
   211       fi
       
   212       ;;
       
   213     rollback) do_rollback ;;
       
   214 esac
       
   215