forked from mytharcher/hookagent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·72 lines (53 loc) · 1.3 KB
/
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
#!/bin/bash
LOG_PATH=/var/log/hookagent
PROJECT=$1
remote=$2
branch=$3
path=$4
task=$5
sudo=$6
user=$7
group=$8
if [[ $sudo == true ]] ; then
echo "Sudo On: sudo -H -u$user -g$group ${BASH_SOURCE[0]} $PROJECT $remote $branch $path $task false $user $group"
sudo -H -u$user -g$group ${BASH_SOURCE[0]} $PROJECT $remote $branch $path $task false $user $group
else
date
echo "start deploying $remote/$branch"
TEMP_FLAG=$LOG_PATH/.$PROJECT.$remote-$branch
if [[ ! -f $TEMP_FLAG ]]; then
touch $TEMP_FLAG
else
echo "still deploying..."
exit 0
fi
found=0
pwd
echo "git reset --hard HEAD"
git reset --hard HEAD
echo "git fetch $remote"
git fetch $remote
for br in $(git branch | sed 's/^[\* ]*//')
do
if [[ $br == $branch ]]; then
echo "found branch: $branch"
found=1
fi
done
if [[ $found == 1 ]]; then
echo "git checkout -q $branch"
git checkout -q $branch
echo "git merge $remote/$branch"
git merge $remote/$branch
else
echo "git checkout $remote/$branch -b $branch"
git checkout $remote/$branch -b $branch
fi
#git submodule update --init --recursive
if [[ $task != '' ]]; then
echo "start to run shell script: sh $task $path $branch"
sh $task $path $branch
fi
rm $TEMP_FLAG
fi
date