Commit Diff


commit - 8b393fbb8bd4a72f243dc7e7b378a3170e56fa06
commit + 4242eafc944ceef1e2748b3698e2a1c93bd246ba
blob - /dev/null
blob + c5cc5df420ac6936532c5be8cad837233828636f (mode 755)
--- /dev/null
+++ publish.sh
@@ -0,0 +1,29 @@
+#!/bin/sh -eu
+fail() { echo "$@" >&2 && exit 1; }
+check_args() {
+	if test "$#" -ne 2; then fail "usage: ${0##*/} <site> <server>"; fi
+	if ! test -d "$1"; then fail "fail: $1 not a directory"; fi
+}
+
+copy_files() { rsync -licr --delete --delete-excluded "$1/" "$2/"; }
+pretty() { grep -Ev '^$|/$' >&2 || :; }
+
+chown_dir() { echo 'chown -R www:staff "'"$1"'"'; }
+hash_dir() {
+	echo 'find "'"$1"'" -type f ! -name ".ssg.src" ! -name ".ssg.dst" -print0 |
+	xargs -0 -n256 sha256 -r | sed "s, '"$1"'/, ," | sort | sha256'
+}
+remote_hash_dir() { (chown_dir "$1" && hash_dir "$1") | ssh -T "$2"; }
+remote_size_dir() { echo 'du -hd0 "'"$1"'" | cut -f1' | ssh -T "$2"; }
+
+main() {
+	check_args "$@"
+	site=$(basename "$1")
+	remote_dir="/var/www/htdocs/${site:?}"
+	copy_files "$1" "$2:$remote_dir" | pretty
+	hash=$(remote_hash_dir "$remote_dir" "$2")
+	size=$(remote_size_dir "$remote_dir" "$2")
+	echo "$hash" "$site" "$2" "$size"
+}
+
+main "$@"
blob - de36dd436456b2978db72130629b068bee1f7647
blob + 2fa134a6e421d5d03dda235f88233894f0ae538a
--- ssg.sh
+++ ssg.sh
@@ -17,7 +17,7 @@
 
 info() { echo "$@" >&2; }
 fail() { echo "$@" >&2 && exit 1; }
-usage() { fail 'usage: '"${0##*/}"' <src> <dst>'; }
+usage() { fail "usage: ${0##*/} <src> <dst>"; }
 
 # exit if less than two arguments
 fail_no_args() { if test $# -ne 2; then usage; fi; }