aboutsummaryrefslogtreecommitdiff
path: root/bin/tmp
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-01-08 19:53:41 -0300
committerEuAndreh <eu@euandre.org>2022-01-08 19:53:41 -0300
commitcb555bb896a13214408a2e79176ca54e5d2c91e4 (patch)
tree3de54b7b126a00c908d552645496a4a1af2e42f3 /bin/tmp
parentTODOs.md: Add #td-d985f05d-3ecb-fc43-986b-b7089d17515d (diff)
downloadeuandre.org-cb555bb896a13214408a2e79176ca54e5d2c91e4.tar.gz
euandre.org-cb555bb896a13214408a2e79176ca54e5d2c91e4.tar.xz
bin/tmp: Add helper script for uploading temporary files
Diffstat (limited to 'bin/tmp')
-rwxr-xr-xbin/tmp74
1 files changed, 74 insertions, 0 deletions
diff --git a/bin/tmp b/bin/tmp
new file mode 100755
index 0000000..712640d
--- /dev/null
+++ b/bin/tmp
@@ -0,0 +1,74 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ tmp FILE...
+ tmp -d
+ tmp -h
+EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -d delete the remote "tmp/" folder
+ -h, --help show this message
+EOF
+}
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+TLD='euandre.org'
+REMOTE_TMP='/home/user-data/www/default/tmp/'
+while getopts 'dh' flag; do
+ case "$flag" in
+ d)
+ printf 'Deleting %s/:%s...\n' "$TLD" "$REMOTE_TMP" >&2
+ ssh "$TLD" rm -rf "$REMOTE_TMP"
+ exit
+ ;;
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+if [ -z "${1:-}" ]; then
+ usage >&2
+ exit 2
+fi
+
+for f in "$@"; do
+ FILENAME="$(basename "$f")"
+ # shellcheck disable=2029
+ ssh "$TLD" "mkdir -p $REMOTE_TMP && cat > $REMOTE_TMP$FILENAME" < "$f"
+
+ LINK="$(printf 'https://%s/tmp/%s' "$TLD" "$FILENAME")"
+ open "$LINK"
+ if [ $# = 1 ]; then
+ printf '%s' "$LINK" | copy
+ printf 'Copied %s to the clipboard!\n' "$LINK" >&2
+ fi
+done