-
-
Save ochen1/46efbeccf618cb4fcae8b859c6bca004 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 - Safe for filenames with spaces | |
# An implementation of litterbox.catbox.moe API in Bash | |
# Author: MineBartekSA (Original Script) | |
# Modified for safer filename handling | |
# Check if cURL is installed | |
if ! command -v curl &> /dev/null; then | |
echo -e "\e[91mcURL not found!\e[0m" | |
echo "Please check if you have cURL installed on your system." | |
exit 1 | |
fi | |
# Function to display usage information | |
usage() { | |
if [ -z "$1" ] || [ "$1" == "version" ]; then | |
echo -e "\e[1mLitterBox\e[0m v1.0" | |
if [ -n "$1" ]; then exit; fi | |
echo "A Bash implementation of litterbox.catbox.moe API." | |
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: 1, 12, 24, 72)" | |
echo " -h, --help, --usage - Prints this message" | |
echo " -v, --version - Prints version" | |
} | |
# Allowed expiry times | |
ALLOWED_TIMES=("1h" "12h" "24h" "72h") | |
# Function to validate the expiry time | |
checkTime() { | |
if [ $# -eq 0 ]; then | |
echo "1h" | |
return | |
fi | |
local val="$1" | |
if [[ $val != *h ]]; then | |
val+="h" | |
fi | |
if [[ " ${ALLOWED_TIMES[@]} " =~ " ${val} " ]]; then | |
echo "$val" | |
else | |
echo -e "\e[91mInvalid time provided\e[0m" >&2 | |
echo -1 | |
fi | |
} | |
HOST="https://litterbox.catbox.moe/resources/internals/api.php" | |
# Parse command-line arguments | |
if [ $# -eq 0 ] || [[ "$1" =~ ^--?(help|usage)$ ]]; then | |
usage | |
exit 0 | |
elif [[ "$1" =~ ^--?(version)$ ]]; then | |
usage "version" | |
exit 0 | |
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 "${f#*=}") | |
else | |
files+=("$f") | |
fi | |
done | |
if [ "$expiry" == "-1" ]; then | |
exit 1 | |
elif [ ${#files[@]} -eq 0 ]; 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 -e "\e[1m$name\e[0m:" | |
link=$(curl -F "reqtype=fileupload" -F "time=$expiry" -F "fileToUpload=@$file" "$HOST") | |
echo -e "\nUploaded to: \e[1m$link\e[0m" | |
echo -n "$link" | xclip -selection clipboard 2>/dev/null || true | |
else | |
echo -e "\e[91mFile '$file' does not exist!\e[0m" | |
fi | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment