Skip to content

Commit 6094bcb

Browse files
robkooperlmarini
andauthored
fix update script (#75)
* fix update script * update CHANGELOG Co-authored-by: Luigi Marini <[email protected]>
1 parent 15f9332 commit 6094bcb

File tree

2 files changed

+74
-17
lines changed

2 files changed

+74
-17
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
### Fixed
1313
- proxy will no correctly handle paths that end with a / at the end.
1414

15+
### CHanged
16+
- updated update-clowder script to work with migration to github
17+
1518
## 1.11.0 - 2020-08-31
1619

1720
### Added

scripts/ubuntu/update-clowder.sh

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,77 @@
11
#!/bin/bash
22

3-
# CATS-CORE is the main branch for this server
4-
CLOWDER_BRANCH=${CLOWDER_BRANCH:-"CATS-CORE"}
5-
CLOWDER_BUILD=${CLOWDER_BUILD:-"latestSuccessful"}
3+
# what version ("" == latest release)
4+
CLOWDER_BRANCH=${CLOWDER_BRANCH:-}
5+
#CLOWDER_BRANCH="develop"
6+
7+
# compute some other variables
8+
if [ "${CLOWDER_BRANCH}" = "" ]; then
9+
CLOWDER_VERSION=$(curl -s https://opensource.ncsa.illinois.edu/projects/artifacts.php?key=CATS | grep '<option selected>' | sed 's#.*<option.*>\([0-9\.]*\)</option>#\1#')
10+
CLOWDER_ZIPFILE=clowder-${CLOWDER_VERSION}.zip
11+
else
12+
CLOWDER_VERSION="${CLOWDER_BRANCH}"
13+
CLOWDER_ZIPFILE=clowder-${CLOWDER_VERSION}-${CLOWDER_BRANCH}.zip
14+
fi
15+
16+
# Should text go to stdout, empty is not
17+
STDOUT="YES"
18+
19+
# HipChat token for notifications
20+
HIPCHAT_TOKEN=""
21+
HIPCHAT_ROOM=""
22+
23+
# Slack token for notifications
24+
SLACK_TOKEN=""
25+
SLACK_CHANNEL="#simpl-ops"
26+
27+
# MSTeams Webhook
28+
MSTEAMS_URL=""
629

730
# change to folder where script is installed
831
cd /home/clowder
932

1033
# fetch software
11-
if [[ ${CLOWDER_BUILD} == latest* ]]; then
12-
BB="${CLOWDER_BRANCH}/${CLOWDER_BUILD}"
34+
if [ -e ]; then
35+
curl -f -s -z "${CLOWDER_ZIPFILE}" -o "${CLOWDER_ZIPFILE}" https://opensource.ncsa.illinois.edu/projects/artifacts/CATS/${CLOWDER_VERSION}/files/${CLOWDER_ZIPFILE} || exit 1
1336
else
14-
BB="${CLOWDER_BRANCH}-${CLOWDER_BUILD}"
37+
curl -f -s -o "${CLOWDER_ZIPFILE}" https://opensource.ncsa.illinois.edu/projects/artifacts/CATS/${CLOWDER_VERSION}/files/${CLOWDER_ZIPFILE} || exit 1
1538
fi
16-
URL="https://opensource.ncsa.illinois.edu/bamboo/browse/${BB}/artifact/shared/dist/"
17-
/usr/bin/wget -q -e robots=off -A "clowder-*.zip" -nd -r -N -l1 ${URL}
18-
LATEST=$( /bin/ls -1rt clowder-*.zip | tail -1 )
1939

20-
if [ -s ${LATEST} ]; then
21-
if [ "$1" == "--force" -o ${LATEST} -nt clowder ]; then
40+
if [ -s ${CLOWDER_ZIPFILE} ]; then
41+
if [ "$1" == "--force" -o ${CLOWDER_ZIPFILE} -nt clowder ]; then
42+
exec 3>&1
43+
exec &> "/tmp/$$.txt"
44+
2245
echo "UPDATING CLOWDER ON ${HOSTNAME}"
2346
echo " bamboo branch = ${CLOWDER_BRANCH}"
2447

2548
# stop clowder
26-
/sbin/stop clowder
49+
/bin/systemctl stop clowder
2750

2851
# save local modifications
2952
if [ -d clowder/custom ]; then
3053
mv clowder/custom clowder.custom
3154
fi
55+
if [ -d clowder/logs ]; then
56+
mv clowder/logs clowder.logs
57+
fi
3258

3359
# install new version
34-
/bin/rm -rf clowder $( basename ${LATEST} .zip )
35-
/usr/bin/unzip -q ${LATEST}
36-
/bin/mv $( basename ${LATEST} .zip ) clowder
60+
/bin/rm -rf clowder $( basename ${CLOWDER_ZIPFILE} .zip )
61+
/usr/bin/unzip -q ${CLOWDER_ZIPFILE}
62+
/bin/mv $( basename ${CLOWDER_ZIPFILE} .zip ) clowder
3763
/usr/bin/touch clowder
3864

3965
# get some nice values from the build
40-
echo " bamboo build = $( grep '\-Dbuild.bamboo' clowder/bin/clowder | sed 's/.*=\(.*\)"$/\1/' )"
66+
echo " github build = $( grep '\-Dbuild.bamboo' clowder/bin/clowder | sed 's/.*=\(.*\)"$/\1/' )"
4167
echo " clowder version = $( grep '\-Dbuild.version' clowder/bin/clowder | sed 's/.*=\(.*\)"$/\1/' )"
4268
echo " clowder branch = $( grep '\-Dbuild.branch' clowder/bin/clowder | sed 's/.*=\(.*\)"$/\1/' )"
4369
echo " clowder gitsha1 = $( grep '\-Dbuild.gitsha1' clowder/bin/clowder | sed 's/.*=\(.*\)"$/\1/' )"
4470

4571
# restore local modifications
72+
if [ -d clowder.logs ]; then
73+
mv clowder.logs clowder/logs
74+
fi
4675
if [ -d clowder.custom ]; then
4776
mv clowder.custom clowder/custom
4877
fi
@@ -56,6 +85,31 @@ if [ -s ${LATEST} ]; then
5685
fi
5786

5887
# start clowder again
59-
/sbin/start clowder
88+
/bin/systemctl start clowder
89+
90+
# send message by hipchat
91+
if [ "${HIPCHAT_TOKEN}" != "" -a "${HIPCHAT_ROOM}" != "" ]; then
92+
url="https://hipchat.ncsa.illinois.edu/v1/rooms/message?format=json&auth_token=${HIPCHAT_TOKEN}"
93+
txt=$(cat /tmp/$$.txt | sed 's/ /%20/g;s/!/%21/g;s/"/%22/g;s/#/%23/g;s/\$/%24/g;s/\&/%26/g;s/'\''/%27/g;s/(/%28/g;s/)/%29/g;s/:/%3A/g;s/$/<br\/>/g')
94+
room=$(echo ${HIPCHAT_ROOM} | sed 's/ /%20/g;s/!/%21/g;s/"/%22/g;s/#/%23/g;s/\$/%24/g;s/\&/%26/g;s/'\''/%27/g;s/(/%28/g;s/)/%29/g;s/:/%3A/g')
95+
body="room_id=${room}&from=clowder&message=${txt}"
96+
result=$(curl -s -X POST -d "${body}" $url)
97+
fi
98+
if [ "${SLACK_TOKEN}" != "" -a "${SLACK_CHANNEL}" != "" ]; then
99+
url="https://hooks.slack.com/services/${SLACK_TOKEN}"
100+
txt=$(cat /tmp/$$.txt | sed 's/"/\\"/g;s/$/\\/g' | tr '\n' 'n' )
101+
payload="payload={\"channel\": \"${SLACK_CHANNEL}\", \"username\": \"clowder\", \"text\": \"${txt}\", \"icon_url\": \"https://opensource.ncsa.illinois.edu/projects/artifacts/CATS/logo.png\"}"
102+
result=$(curl -s -X POST --data-urlencode "${payload}" $url)
103+
fi
104+
if [ "${MSTEAMS_URL}" != "" ]; then
105+
txt=$(cat /tmp/$$.txt | sed 's/"/\\"/g;s/$/\\/g' | tr '\n' 'n' )
106+
payload="{\"title\": \"UPDATE CLOWDER\", \"text\": \"${txt}\" }"
107+
result=$(curl -s -X POST -H "Content-Type: application/json" -d "${payload}" $MSTEAMS_URL)
108+
fi
109+
if [ "${STDOUT}" != "" ]; then
110+
cat /tmp/$$.txt >&3
111+
fi
112+
rm /tmp/$$.txt
60113
fi
61114
fi
115+

0 commit comments

Comments
 (0)