Last active
August 29, 2015 14:21
-
-
Save Rawa/529723f2b98cf194ab14 to your computer and use it in GitHub Desktop.
Simple upload script that sends file to your server, also copy the url to file to the clipboard.
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
#/usr/bin/env bash | |
version="1.0" | |
upload_path="/data/upload/" | |
server="srv" | |
#Url of the website (used for copying url to clipboard) | |
url="http://upload.yourwebsite.com/" | |
function print_help { | |
echo "Upload files to your remote server" | |
echo "" | |
echo "usage:" | |
echo "upload [FILE(s)] Uploads files to the server" | |
echo "upload clean Clean the directory of files" | |
echo "upload -h, --help Prints this help dialog" | |
echo "" | |
echo "upload v$version by Rawa" | |
echo "www.davidgoransson.com" | |
} | |
#Check if correct number of arguments | |
if [ "$#" -eq 0 ]; then | |
print_help | |
exit 1 | |
fi | |
#If only one argument check if it is help or clean | |
if [ "$#" -eq 1 ]; then | |
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then | |
print_help | |
exit 0 | |
fi | |
if [ "$1" == "clean" ] ; then | |
#Print confirm box | |
read -p "Are you sure? " -n 1 -r | |
echo # (optional) move to a new line | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
#Clean upload folder | |
ssh $server "cd $upload_path ; rm * -rf" | |
exit 0 | |
fi | |
exit 0 | |
fi | |
fi | |
#Copy the files to the server | |
scp $@ $server:$upload_path | |
#Copy url to clipboard (direct link if single file) | |
if [ "$#" -eq 1 ]; then | |
echo $url$1 | xsel -ib | |
else | |
echo $url | xsel -ib | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment