diff options
Diffstat (limited to 'bin/up.sh')
-rw-r--r-- | bin/up.sh | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/bin/up.sh b/bin/up.sh index cebc29c4..6305b1ee 100644 --- a/bin/up.sh +++ b/bin/up.sh @@ -4,21 +4,32 @@ set -eu readonly Host='temp.causal.agency' readonly Root='/var/www' +temp= +temp() { + temp=$(mktemp -d) + trap 'rm -r "$temp"' EXIT +} + +warn= upload() { src=$1 ext=${src##*.} - ts=$(date +'%s') - rand=$(openssl rand -hex 4) - url=$(printf '%s/%x%s.%s' "$Host" "$ts" "$rand" "$ext") + name=$(printf '%x%s' "$(date +%s)" "$(openssl rand -hex 4)") + url="${Host}/${name}.${ext}" scp -q "$src" "${Host}:${Root}/${url}" + if test -n "$warn"; then + test -n "$temp" || temp + cat >"${temp}/warn.html" <<-EOF + <!DOCTYPE html> + <title>${warn}</title> + <meta http-equiv="refresh" content="0;url=${name}.${ext}"> + EOF + url="${Host}/${name}.html" + scp -q "${temp}/warn.html" "${Host}:${Root}/${url}" + fi echo "https://${url}" } -temp() { - temp=$(mktemp -d) - trap 'rm -r "$temp"' EXIT -} - uploadText() { temp cat >"${temp}/input.txt" @@ -64,12 +75,13 @@ uploadTerminal() { upload "${temp}/term.html" } -while getopts 'chst' opt; do +while getopts 'chstw:' opt; do case $opt in (c) fn=uploadCommand;; (h) fn=uploadHilex;; (s) fn=uploadScreen;; (t) fn=uploadTerminal;; + (w) warn=$OPTARG;; (?) exit 1;; esac done |