-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.sh
executable file
·80 lines (63 loc) · 1.65 KB
/
upload.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
#!/usr/bin/env bash
# This script can be used to upload files to a Harambe server
# Usage: ./upload.sh <file_path>
# Example: ./upload.sh /path/to/file.jpg
# -------------------------------
URL="https://someurl.com"
USERNAME="someusername"
PASSWORD="somepassword"
ENDPOINT="apiupload"
# -------------------------------
# Resolve the full path of the file
FILE_PATH="$1"
# Prompt for title or not
MODE="${2:-normal}"
# Remove "file://" prefix if present
if [[ "$FILE_PATH" == file://* ]]; then
FILE_PATH="${FILE_PATH#file://}"
fi
# Convert to absolute path
FILE_PATH=$(realpath "$FILE_PATH")
if [ -z "$URL" ]; then
echo "Error: URL is not set"
exit 1
fi
if [ -z "$FILE_PATH" ]; then
echo "Error: FILE_PATH is not set"
exit 1
fi
if [ -z "$USERNAME" ]; then
echo "Error: USERNAME is not set"
exit 1
fi
if [ -z "$PASSWORD" ]; then
echo "Error: PASSWORD is not set"
exit 1
fi
# Prompt to get the title
if [ "$MODE" == "title" ]; then
title=$(zenity --entry --title="Harambe Upload" --text="Enter a title:")
if [ $? -ne 0 ]; then
echo "User cancelled the input."
exit 1
fi
else
title=""
fi
echo "Uploading: $FILE_PATH"
# Make the POST request and capture the response
RESPONSE=$(curl -s -X POST "$URL/$ENDPOINT" \
-F "file=@\"${FILE_PATH}\"" \
-F "title=\"${title}\"" \
-F "username=\"${USERNAME}\"" \
-F "password=\"${PASSWORD}\"" \
)
# Check if the response starts with "file/"
if [[ "$RESPONSE" == post/* ]]; then
FULL_URL="${URL}/${RESPONSE}"
echo -n "$FULL_URL" | xclip -selection clipboard
echo "URL Copied: $FULL_URL"
awesome-client 'Utils.msg("Harambe: Upload Complete")'
else
echo $RESPONSE
fi