forked from rancher/cattle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cattle.sh
executable file
·118 lines (101 loc) · 2.23 KB
/
cattle.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
set -e
if [ -z "$BUG_INCEPTION" ]; then
# Work around issue https://github.com/dotcloud/docker/issues/4854
export BUG_INCEPTION=true
$0 "$@"
exit $?
fi
BASE=$(dirname $0)
cd $BASE
trap fixperms EXIT
fixperms()
{
if [ -n "$BUILD_USER_ID" ]; then
cd $BASE
echo "Assign files to $BUILD_USER_ID"
chown -R $BUILD_USER_ID .
fi
}
run()
{
WAR="$(selectjar)"
if [ ! -e "$WAR" ]; then
mvn clean install
fi
WAR=$(readlink -f $WAR)
mkdir -p runtime
cd runtime
echo Running $WAR "$@"
exec java -jar $WAR "$@"
}
selectjar()
{
local files=(code/packaging/app/target/*.war
code/packaging/bundle/target/cattle-bundle*.jar
target/checkout/.m2/io/cattle/cattle-bundle/*/cattle-bundle-[0-9].[0-9].[0-9].jar)
local src=
for i in ${files[@]}; do
if [ -e "$i" ]; then
if [ "$src" = "" ] || [ $i -nt $src ]; then
src=$i
fi
fi
done
if [ -e "${src}" ]; then
echo ${src}
fi
}
build()
{
echo HOME=$HOME
if [ ! -e $HOME/.m2 ] && [ -e /opt/m2-base ]; then
cp -rf /opt/m2-base $HOME/.m2
fi
if [ ! -e $HOME/.m2/repository/io/github/cattle ] && [ -e deps/cattle ]; then
(
cd deps/cattle
mvn -DskipTests=true install
)
fi
if [ "$#" = "0" ]; then
mvn $MAVEN_ARGS ${MAVEN_TARGET:-install}
else
mvn "$@"
fi
mkdir -p dist/server/artifacts
local target=dist/server/artifacts/cattle.jar
local src=$(selectjar)
if [ -e "$src" ] && [ ! -e $target ] || [ "$src" -nt "$target" ]; then
echo "Copying $src => $target"
cp $src $target
if [[ $src =~ .*jar$ ]]; then
java -jar $target version > dist/version
fi
fi
tar c -C tools/docker/package . | tar xf - -C dist
}
if [ "$#" = "0" ]; then
echo "Usage:"
echo -e "\t$0 (build|run)"
echo -e "\t\t build: Compiles from source"
echo -e "\t\t run: Starts Cattle on port 8080 (will build if no build has been done)"
exit 1
fi
case $1 in
mvn)
shift
build "$@"
;;
build)
shift
build "$@"
;;
run)
shift
run "$@"
;;
*)
"$@"
;;
esac