streaming-website/deploy.sh

78 lines
2.2 KiB
Bash
Raw Normal View History

2021-10-14 12:22:06 +00:00
#!/usr/bin/env bash
2016-10-12 07:35:01 +00:00
if [ "$1" != '--without-validation' ]; then
2024-03-24 13:52:06 +00:00
for cmd in find xargs php git python3; do
2024-03-24 13:41:03 +00:00
command -v $cmd >/dev/null 2>&1 || { echo >&2 "I require $cmd but it's not installed. Aborting."; exit 1; }
done
2024-03-24 13:41:03 +00:00
find . -name "*.php" | grep -v archive | xargs -n1 php -l
2024-03-24 13:52:06 +00:00
find configs/conferences/ -name "*.json" | xargs -n1 python3 -m json.tool > /dev/null
2024-03-24 13:41:03 +00:00
if [ $? -ne 0 ]; then
echo "not deploying b0rken code ;)"
exit 1
fi
2016-10-12 07:35:01 +00:00
fi
2024-03-24 13:41:03 +00:00
echo
DEPLOY_BRANCH=`git rev-parse --abbrev-ref HEAD`
2016-12-29 12:51:53 +00:00
# Fetch all remotes so we know what's actually on there. This is helpful
# if people have configured gitolite and github.
git fetch --all
2024-03-24 13:41:03 +00:00
echo
2016-12-29 12:51:53 +00:00
if [ `git rev-parse --verify origin/$DEPLOY_BRANCH` != `git rev-parse --verify $DEPLOY_BRANCH` ]; then
2024-03-24 13:41:03 +00:00
echo "You have commits on the $DEPLOY_BRANCH branch not pushed to origin yet. They would not be deployed."
echo "do you still which to deploy what's already in the repo? then type yes"
read -p "" input
if [ "x$input" != "xyes" ]; then
exit 2
fi
echo ""
fi
2016-12-29 12:51:53 +00:00
if ! (git diff --exit-code >/dev/null && git diff --cached --exit-code >/dev/null); then
2024-03-24 13:41:03 +00:00
echo "You have uncomitted changes. They would not be deployed."
echo "do you still which to deploy what's already in the repo? then type yes"
read -p "" input
if [ "x$input" != "xyes" ]; then
exit 2
fi
echo ""
fi
2016-12-29 12:51:53 +00:00
if [ "x$DEPLOY_BRANCH" != "xmaster" ]; then
2024-03-24 13:41:03 +00:00
echo "You're currently on branch $DEPLOY_BRANCH."
echo "Are you sure you want to deploy that branch (and not master)? then type yes"
read -p "" input
if [ "x$input" != "xyes" ]; then
exit 2
fi
echo ""
fi
2022-04-09 14:45:25 +00:00
for host in lb.alb.c3voc.de lb.dort.c3voc.de lb.wob.c3voc.de; do
2016-12-24 16:32:25 +00:00
echo "deploying to $host"
2021-04-06 17:44:22 +00:00
ssh voc@$host 'sudo sh' << EOT
2016-10-01 16:06:44 +00:00
cd /srv/nginx/streaming-website
2016-12-28 16:36:05 +00:00
echo "updating code"
2016-10-01 16:06:44 +00:00
git fetch origin
git reset --hard HEAD
git checkout $DEPLOY_BRANCH
git reset --hard origin/$DEPLOY_BRANCH
2016-12-28 16:36:05 +00:00
echo "fixing permissions"
2016-10-01 16:06:44 +00:00
chown -R voc:staff .
chown -R downloader configs
2016-12-28 16:36:05 +00:00
echo "re-downloading schedules"
sudo -udownloader php index.php download
echo "clearing cache"
2016-10-12 07:31:23 +00:00
./clear_cache
2016-10-01 16:06:44 +00:00
EOT
2016-12-24 16:32:25 +00:00
echo "deploying to $host done"
done