This repository has been archived by the owner on Jun 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
build1.sh
executable file
·221 lines (189 loc) · 4.32 KB
/
build1.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env bash
#project dir
prj_dir=pwd
build_script="build1.sh"
agent_base_name="agent"
server_base_name="hawkcd"
version="0.0.5"
#save to a file the latest commit
git show > rev.txt
arg1=$1
if [[ -z $2 ]]; then
revision="alpha.xx"
else
revision="alpha."$2
fi
agent_artifact="$agent_base_name-$version-$revision.jar"
server_artifact="$server_base_name-$version-$revision.jar"
echo "Arguments: $arg1 , $revision "
echo "Agent Artifact: $agent_artifact"
echo "Server Artifact: $server_artifact"
#utill
function clean {
#clean up dist folder
if [ -d "dist" ]; then
rm -rf dist
exit_on_fail
fi
}
function _init {
#create install image folder
if [ ! -d "dist" ]; then
mkdir dist
cd dist
mkdir Agent
mkdir Server
cd ../
fi
}
function exit_on_fail {
if [ $? -eq 0 ]
then
echo "Successfully completed"
else
echo "Error building" >&2
exit 1;
fi
}
if [ ! -f "$build_script" ]; then
echo "error: build script: $build_script does not exist in the current dir"
exit 1
fi
# initilize
_init
function compile_agent {
echo "building the agent.."
rm -rf $($prj_dir)/dist/Agent/*
#cd Agent
gradle -b $($prj_dir)/Agent/build.gradle clean
gradle -b $($prj_dir)/Agent/build.gradle -Pbase_Name="$agent_base_name" -PbuildVersion="$version" -Prevision="$revision" build -x test
cp $($prj_dir)/rev.txt dist/Agent
cp $($prj_dir)/Agent/agent.sh dist/Agent
sed -i "s/<replace>/$agent_base_name-$version-$revision/g" $($prj_dir)/dist/Agent/agent.sh
cp "$($prj_dir)/Agent/build/libs/$agent_artifact" dist/Agent
exit_on_fail
}
function run_agent_unit_test {
echo "building the agent.."
gradle -b $($prj_dir)/Agent/build.gradle test
exit_on_fail
}
function package_agent_nix {
echo "packaging agent.."
rm -rf $($prj_dir)/dist/hawkcd-agent.tar.gz
cd dist
tar -cvzf hawkcd-agent.tar.gz Agent
cd ../
exit_on_fail
}
function package_agent_win {
echo "to be implemented"
}
function build_ui {
if [ -d "$($prj_dir)/Server/src/main/resources/dist" ]; then
rm -rf $($prj_dir)/Server/src/main/resources/dist
exit_on_fail
fi
#npm --prefix ./some_project
#npm --prefix $($prj_dir)/Server/ui install
exit_on_fail
cd $($prj_dir)/Server/ui
npm install
bower install
exit_on_fail
gulp build
exit_on_fail
cd ../../
}
function compile_server {
build_ui
echo "building the server.."
rm -rf $($prj_dir)/dist/Server/*
#cd Agent
gradle -b $($prj_dir)/Server/build.gradle clean
gradle -b $($prj_dir)/Server/build.gradle -Pbase_Name="$server_base_name" -PbuildVersion="$version" -Prevision="$revision" build -x test
echo "$prj_dir"
cp $($prj_dir)/rev.txt dist/Server
cp "$($prj_dir)/Server/build/libs/$server_artifact" dist/Server
cp $($prj_dir)/Server/hawkcd.sh dist/Server
sed -i "s/<replace>/$server_base_name-$version-$revision/g" $($prj_dir)/dist/Server/hawkcd.sh
exit_on_fail
}
function run_server_unit_test {
#statements
echo "running server tests.."
gradle -b $($prj_dir)/Server/build.gradle test
exit_on_fail
}
function package_server_win {
echo pwd
}
function package_server_nix {
#statements
cd $($prj_dir)/dist/Server
wget http://www.hawkcd.io/downloads/dependences/redis.tar.gz
tar zxvf redis.tar.gz
rm redis.tar.gz
cd ..
#package
tar -cvzf hawkcd.tar.gz Server
cd ../
exit_on_fail
}
function build_all {
compile_agent
run_agent_unit_test
package_agent_nix
compile_server
#run_server_unit_test
package_server_nix
}
function list {
echo "usage: ./build.sh <command> "
echo
echo " run_agent_unit_test"
echo " package_agent_nix"
echo " package_agent_win"
echo " compile_server"
echo " build_ui"
echo " run_server_unit_test"
echo " package_server_nix"
echo " package_server_win"
echo " build_all"
echo
}
case "$arg1" in
"compile_agent")
compile_agent
;;
"run_agent_unit_test")
run_agent_unit_test
;;
"package_agent_nix")
package_agent_nix
;;
"package_agent_win")
package_agent_win
;;
"compile_server")
compile_server
;;
"build_ui")
build_ui
;;
"run_server_unit_test")
run_server_unit_test
;;
"package_server_nix")
package_server_nix
;;
"package_server_win")
package_server_nix
;;
"build_all")
"build_all"
;;
*)
"list"
;;
esac