-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·51 lines (44 loc) · 1.85 KB
/
run.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
#!/usr/bin/env bash
set -e
echo APP_NAME ${APP_NAME}
echo VERSION ${VERSION}
echo ENVIRONMENT ${ENVIRONMENT}
echo JAVA_OPTIONS \"${JAVA_OPTIONS:-}\"
echo URL ${URL}
echo WGET_OPTIONS \"${WGET_OPTIONS}\"
echo WGET_USERNAME ${WGET_USERNAME}
echo WGET_PASSWORD $(test ! -z ${WGET_PASSWORD} && echo hidden)
echo AWS_ACCESS_KEY $(test ! -z ${AWS_ACCESS_KEY} && echo hidden)
echo AWS_SECRET_KEY $(test ! -z ${AWS_SECRET_KEY} && echo hidden)
echo AWS_REGION ${AWS_REGION}
echo AWS_BUCKET ${AWS_BUCKET}
echo ""
WGET_COMMON_OPTIONS='-q --timeout=5 -O /home/nm-user/app.jar'
test ! -z ${WGET_USERNAME} && WGET_OPTIONS="${WGET_OPTIONS} --user=${WGET_USERNAME}"
test ! -z ${WGET_PASSWORD} && WGET_OPTIONS="${WGET_OPTIONS} --password=${WGET_PASSWORD}"
APP_COMMON_PATH="${APP_NAME}/${ENVIRONMENT}/${APP_NAME}_${VERSION}.jar"
WGET_RCODE=0
# Default download method
echo "Downloading jar..."
wget ${WGET_COMMON_OPTIONS} ${WGET_OPTIONS} ${URL}/${APP_COMMON_PATH} || WGET_RCODE=$?
# Fallback download method
if [ $WGET_RCODE != 0 ] ; then
echo "Using alternative solution to download app"
contentType="text/html; charset=UTF-8"
date="`date -u +'%a, %d %b %Y %H:%M:%S GMT'`"
resource="/${AWS_BUCKET}/${APP_COMMON_PATH}"
string="GET\n\n${contentType}\n\nx-amz-date:${date}\n${resource}"
signature=`echo -en $string | openssl sha1 -hmac "${AWS_SECRET_KEY}" -binary | base64`
WGET_RCODE=0
wget ${WGET_COMMON_OPTIONS} \
--header "x-amz-date: ${date}" \
--header "Content-Type: ${contentType}" \
--header "Authorization: AWS ${AWS_ACCESS_KEY}:${signature}" \
"https://s3-${AWS_REGION}.amazonaws.com${resource}" || WGET_RCODE=$?
if [ $WGET_RCODE != 0 ] ; then
echo "Can't find the required app version in any location"
exit 1
fi
fi
echo "Launching jar..."
su - nm-user -c "java ${JAVA_OPTIONS} -jar /home/nm-user/app.jar"