Skip to content

Instantly share code, notes, and snippets.

@stfnhh
Last active November 1, 2022 02:20
Show Gist options
  • Save stfnhh/76b0e1df901a68c82f6b to your computer and use it in GitHub Desktop.
Save stfnhh/76b0e1df901a68c82f6b to your computer and use it in GitHub Desktop.
Command line interface for file.io
#!/bin/bash
WEEKS=0
ENCRYPTION=false
FILE=$1
usage() {
cat <<EOF
Usage: $0 FILE [options]
-w set amount of weeks until expirary
-m set amount of months until expirary
-y set amount of years until expirary
-e turn encryption on, to decrypt run \`openssl enc -aes-256-cbc -d -in file.txt.enc -out file.txt\`
EOF
}
while getopts :w:m:y:eh opts ${@:2}; do
case ${opts} in
w) WEEKS=${OPTARG} ;;
m) WEEKS=$((${OPTARG}*4)) ;;
y) WEEKS=$((${OPTARG}*52)) ;;
e) ENCRYPTION=true ;;
h)
usage
exit 1;;
\?)
echo "Invalid option: -"$OPTARG"" >&2
exit 1;;
: )
echo "Option -"$OPTARG" requires an argument." >&2
exit 1;;
esac
done
if $ENCRYPTION
then
openssl enc -aes-256-cbc -salt -in $FILE -out "${FILE}.enc"
FILE="${FILE}.enc"
fi
RESULT=$(curl -sSF "file=@$FILE" "https://file.io?expires=${WEEKS}w")
STATUS=$(echo $RESULT | jq .success | tr -d '"')
if $ENCRYPTION
then
rm $FILE
fi
if [ "$STATUS" = "true" ]
then
KEY=$(echo $RESULT | jq .key | tr -d '"')
EXPIRES=$(echo $RESULT | jq .expiry | tr -d '"')
if [ $WEEKS -gt 0 ]
then
echo "Expires in ${EXPIRES}"
fi
echo "https://file.io/${KEY}"
else
ERROR=$(echo $RESULT | jq .error | tr -d '"')
echo "ERROR ${ERROR}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment