removed debug
[deploy-hooks.git] / edward.git / post-update
1 #!/bin/bash
2
3 date_fmt="+%m-%d-%Y %H:%M:%S"
4
5 local_checkout_base=/home/git/local/checkouts/edward
6 package_path_base=/var/www/agpl.fsf.org/emailselfdefense.fsf.org/edward/
7 package_host=agpl.fsf.org
8 package_name=edward
9 package_user=vcshookuser
10
11 repository=/home/git/repositories/edward.git
12 remote_user=edward
13 target_path=~$remote_user/edward-src
14
15 doc_base=/var/www/docs/$package_name
16
17 echo -n $(date "$date_fmt"); echo " - Starting post-update hook..."
18
19 # Unset GIT_DIR to allow for calls to git clone/pull
20 git update-server-info
21 unset GIT_DIR
22
23
24 # Extract the branch name
25 branch=$(echo $1 | awk -F'/' '{print $3}')
26
27 # Debug
28 echo -n $(date "$date_fmt"); echo " - Processing branch: $1"
29
30 # Set branch specific configurations
31 case $branch in
32 master)
33 local_checkout=$local_checkout_base/$branch
34 package_path=$package_path_base/
35 target_host=fencepost.gnu.org
36 ;;
37 *)
38 echo Hook for $branch does not exist, taking no further action.
39 exit
40 ;;
41 esac
42
43 doc_path=$doc_base/$branch
44
45 echo -n $(date "$date_fmt"); echo " - Target host: $target_host"
46 echo -n $(date "$date_fmt"); echo " - Target path: $target_path"
47 echo -n $(date "$date_fmt"); echo " - Package host: $package_host"
48 echo -n $(date "$date_fmt"); echo " - Package path: $package_path"
49 echo -n $(date "$date_fmt"); echo " - Remote user: $remote_user"
50
51 # See if local checkout exists
52 if [ ! -d $local_checkout ]; then
53 echo -n $(date "$date_fmt"); echo " - No local checkout detected, creating now"
54 mkdir -p $local_checkout
55 git clone $repository $local_checkout &>/dev/null
56 cd $local_checkout
57 git checkout $branch &>/dev/null
58 else
59 echo -n $(date "$date_fmt"); echo " - Updating local checkout"
60 cd $local_checkout
61 git checkout $branch &>/dev/null
62 git pull origin $branch &>/dev/null
63 fi
64
65 echo -n $(date "$date_fmt"); echo " - Packing zip and tarball for package host"
66 rm -f $local_checkout_base/*tar.gz
67 rm -f $local_checkout_base/*zip
68 cd $local_checkout_base
69 tar czv --exclude-vcs -f $package_name.tar.gz $branch &>/dev/null
70 zip -r $package_name $branch -x "*/.git/*" "*/.gitignore" &>/dev/null
71
72 echo -n $(date "$date_fmt"); echo " - Pushing to packaging server: https://$package_host/emailselfdefense.fsf.org/edward/"
73 scp $package_name.zip $package_name.tar.gz $package_user@$package_host:$package_path/ >/dev/null
74
75 # Stop here if not updating a host
76 if [ -z $target_host ]; then
77 exit
78 fi
79
80 echo -n $(date "$date_fmt"); echo " - Pushing files to target host: $target_host:$target_path"
81 rsync -arvPSX --exclude=lang/ --exclude=.git/ --delete $local_checkout/* $remote_user@$target_host:$target_path/ &>/dev/null
82