summaryrefslogtreecommitdiff
path: root/deploy
blob: 7c51dbe0b5377fcada201f14a1ae63fa2ef251f4 (plain)
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
#! /bin/sh

# Deploy the static website.
#
# Re-generates the static website from source and asserts a clean working tree
# before uploading the website to the server.

set -o errexit
set -o nounset

# Git root directory
root="$( git rev-parse --show-toplevel )"

# Source directory with a trailing slash for rsync
src="${root}/_site/"

# Git revision
rev="$( git rev-parse --verify HEAD )"

# ISO 8601 timestamp
now="$( date -u "+%Y-%m-%dT%H:%M:%SZ" )"

# Archive file name
archive="./${now}_${rev}.tar.gz"

printf "Re-generating static website from source ...\\n"
( cd "${root}" \
  && stack run -- clean >/dev/null 2>&1 \
  && stack run -- build >/dev/null 2>&1 )

[ -z "$( git status --porcelain )" ] || {
  ( >&2 printf "error: dirty working tree\\n" )
  printf "Aborting deployment due to unstaged changes or untracked files.\\n"
  exit 1
}

tar -czf "${archive}" "${src}"
scp "${archive}" engine.skreutz.com:www-archive/

rsync --rsync-path=openrsync --archive --delete --verbose \
  "${src}" "engine.skreutz.com:/var/www/htdocs/www.skreutz.com"
Generated by cgit. See skreutz.com for my tech blog and contact information.