-
Notifications
You must be signed in to change notification settings - Fork 23
/
deploy.sh
executable file
·34 lines (27 loc) · 1.23 KB
/
deploy.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
#!/bin/bash
#
# Deploy artifacts (e.g. dmg, deb files) built by CI to downloads.mixxx.org.
set -eu -o pipefail
USER=mixxx
HOSTNAME=downloads-hostgator.mixxx.org
DESTDIR=public_html/downloads/builds/buildserver
SSH="ssh -i ${SSH_KEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
DEST_PATH=${DESTDIR}/${GIT_BRANCH}
TMP_PATH=${DESTDIR}/.tmp/${GIT_BRANCH}
echo "Deploying to $TMP_PATH, then to $DEST_PATH."
# Remove permissions for group and other users so that ssh-keygen does not
# complain about the key not being protected.
chmod go-rwx ${SSH_KEY}
# "Unlock" the key by removing its password. This is easier than messing with ssh-agent.
ssh-keygen -p -P ${DOWNLOADS_HOSTGATOR_DOT_MIXXX_DOT_ORG_KEY_PASSWORD} -N "" -f ${SSH_KEY}
# Always upload to a temporary path.
# This prevents users from downloading an incomplete file from the server which has not yet finished deploying.
shopt -s extglob
rsync -e "${SSH}" --rsync-path="mkdir -p ${TMP_PATH} && rsync" -r --delete-after ${FILE_TO_DEPLOY} ${USER}@${HOSTNAME}:${TMP_PATH}
# Move from the temporary path to the final destination.
$SSH ${USER}@${HOSTNAME} << EOF
mkdir -p ${DEST_PATH} &&
mv ${TMP_PATH}/* ${DEST_PATH} &&
rmdir ${TMP_PATH}
EOF