This repository has been archived by the owner on Feb 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rsync-deploy.sh
executable file
·81 lines (68 loc) · 1.61 KB
/
rsync-deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh
#
# An update hook that deploys the master branch via rsync.
# Checks if the update is a commit on the master branch, then checks out the
# files to a temporary directory and rsyncs them up to the web-server.
#
# --- Command line
refname="$1"
oldrev="$2"
newrev="$3"
# --- Safety check
if [ -z "$GIT_DIR" ]; then
echo "Don't run this script from the command line." >&2
echo " (if you want, you could supply GIT_DIR then run" >&2
echo " $0 <ref> <oldrev> <newrev>)" >&2
exit 1
fi
if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
echo "usage: $0 <ref> <oldrev> <newrev>" >&2
exit 1
fi
# --- Config
wwwpath=$(git config hooks.wwwpath)
keeptmpdir=$(git config --bool hooks.keeptmpdir)
# --- Check types
# if $newrev is 0000...0000, it's a commit to delete a ref.
zero="0000000000000000000000000000000000000000"
if [ "$newrev" = "$zero" ]; then
newrev_type=delete
else
newrev_type=$(git cat-file -t $newrev)
fi
if [[ "$refname","$newrev_type" == "refs/heads/master","commit" ]]; then
if [[ -z $wwwpath ]]; then
echo "Path to web server is empty (hooks.wwwpath)" 1>&2
exit 1
fi
tmpdir=`mktemp -d`
echo "building in $tmpdir" 1>&2
git --work-tree=$tmpdir checkout --force $newrev >/dev/null
if [[ $? -ne 0 ]]; then
echo "failed checking out $newrev to $tmpdir" 1>&2
exit 1
fi
set -e
cd $tmpdir
make
chmod -R a+r build/*
chown -R git:apache build/*
rsync \
--recursive \
--perms \
--times \
--links \
--verbose \
--progress \
--stats \
--compress \
--update \
build/* \
$wwwpath
if [[ "$keeptmpdir" != "true" ]]; then
cd
rm -rf $tmpdir
fi
fi
# --- Finished
exit 0