-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprepareEnvironment.sh
More file actions
executable file
·101 lines (86 loc) · 3.02 KB
/
prepareEnvironment.sh
File metadata and controls
executable file
·101 lines (86 loc) · 3.02 KB
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
#!/bin/bash
################################################################################
# This tool prepares a self-contained SDK environment for metaphactory,
# i.e. it retrieves and copies all necessary files and scripts into the current
# directory.
# Run "./prepareEnvironment.sh -h" to see usage.
################################################################################
METAPHACTORY_DOCKER_IMAGE=metaphacts/metaphactory:5.11.0
TIMESTAMP="$(date +%s)"
CONTAINER_NAME="metaphactory-sdk-${TIMESTAMP}"
TEMP_FOLDER="./tmp/${CONTAINER_NAME}"
SDK_FOLDER="./.sdk"
while getopts "fhi:" option; do
case $option in
f) # force mode
FORCE="yes"
;;
h) # help/usage
echo "Usage: $0 [OPTIONS]"
echo "OPTIONS:"
echo "-f force update of SDK, even if the metaphactory version did not change"
echo "-h display this help"
echo "-i <image> use custom docker image, default: ${METAPHACTORY_DOCKER_IMAGE}"
echo "Examples:"
echo " - with custom docker image: \"$0 -i ${METAPHACTORY_DOCKER_IMAGE}\""
exit 0
;;
i) # custom image
METAPHACTORY_DOCKER_IMAGE="${OPTARG}"
;;
esac
done
# If force mode is not active check for new version
if [ -z "${FORCE}" ]
then
if [ -e "./metaphactory-release" ] && [ "$(cat ./metaphactory-release)" == "SDK created from ${METAPHACTORY_DOCKER_IMAGE}" ]
then
SAME_VERSION="yes"
fi
# Exit script if the SDK folder already exists and there is no new version
if [ -e "${SDK_FOLDER}" ] && [ -n "${SAME_VERSION}" ]
then
echo "SDK folder \"${SDK_FOLDER}\" already exists, skipping SDK setup. To update the SDK, please delete this folder."
exit 0
fi
fi
# Create the container temporarily to extract data
docker create --name "${CONTAINER_NAME}" "${METAPHACTORY_DOCKER_IMAGE}" > /dev/null
if [ $? -ne 0 ]
then
echo "Failed to create metaphactory container"
exit 1
fi
# Copy SDK from container and unzip it
docker cp "${CONTAINER_NAME}:/sdk/sdk.zip" "./sdk.zip" > /dev/null
if [ $? -ne 0 ]
then
echo "Failed to extract SDK from metaphactory container"
docker rm "${CONTAINER_NAME}" > /dev/null
exit 1
fi
mkdir -p "${TEMP_FOLDER}"
unzip "./sdk.zip" -d "${TEMP_FOLDER}" > /dev/null
cp -rf "${TEMP_FOLDER}/sdk/." .
rm -r "${TEMP_FOLDER}"
rm "./sdk.zip"
echo "SDK created from ${METAPHACTORY_DOCKER_IMAGE}" > metaphactory-release
cat metaphactory-release
# Copy metaphactory WAR file from container
if [ -e "./metaphactory-release.war" ]
then
rm "./metaphactory-release.war"
fi
docker cp "${CONTAINER_NAME}:/var/lib/jetty/webapps/ROOT.war" "./metaphactory-release.war" > /dev/null
# Remove temporary container
docker rm "${CONTAINER_NAME}" > /dev/null
# Only overwrite gradle.properties if it doesn't exist or force mode is active
if [ ! -e "./gradle.properties" ] || [ -n "${FORCE}" ]
then
sed "s/platformLocation=.*/platformLocation=.\/metaphactory-release.war/" gradle.properties.template > gradle.properties
echo "Created/updated gradle.properties from template"
else
echo "Keeping existing gradle.properties (use -f to force update)"
fi
rm gradle.properties.template
./gradlew prepareEnvironment