-
Notifications
You must be signed in to change notification settings - Fork 13
/
setup_services.sh
executable file
·69 lines (56 loc) · 1.78 KB
/
setup_services.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
#!/bin/sh
#
# this script sets up the cso2 master server services
# it downloads or builds the required files and installs the required npm dependencies
# pass --build-services as an argument to the script to build the services yourself
#
set -e
SHOULD_BUILD_SERVICES=0
get_latest_build_tag() {
git describe --tags "$(git rev-list --tags --max-count=1)"
}
fetch_service_build_url() {
FETCH_REPO_OWNER=$1
FETCH_REPO_NAME=$2
FETCH_BUILD_TAG=$3
curl -Ls "https://api.github.com/repos/$FETCH_REPO_OWNER/$FETCH_REPO_NAME/releases/tags/$FETCH_BUILD_TAG" |
grep "browser_download_url" |
cut -d '\:' -f 2,3 |
tr -d "\"\ "
}
download_latest_service_build() {
SERVICE_NAME=$1
SERVICE_OWNER=$2
LAST_TAG=$(get_latest_build_tag)
BUILD_URL=$(fetch_service_build_url "$SERVICE_OWNER" "$SERVICE_NAME" "$LAST_TAG")
echo "Downloading $BUILD_URL"
curl -L "$BUILD_URL" | tar -xz
}
handle_submodule() {
SUBMODULE_NAME=$1
SUBMODULE_DIR=$2
cd ./"${SUBMODULE_DIR}"
if [ $SHOULD_BUILD_SERVICES = 0 ]; then
echo "Fetching ${SUBMODULE_NAME}"
download_latest_service_build "$SUBMODULE_NAME" L-Leite
npm i --only=production
elif [ $SHOULD_BUILD_SERVICES = 1 ]; then
echo "Building ${SUBMODULE_NAME}"
npm i
npx gulp build
fi
cd ../
}
for i in "$@"; do
if [ "$i" = "--build-services" ]; then
SHOULD_BUILD_SERVICES=1
echo "The user selected to build services..."
fi
done
if [ $SHOULD_BUILD_SERVICES = 0 ]; then
echo "The user selected to download services prebuilds..."
fi
handle_submodule cso2-master-server master-server
handle_submodule cso2-users-service users-service
handle_submodule cso2-inventory-service inventory-service
handle_submodule cso2-webapp webapp