Last active
August 29, 2015 14:15
-
-
Save sanderploegsma/d02034569752d5a156f8 to your computer and use it in GitHub Desktop.
Linkdump upload script
This file contains hidden or 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 | |
# up.sh by Sander Ploegsma (@sanderploegsma) | |
# | |
# Copy file to remote location using generated filename. Return file link and copy to clipboard | |
# NOTE: Currently only meant for OS X due to use of pbcopy. | |
# | |
REMOTE_USER="username" | |
REMOTE_URL="example.com" | |
REMOTE_PATH="/path/to/files" | |
LINK_BASE="http://my.short.url/" | |
if [ $# -eq 0 ] ; then | |
echo "No filename given! Usage: up <filename>" | |
elif [ -f "$1" ] ; then | |
filename=$(basename "$1") | |
extension="${filename##*.}" | |
newname=$(cat /dev/urandom | base64 | tr -dc "[:alnum:]" | head -c 8) | |
scp "$1" "$REMOTE_USER@$REMOTE_URL:$REMOTE_PATH/$newname.$extension" | |
file="$LINK_BASE/$newname.$extension" | |
echo $file | |
echo $file | pbcopy # remove line if not on OS X. | |
else | |
echo 'File "$1" not found.' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment