-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileupload0x0.sh
executable file
·81 lines (70 loc) · 1.8 KB
/
fileupload0x0.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# Default values
file_to_upload=""
remote_url=""
secret=""
expiration_hours=""
# Function to display usage instructions
usage() {
echo "Usage: $0 [options]"
echo "Options:"
echo " -f, --file <file_path> Upload a local file."
echo " -u, --url <remote_url> Upload a remote URL."
echo " -s, --secret <secret_key> Set a secret key for the upload."
echo " -e, --expires <hours> Set expiration time in hours."
echo " -h, --help Display this help message."
exit 1
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-f|--file)
file_to_upload="$2"
shift 2
;;
-u|--url)
remote_url="$2"
shift 2
;;
-s|--secret)
secret="$2"
shift 2
;;
-e|--expires)
expiration_hours="$2"
shift 2
;;
-h|--help)
usage
;;
*)
echo "Invalid option: $1"
usage
;;
esac
done
# Check if at least one of file or URL is provided
if [ -z "$file_to_upload" ] && [ -z "$remote_url" ]; then
echo "Error: You must provide either a local file or a remote URL to upload."
usage
fi
# Upload a file or remote URL with optional secret and expiration
upload() {
local url="http://0x0.st"
local args=()
if [ -n "$file_to_upload" ]; then
args+=("-Ffile=@$file_to_upload")
elif [ -n "$remote_url" ]; then
args+=("-Furl=$remote_url")
fi
if [ -n "$secret" ]; then
args+=("-Fsecret=")
fi
if [ -n "$expiration_hours" ]; then
args+=("-Fexpires=$expiration_hours")
fi
curl "${args[@]}" "$url"
}
# Main upload function
upload