44 lines
1.2 KiB
Bash
Executable file
44 lines
1.2 KiB
Bash
Executable file
#!/bin/sh
|
|
base=${1%.*}
|
|
baseName=$(basename "$1")
|
|
ext=${baseName##*.}
|
|
variable=$(openssl rand -hex 8)
|
|
REMOTE_NAME=remote
|
|
REMOTE_PATH=/var/www/html/images #this is the path the file will be uploaded to
|
|
REMOTE_URL=https://example.org/images #no / at end
|
|
MAX_COLLISSIONS=5
|
|
|
|
if [ ! -f "$1" ]; then
|
|
kdialog --passivepopup "No File!" 5
|
|
exit
|
|
fi
|
|
|
|
i=1
|
|
|
|
while [ -f "$1" ]
|
|
do
|
|
|
|
rclone moveto "$1" "$REMOTE_NAME":"$REMOTE_PATH/$variable.$ext" -v --ignore-existing # ignore existing in case the file already exists
|
|
|
|
if [ -e "$1" ] && [ "$i" -lt $MAX_COLLISSIONS ]; then # if the file is still at $1 we must've gotten some kind of error, we assume its a Collision
|
|
kdialog --sorry "Collision $i"
|
|
i=$((i+1))
|
|
variable=$(openssl rand -hex 8)
|
|
elif [ "$i" -gt $((MAX_COLLISSIONS-1)) ]; then
|
|
kdialog --error "Too many collisions, file still exists at $1. Attempts: $i"
|
|
exit
|
|
fi
|
|
|
|
|
|
done
|
|
|
|
|
|
if [ "$XDG_SESSION_TYPE" == "x11" ]; then
|
|
echo "$REMOTE_URL/$variable.$ext" | xclip -selection clipboard
|
|
else
|
|
wl-copy "$REMOTE_URL/$variable.$ext" &> /dev/null
|
|
fi
|
|
|
|
kdialog --passivepopup "Uploaded! $REMOTE_URL/$variable.$ext" 5
|
|
ffplay /usr/share/sounds/freedesktop/stereo/service-login.oga -hide_banner -autoexit -nodisp
|
|
|