-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinit.sh
executable file
·145 lines (122 loc) · 3.02 KB
/
init.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
#!/usr/bin/env bash
client_dir=src/client
jar_path=target/tus-spring-boot-1.0-SNAPSHOT.jar
settings=$M2_HOME/conf/settings.xml
function print_help {
local msg="This is the init script for the TusSpringBoot project."
msg="$msg\n[OPTIONS]"
msg="$msg\n--help | help (print this help message)"
msg="$msg\n--clean-mvn (run the app with the 'clean' argument for maven)"
msg="$msg\n--clean-client (run the app with a fresh production build of the reactjs client)"
msg="$msg\n--clean-all (run the app with a fresh build of both the server and the client)"
printf "$msg\n"
}
function check_help {
local opt=$1
case $opt in
"--help" )
print_help
exit 0 ;;
"help" )
print_help
exit 0 ;;
esac
}
function get_client {
git clone [email protected]:cjvirtucio87/tus-spring-boot-client.git $client_dir
}
function build_client {
pushd $client_dir
npm install && \
npm run build && \
popd && \
mv $client_dir/build/ src/main/resources/public/
}
function build_image {
cp $settings .
docker build \
--build-arg HTTP_PROXY=$HTTP_PROXY \
--build-arg HTTP_PROXY_PORT=$HTTP_PROXY_PORT \
-t tus-spring-boot .
}
function run_container {
docker run -p 8080:8080 -t --name=tus-spring-boot tus-spring-boot
}
function build_app {
local opt=$1
case $opt in
"--clean-mvn" )
mvn clean install ;;
"--clean-client" )
build_client && mvn install ;;
"--clean-all" )
build_client && mvn clean install ;;
"" )
echo "No option passed. Running the application." ;;
* )
echo "Error! Invalid argument!"
exit 1;
esac
}
function run_app {
java -jar $jar_path
}
function main {
local opt=$1
check_help $opt
which docker > /dev/null
if [ $? = 0 ]; then
echo "Docker detected."
echo "Downloading client."
get_client
if [ $? = 0 ]; then
echo "Done."
else
echo "Error! Failed to download client!"
exit 1
fi
echo "Building image."
build_image
if [ $? = 0 ]; then
echo "Done."
echo "Running tus-spring-boot. Cheers!"
rm settings.xml
rm -rf $client_dir
run_container
else
echo "Error! Failed to build the image."
exit 1
fi
else
echo "Docker not detected."
if [ ! -d "src/main/resources/public" ]; then
if [ ! -f "$jar_path" ]; then
echo "Creating build for first-time run."
opt="--clean-all"
elif [ "$opt" == "--clean-mvn" ]; then
echo "No client code in the resources folder. Building client code, first."
opt="--clean-all"
fi
fi
echo "Downloading client."
get_client
if [ $? = 0 ]; then
echo "Done."
else
echo "Error! Failed to download client!"
exit 1
fi
build_app $opt
if [ $? = 0 ]; then
echo "Done."
echo "Running tus-spring-boot. Enjoy!"
rm -rf $client_dir
rm -rf src/main/resources/public
run_app
else
echo "Error! Failed to build the application."
exit 1
fi
fi
}
main $1