aboutsummaryrefslogtreecommitdiffstats
path: root/tools/conf/srv/gitolite/deployweb
blob: 5a18ed10287375a75d94cffe28dae606db8230b7 (plain) (blame)
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
#!/bin/sh

######################################################################
#
# Put this file in;
# /usr/share/gitolite/deployweb
#
DIR_WWW=/srv/www/
DEPLOY_BRANCH=deployweb
TARGET_USER=nginx

for DP_FILE in /srv/gitolite/deploy/*
do

	if [ ! -f "$DP_FILE" ]; then
		# Nothing to do ;)
		#echo "Deploy: invalid DP_FILE"
		exit 1;
	fi

	# Get project name
	PROJECT=$(basename "$DP_FILE")
	echo "Deploy: PROJECT=${PROJECT}"

	# Get git repository path and verify if exists
	DIR_GIT=$(head -n 1 $DP_FILE)
	if [ ! -d "$DIR_GIT" ]; then
		echo "Deploy: invalid DIR_GIT: ${DIR_GIT}"
		exit 2;
	fi
	echo "Deploy: DIR_GIT=${DIR_GIT}"

	# Get directory to deploy and verify if exists
	GIT_WORK_TREE=${DIR_WWW}${PROJECT}/
	if [ ! -d "$GIT_WORK_TREE" ]; then
		echo "Deploy: invalid GIT_WORK_TREE: ${GIT_WORK_TREE}"
		echo "Deploy: creating directory: $GIT_WORK_TREE}"
		mkdir -p $GIT_WORK_TREE
	fi
	echo "Deploy: GIT_WORK_TREE={$GIT_WORK_TREE}"

	# Deploy (checkout)
	echo "Deploy: starting git checkout"

	git --git-dir=$DIR_GIT \
		--work-tree=$GIT_WORK_TREE \
		checkout -f $DEPLOY_BRANCH


	# Fix ownership and permissions
	echo "Deploy: fixing permissions"

	echo "Deploy: setting owner: chown -R ${TARGET_USER}"
	chown -R ${TARGET_USER}:${TARGET_USER} $GIT_WORK_TREE

	echo "Deploy: setting directory permissions: chmod 755"
	find $GIT_WORK_TREE -type d -print0 | xargs -0 chmod 755

	echo "Deploy: setting file permissions: chmod 644"
	find $GIT_WORK_TREE -type f -print0 | xargs -0 chmod 644

	# Call project script
	if [ -f "${GIT_WORK_TREE}/deploy.sh" ]; then
		echo "Deploy: calling ${GIT_WORK_TREE}deploy.sh"
		cd ${GIT_WORK_TREE}
		sudo -u ${TARGET_USER} sh ${GIT_WORK_TREE}deploy.sh
	fi

	# Done with project
	echo "Deploy: removing deploy file="$DP_FILE
	rm $DP_FILE

	exit 0;
done