-
Notifications
You must be signed in to change notification settings - Fork 779
/
Copy pathupload-bundles-wise.sh
executable file
·96 lines (81 loc) · 2.99 KB
/
upload-bundles-wise.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
#!/bin/bash
#set -eu
#set -x
if [ `id -u` -eq 0 ] ; then
echo "ERROR: running as root is not supported"
echo "Please run 'export UID' before running docker-compose!"
exit 1
fi
if [ -z "$WISE_USERNAME" ] ; then
echo "ERROR: WISE_USERNAME is empty"
exit 2
fi
if [ -z "$WISE_PASSWORD" ] ; then
echo "ERROR: WISE_PASSWORD is empty"
exit 2
fi
if [ -z "$WISE_URL" ] ; then
echo "ERROR: WISE_URL is empty"
exit 2
fi
WISE_CLI="nodejs /app/index.js"
BUNDLES=/mnt/AssetBundles
BUNDLES_SOURCES=/mnt/Assets/External
RESULT=0
ASSETS=0
function uploadAssets()
{
local ASSET_FOLDER=$2
local ASSET_PREFIX=$3
local ASSET_TYPE=$4
# we don't need ASSET_IDs here
local ASSET_NAMES=`echo "$1" | awk '{print $2}'`
for ASSET_NAME in $ASSET_NAMES; do
ASSETS=`expr $ASSETS + 1`
# We need to get the name from description.json, because e.g. asset_name SanFrancisco
# when uploaded with current description.json will have a name shown by wise-cli list
# as "San Francisco" and because the extra space, the grep doesn't catch it and
# it's not deleted before upload
ASSET_REAL_NAME=`jq .name ${BUNDLES_SOURCES}/${ASSET_FOLDER}/${ASSET_NAME}/description.json`
echo "INFO: Check if '$ASSET_NAME' asset is already uploaded with the name from description.json: '$ASSET_REAL_NAME'"
# There are already quotes around the asset name from jq output, which is good, because then
# this grep won't so easily match with some other asset which contains ASSET_REAL_NAME as substring
# just add spaces around as well
local ASSET_UID=`$WISE_CLI list -t $ASSET_TYPE | grep " ${ASSET_REAL_NAME} " | awk '{print $1}'`
if [ -n "$ASSET_UID" ]; then
echo "INFO: $ASSET_NAME: Asset already uploaded"
echo "INFO: Removing already uploaded version"
if ! $WISE_CLI delete -t $ASSET_TYPE --id $ASSET_UID; then
echo "ERROR: Failed to delete asset: $ASSET_NAME"
RESULT=`expr $RESULT + 1`
fi
fi
echo "INFO: $ASSET_NAME: Uploading the asset"
if ! $WISE_CLI upload -t $ASSET_TYPE -a ${BUNDLES}/${ASSET_FOLDER}/${ASSET_PREFIX}_${ASSET_NAME} -d ${BUNDLES_SOURCES}/${ASSET_FOLDER}/${ASSET_NAME}/description.json; then
echo "ERROR: Failed to upload asset: $ASSET_NAME"
RESULT=`expr $RESULT + 1`
fi
done
}
echo "INFO: Login into WISE:$WISE_URL just to test if provided username/password works"
if ! $WISE_CLI login --url $WISE_URL; then
echo "ERROR: Failed to login to WISE:$WISE_URL"
exit 1
fi
if [ ! -z ${SIM_ENVIRONMENTS+x} ]; then
uploadAssets "${SIM_ENVIRONMENTS}" Environments environment map
fi
if [ ! -z ${SIM_VEHICLES+x} ]; then
uploadAssets "${SIM_VEHICLES}" Vehicles vehicle vehicle
fi
if [ ! -z ${SIM_SENSORS+x} ]; then
uploadAssets "${SIM_SENSORS}" Sensors sensor plugin
fi
if [ ! -z ${SIM_BRIDGES+x} ]; then
uploadAssets "${SIM_BRIDGES}" Bridges bridge plugin
fi
echo "INFO: ${ASSETS} assets were processed"
if [ "${RESULT}" -ne 0 ] ; then
echo "ERROR: there were ${RESULT} errors while processing them"
fi
exit ${RESULT}