Created
February 1, 2021 14:17
-
-
Save MineBartekSA/c82fd4d5eeda3f253b002ece4df40579 to your computer and use it in GitHub Desktop.
LitterBox - A implementation of litterbox.catbox.moe API in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# LitterBox v1.0 | |
# A implelemtation of litterbox.catbox.moe API in Bash | |
# Author: MineBartekSA | |
# Gist: https://gist.github.com/MineBartekSA/c82fd4d5eeda3f253b002ece4df40579 | |
# | |
curl --version >> /dev/null | |
if [ $? -ne 0 ] | |
then | |
echo -e "\e[91mcURL not found!\e[0m" | |
echo "Please check if you have cURL installed on your system" | |
exit 1 | |
fi | |
usage() | |
{ | |
if [ -z $1 ] || [ $1 == "version" ] | |
then | |
echo -e "\e[1mLitterBox\e[0m v1.0" | |
if ! [ -z $1 ]; then exit; fi | |
echo "A implementation of litterbox.catbox.moe API in Bash" | |
echo "" | |
elif [ $1 != "\r" ] | |
then echo -e $1 | |
fi | |
echo -e "Usage: $0 [option] <filename(s)>\n" | |
echo "Options:" | |
echo " -t, --time - Set the expiry time of your file(s) (in hours and only allowed 1, 12, 24, and 72)" | |
echo " -h, --help, --usage - Prints this message" | |
echo " -v, --version - Prints version" | |
} | |
ALLOWED_TIMES=("1h" "12h" "24h" "72h") | |
checkTime() | |
{ | |
if [ $# -eq 0 ] | |
then | |
echo "1h" | |
return | |
fi | |
val=$1 | |
if [[ $val != *h ]] | |
then val+="h" | |
fi | |
if [[ " ${ALLOWED_TIMES[@]} " =~ " ${val} " ]] | |
then echo $val | |
else | |
echo -e "\e[91mInvalid time proided\e[0m" >&2 | |
echo -1 | |
fi | |
} | |
HOST="https://litterbox.catbox.moe/resources/internals/api.php" | |
if [ $# -eq 0 ] || [ $1 == "--usage" ] || [ $1 == "-h" ] || [ $1 == "--help" ] | |
then usage | |
elif [ $1 == "-v" ] || [ $1 == "--version" ] | |
then usage "version" | |
elif ( ( [ $# -eq 1 ] || [ $# -eq 2 ] ) && ( [ $1 == "-t" ] || [ $1 == "--time" ] || [ $1 == "--time=" ] ) ) || ( [ $# -eq 1 ] && [[ $1 == --time=* ]] ) | |
then | |
usage | |
exit 1 | |
else | |
files="" | |
expiry="1h" | |
tn=0 | |
for f in "$@" | |
do | |
if [ $tn -eq 1 ] | |
then | |
expiry=$(checkTime $f) | |
tn=0 | |
elif [ $f == "-t" ] || [ $f == "--time" ] | |
then tn=1 | |
elif [[ $f == --time=* ]] | |
then expiry=$(checkTime $(echo $f | cut -d'=' -f 2)) | |
else | |
if [ "$files" == "" ] | |
then files=$f | |
else files+=" $f" | |
fi | |
fi | |
done | |
if [ "$expiry" == "-1" ] | |
then exit 1 | |
elif [ "$files" == "" ] | |
then | |
echo -e "\e[91mNo files given\e[0m" >&2 | |
exit 1 | |
fi | |
echo "Uploading..." | |
for file in $files | |
do | |
if [ -f "$file" ] || [ -L "$file" ] | |
then | |
name=$(basename -- "$file") | |
echo -en "\e[1m$name\e[0m:\n" | |
link=`curl -F "reqtype=fileupload" -F "time=$expiry" -F "fileToUpload=@$file" $HOST` | |
echo -en "\n" | |
echo -en "Uploaded to: \e[1m$link\n" | |
echo -n $link|xclip -selection clipboard | |
else | |
echo -e "\e[91mFile $file dose not exists!\e[0m" | |
fi | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment