aboutsummaryrefslogtreecommitdiff
path: root/bin/tmp
blob: 80cadd952a4ad907c940657c750494f98876e264 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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