From e3aa1f1416e24e40b545a42c38f2568055cb886c Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Tue, 26 Jul 2022 14:51:54 -0400 Subject: Add -w to up --- bin/up.sh | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'bin/up.sh') 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 + + ${warn} + + 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 -- cgit 1.4.1