-
Notifications
You must be signed in to change notification settings - Fork 1
/
upgrade.sh
executable file
·43 lines (37 loc) · 1.06 KB
/
upgrade.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
#!/bin/bash
if [ $# -eq 0 ]
then
echo "Usage: $0 release-name.tar.gz"
exit 0
fi
TARBALL=$1
RELEASE_NAME=$(basename "$TARBALL")
RELEASE_NAME="${RELEASE_NAME%%.*}"
RELEASE_BASE="/data/releases"
RELEASE_DIR="$RELEASE_BASE/$RELEASE_NAME"
# Echo commands
set -x
# shellcheck disable=SC2010,SC2046
mkdir "$RELEASE_DIR" && \
tar xzf "$TARBALL" --directory "$RELEASE_DIR" && \
cd "$RELEASE_DIR" && \
HOME=/tmp npm rebuild --unsafe-perm --build-from-source && \
cp /data/colab/lib/local_settings.js "$RELEASE_DIR/lib/local_settings.js" && \
ln -s -f "$RELEASE_DIR" /data/colab-new && \
mv -T -f /data/colab-new /data/colab && \
sv restart /service/colab && \
echo "Successfully updated to $RELEASE_NAME"
# shellcheck disable=SC2181
if [ $? -ne 0 ]
then
echo "ERROR DEPLOYING! BAILING"
exit 1
fi
# Remove all but the last 5 releases
# shellcheck disable=SC2010
OLD_RELEASES=$(ls -t -1 $RELEASE_BASE | grep -F "colab-" | sed -e '1,5d')
for OLD_RELEASE in $OLD_RELEASES
do
echo "Removing old release: $RELEASE_BASE/$OLD_RELEASE"
rm -fr "${RELEASE_BASE:?}/${OLD_RELEASE:?}"
done