-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhooks.sh
More file actions
59 lines (40 loc) · 1.51 KB
/
hooks.sh
File metadata and controls
59 lines (40 loc) · 1.51 KB
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
#!/bin/bash
# Author : Harshad Yeola
# This scripts is intended to be used as hook to sync repositories on server.
declare -A repos
declare -A branch
LOG="/var/log/hooks.log"
function error()
{
echo -e "[ `date` ] failed ==> $(tput setaf 1)$@$(tput sgr0)" | tee -ai $LOG
exit $2
}
function echo_output()
{
echo -e "[ `date` ] success ==> $(tput setaf 4)$@$(tput sgr0)" | tee -ai $LOG
}
# define repo path and branch
# etc-config repo
repos['etc-config']='/etc'
branch['etc-config']='master'
# example-com-wp-composer repo
repos['example-com-wp-composer']='/var/www/wp.example.com'
branch['example-com-wp-composer']='master'
# repos['etc-config']="/home/harshad/Github/easyengine"
# branch['etc-config']='feature/plugin'
for repo in ${!repos[@]}; do
path=${repos[$repo]}
git_branch=${branch[$repo]}
current_branch=$(cd $path && git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" == "$git_branch" ]; then
echo_output "Fetching $repo commits at $path with branch $git_branch "
cd $path &>>$LOG || error "cd $path" $?
git reset --hard HEAD &>>$LOG || error "git reset --hard HEAD" $?
git pull origin ${git_branch} &>>$LOG || error "git pull origin ${git_branch}" $?
if [ "$path" == "/etc" ]; then
service nginx reload &>>$LOG || error "service nginx reload" $?
service php5-fpm reload &&>>$LOG || error "service php5-fpm reload" $?
service mysql reload &&>>$LOG || error "service mysql reload" $?
fi
fi
done