Skip to content

Instantly share code, notes, and snippets.

@brockers
Created October 8, 2014 21:03
Show Gist options
  • Save brockers/e8d555941c0bbc2dbb12 to your computer and use it in GitHub Desktop.
Save brockers/e8d555941c0bbc2dbb12 to your computer and use it in GitHub Desktop.
A brash script to upload, encrpyt, and track your www.transfer.sh files.
#!/bin/bash
set -o nounset
set -o errexit
OPTION=""
HISTORYFILE="${HOME}/.transfer_history"
testfile() {
FILETOTEST=$1
if ! [ -f "$FILETOTEST" ]; then
echo " ERROR: File $FILETOTEST does not exist or is not a real file." >&2
exit 1
fi
}
uploadfile() {
FILETOUPLOAD=$1
curl --progress-bar --upload-file $FILETOUPLOAD https://transfer.sh/$(basename $FILETOUPLOAD) |tee -a $HISTORYFILE
}
encrpytfile() {
FILETOCRYPT=$1
TMPFOLDER=$(/bin/mktemp -d)
CRYPTFILENAME=$TMPFOLDER/$(basename $FILETOCRYPT).asc
# Crpyt file to temp and upload it
gpg --output $CRYPTFILENAME -ac $FILETOCRYPT
uploadfile $CRYPTFILENAME
# Cleanup after ourselves
rm -rf "$TMPFOLDER"
}
showhistory() {
nl "$HISTORYFILE"
}
printfile() {
# Test to make sure Linenum is a number
RE='^[0-9]+$'
LINENUM=$1
if [[ $LINENUM =~ $RE ]]; then
head -n $LINENUM "$HISTORYFILE" |tail -1
else
echo " ERROR: $LINENUM is not a number from the transfer history" >&2; exit 1
fi
}
usage () {
echo "`basename $0` [COMMAND]"
echo " Upload, encrpyt, and review files uploaded to transfer.sh"
echo " "
echo "Commands:"
echo " <FILE> ...If no command is specified upload is assumed "
echo " add|upload <FILE> ...Upload a <FILE> to transfer.sh"
echo " crypt|secure <FILE> ...Encrpyt (CAST5 w/ ASCII Armor) file with a passphrase upload"
echo " hist|list|history ...Show history of uploaded files."
echo " help|-h ...Show this help screen."
echo " print <NUM> ...Print URL of number <NUM> from the history file."
echo ""
exit 1
}
if [[ ! $# == 0 && -n $1 ]]; then
case $1 in
crypt|secure)
OPTION=$2
testfile $OPTION
encrpytfile $OPTION
;;
-h|help)
usage
;;
list|hist|history)
showhistory
;;
add|upload)
OPTION=$2
testfile $OPTION
uploadfile $OPTION
;;
print)
OPTION=$2
printfile $OPTION
;;
*)
OPTION=$1
testfile $OPTION
uploadfile $OPTION
;;
esac
else
usage
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment