|
| 1 | +#! /usr/bin/env bash |
| 2 | + |
| 3 | +set -ex |
| 4 | + |
| 5 | +# This script should be run on the trypurescript server to deploy a new |
| 6 | +# version. It does not attempt to take care of any of the following: |
| 7 | +# |
| 8 | +# - configuration of secrets/credentials |
| 9 | +# - nginx SSL configuration |
| 10 | +# |
| 11 | +# so whenever any of these are needed, they must be done manually. |
| 12 | + |
| 13 | +if [ $(id --user) -ne 0 ] |
| 14 | +then |
| 15 | + echo >&2 "This script must be run as root" |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +trypurescript_version="$1" |
| 20 | + |
| 21 | +if [ "$trypurescript_version" = "" ] |
| 22 | +then |
| 23 | + echo >&2 "Need to provide a version" |
| 24 | + exit 1 |
| 25 | +fi |
| 26 | + |
| 27 | +download_url_base="https://github.com/purescript/trypurescript/releases/download/${trypurescript_version}" |
| 28 | + |
| 29 | +echo "[$(date)] $0: starting trypurescript install" |
| 30 | + |
| 31 | +# set up directories for deploying into |
| 32 | +if [ ! -d /var/www/trypurescript ]; then |
| 33 | + mkdir -p /var/www/trypurescript |
| 34 | + chown -R www-data:www-data /var/www/trypurescript |
| 35 | +fi |
| 36 | + |
| 37 | +# download release |
| 38 | +tmpdir="$(sudo -u www-data mktemp -d)" |
| 39 | +pushd "$tmpdir" |
| 40 | +for component in server client; do |
| 41 | + bundle="trypurescript-${component}.tar.gz" |
| 42 | + sudo -u www-data wget "$download_url_base/${bundle}" |
| 43 | + sudo -u www-data tar xzf "$bundle" -C /var/www/trypurescript --overwrite |
| 44 | +done |
| 45 | +# We install the binary to a location outside of /var/www/trypurescript so that we |
| 46 | +# can extract tar.gz files into /var/www/trypurescript safely in future deploys. |
| 47 | +install /var/www/trypurescript/trypurescript /usr/local/bin/trypurescript |
| 48 | +popd |
| 49 | +rm -r "$tmpdir" |
| 50 | + |
| 51 | +# install nginx config |
| 52 | +cp /var/www/trypurescript/deploy/nginx.conf /etc/nginx/sites-enabled/trypurescript.conf |
| 53 | +systemctl reload nginx |
| 54 | + |
| 55 | +# install systemd service confing |
| 56 | +cp /var/www/trypurescript/deploy/trypurescript.service /etc/systemd/system/trypurescript.service |
| 57 | +systemctl daemon-reload |
| 58 | +systemctl restart trypurescript.service |
| 59 | + |
| 60 | +echo "[$(date)] $0: done trypurescript install" |
0 commit comments