Blame


1 4242eafc 2026-01-22 hi #!/bin/sh -eu
2 4242eafc 2026-01-22 hi fail() { echo "$@" >&2 && exit 1; }
3 4242eafc 2026-01-22 hi check_args() {
4 4242eafc 2026-01-22 hi if test "$#" -ne 2; then fail "usage: ${0##*/} <site> <server>"; fi
5 4242eafc 2026-01-22 hi if ! test -d "$1"; then fail "fail: $1 not a directory"; fi
6 4242eafc 2026-01-22 hi }
7 4242eafc 2026-01-22 hi
8 4242eafc 2026-01-22 hi copy_files() { rsync -licr --delete --delete-excluded "$1/" "$2/"; }
9 4242eafc 2026-01-22 hi pretty() { grep -Ev '^$|/$' >&2 || :; }
10 4242eafc 2026-01-22 hi
11 4242eafc 2026-01-22 hi chown_dir() { echo 'chown -R www:staff "'"$1"'"'; }
12 4242eafc 2026-01-22 hi hash_dir() {
13 4242eafc 2026-01-22 hi echo 'find "'"$1"'" -type f ! -name ".ssg.src" ! -name ".ssg.dst" -print0 |
14 4242eafc 2026-01-22 hi xargs -0 -n256 sha256 -r | sed "s, '"$1"'/, ," | sort | sha256'
15 4242eafc 2026-01-22 hi }
16 4242eafc 2026-01-22 hi remote_hash_dir() { (chown_dir "$1" && hash_dir "$1") | ssh -T "$2"; }
17 4242eafc 2026-01-22 hi remote_size_dir() { echo 'du -hd0 "'"$1"'" | cut -f1' | ssh -T "$2"; }
18 4242eafc 2026-01-22 hi
19 4242eafc 2026-01-22 hi main() {
20 4242eafc 2026-01-22 hi check_args "$@"
21 4242eafc 2026-01-22 hi site=$(basename "$1")
22 4242eafc 2026-01-22 hi remote_dir="/var/www/htdocs/${site:?}"
23 4242eafc 2026-01-22 hi copy_files "$1" "$2:$remote_dir" | pretty
24 4242eafc 2026-01-22 hi hash=$(remote_hash_dir "$remote_dir" "$2")
25 4242eafc 2026-01-22 hi size=$(remote_size_dir "$remote_dir" "$2")
26 4242eafc 2026-01-22 hi echo "$hash" "$site" "$2" "$size"
27 4242eafc 2026-01-22 hi }
28 4242eafc 2026-01-22 hi
29 4242eafc 2026-01-22 hi main "$@"