1a749a8828156493897772785e599c0ce2ddf519
[deploy-hooks.git] / trustcommerce.git / post-update
1 #!/bin/sh
2 #
3 # An example hook script to prepare a packed repository for use over
4 # dumb transports.
5 #
6 # To enable this hook, rename this file to "post-update".
7
8 date_fmt="+%m-%d-%Y %H:%M:%S"
9
10 local_checkout_base=/home/git/local/checkouts/trustcommerce
11 package_path_base=/var/www/agpl.fsf.org/crm.fsf.org
12 package_host=agpl.fsf.org
13 package_name=trustcommerce
14
15 repository=/home/git/repositories/trustcommerce.git
16 target_path=/var/www/civicrm_custom/extensions/org.fsf.payment.trustcommerce
17 remote_user=vcshookuser
18
19 echo -n $(date "$date_fmt"); echo " - Starting post-update hook..."
20
21
22 # Unset GIT_DIR to allow for calls to git clone/pull
23 git update-server-info
24 unset GIT_DIR
25
26
27 # Extract the branch name
28 branch=$(echo $1 | awk -F'/' '{print $3}')
29
30 # Debug
31 echo -n $(date "$date_fmt"); echo " - Processing branch: $1"
32
33 # Set branch specific configurations
34 case $branch in
35 master)
36 package_path=$package_path_base/devel
37 local_checkout=$local_checkout_base/$branch
38 target_host=crm-dev.fsf.org
39 ;;
40 live)
41 package_path=$package_path_base/$branch
42 local_checkout=$local_checkout_base/$branch
43 target_host=crm.fsf.org
44 ;;
45 *)
46 echo $branch was deleted
47 exit
48 ;;
49 esac
50
51 echo -n $(date "$date_fmt"); echo " - Target host: $target_host"
52 echo -n $(date "$date_fmt"); echo " - Target path: $target_path"
53 echo -n $(date "$date_fmt"); echo " - Package host: $package_host"
54 echo -n $(date "$date_fmt"); echo " - Package path: $package_path"
55 echo -n $(date "$date_fmt"); echo " - Remote user: $remote_user"
56
57 # See if local checkout exists
58 if [ ! -d $local_checkout ]; then
59 echo -n $(date "$date_fmt"); echo " - No local checkout detected, creating now"
60 git clone $repository $local_checkout
61 cd $local_checkout
62 else
63 echo -n $(date "$date_fmt"); echo " - Updating local checkout"
64 cd $local_checkout
65 git pull origin $branch
66 fi
67
68 echo -n $(date "$date_fmt"); echo " - Pushing files to target host"
69 rsync -arzSPX --exclude=.git/ --delete $local_checkout/* $remote_user@$target_host:$target_path/ #2>/dev/null
70
71 echo -n $(date "$date_fmt"); echo " - Updating target path permissions"
72 ssh $remote_user@$target_host "find $remote_path -type f -print0 | xargs -0 chmod 644 && find $remote_path -type d -print0 | xargs -0 chmod 755" # 2>/dev/null
73
74 echo -n $(date "$date_fmt"); echo " - Packing for export to package host"
75 rm -f $local_checkout_base/*tar.gz
76 rm -f $local_checkout_base/*zip
77 cd $local_checkout_base
78 tar czv --exclude-vcs -f $package_name.tar.gz $branch
79 zip -r $package_name $branch -x "*/.git/*" "*/.gitignore"
80
81 echo -n $(date "$date_fmt"); echo " - Pushing to packaging server"
82 scp $package_name.zip $package_name.tar.gz $remote_user@$package_host:$package_path/
83
84