-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-receive
71 lines (60 loc) · 1.7 KB
/
post-receive
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
#!/bin/bash
PROJECT_NAME=yt-player
BASE_DIR=/var/slothyx
TMP_DIR=$BASE_DIR/tmp
RELEASE_DIR=$BASE_DIR/$PROJECT_NAME
DEV_DIR=$BASE_DIR/$PROJECT_NAME-dev
LOG_FILE=$BASE_DIR/$PROJECT_NAME.log
REPOSITORY=/opt/git/repositories/$PROJECT_NAME.git
TOMCAT_DIR=/var/lib/tomcat7/webapps
exec 1>$LOG_FILE
exec 2>&1
function checkoutRepo {
branch="$1"
targetDir="$2"
cd $TMP_DIR
echo "Cloning branch ${branch}..."
unset GIT_DIR
git clone -b $branch $REPOSITORY $branch
echo "Running build script..."
cd "$branch"
chmod a+x build.sh
./build.sh
echo "Searching built data..."
if [ -d "out/www" ]; then
echo "www-folder detected!"
rm -rf "$targetDir"
cp -rf "out/www" "$targetDir"
chmod -R a+rx "$targetDir"
fi
if [ -f "out/service.war" ]; then
echo "service.war detected!"
warname="slothyx_${branch}.war"
warpath="$TOMCAT_DIR/$warname"
rm -f "$warpath"
cp -f "out/service.war" "$warpath"
chmod a+rx "$warpath"
fi
cd ..
echo "Cleanup..."
rm -rf $branch
}
function thirdElementOf {
string="$1"
delimiter="$2"
args=(${string//"${delimiter}"/ })
echo "${args[2]}"
}
while read line
do
ref="$(thirdElementOf "$line" " ")"
branch="$(thirdElementOf "$ref" "/")"
done < /dev/stdin
if [ "$branch" == "release" ]; then
echo "New Release detected!"
checkoutRepo "$branch" "$RELEASE_DIR"
fi
if [ "$branch" == "master" ]; then
echo "New Dev-version detected!"
checkoutRepo "$branch" "$DEV_DIR"
fi