-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload
More file actions
executable file
·57 lines (49 loc) · 1.29 KB
/
upload
File metadata and controls
executable file
·57 lines (49 loc) · 1.29 KB
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
#!/bin/bash
# sudo apt-get install jq
# sudo npm install -g clipboard-cli
endpoint=https://file.io
red='\e[;31m'
green='\e[;32m'
yellow='\e[;33m'
white='\e[m'
help() {
echo "Upload a file to $endpoint."
echo ""
echo "Usage: upload <file>"
echo " file the path of the file needs uploading"
echo ""
echo "Dependencies:"
echo " jq from apt-get"
echo " clipboard-cli from npm (optional)"
}
finish() {
echo -e "${green}Your file is successfully uploaded!${white}"
echo ""
echo " Name: $1"
echo " Size: $2"
echo " Link: $3"
echo " Expires: $4"
echo ""
if [ ! -z $5 ]; then
echo -e "${yellow}P/s: Link has been copied to your clipboard.${white}"
fi
}
error() {
echo -e "${red}Failed!${white}"
exit 1
}
start() {
uploaded=$(curl -s -X POST -F "file=@\"$1\"" "$endpoint")
name=$(echo "$uploaded" | jq -r ".name")
size=$(echo "$uploaded" | jq -r ".size")
link=$(echo "$uploaded" | jq -r ".link")
expires=$(echo "$uploaded" | jq -r ".expires")
copied=
if [ ! -z $link ]; then
[ -L "$(which clipboard)" ] && echo -n "$link" | clipboard && copied=1
finish $name $size $link $expires $copied
else
error
fi
}
[ -f "$(which jq)" ] && [ -f "$1" ] && start $1 || help