-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrmUp.sh
executable file
·64 lines (53 loc) · 1.26 KB
/
rmUp.sh
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
#!/bin/bash
scriptname="$(basename "$0")"
# Default options
declare -i verbose=0
# Error function
error() {
echo "Usage: ${scriptname} [-h] [-v] <FILE_NAME>" 1>&2 && exit "$1"
}
help() {
echo "Upload the <FILE_NAME> to the remarkable."
echo "The new file will be placed somewhere, I don't seem to be able to control where..."
echo ""
echo "Syntax: ${scriptname} [-h] [-v] <FILE_NAME>"
echo ""
echo "options:"
echo " -v verbose, only turns on verbose for curl, as there isn't more to this"
echo " -h help, show this message"
}
# Option handling
while getopts ":vh" opt
do
case "${opt}" in
v) verbose=1
;;
h) help
exit 0
;;
\?) error 1
;;
esac
done
shift $((OPTIND - 1))
# Make sure that there is only 1 argument remaining
if (( $# != 1)); then
error 2
fi
# Make sure this argument is a real file
if [[ ! -e "$1" ]]; then
error 3
fi
if (( verbose == 1)); then
curl --connect-timeout 1 "--verbose" \
-H "Content-Type: multipart/form-data" \
-F "file=@$(realpath "$1")" \
"http://10.11.99.1/upload"
else
curl --connect-timeout 1 \
-H "Content-Type: multipart/form-data" \
-F "file=@$(realpath "$1")" \
"http://10.11.99.1/upload"
fi
# Newline cause it's prettier
echo ''