Skip to content

Instantly share code, notes, and snippets.

@juliusknorr
Last active January 6, 2024 11:59
Show Gist options
  • Save juliusknorr/5905622 to your computer and use it in GitHub Desktop.
Save juliusknorr/5905622 to your computer and use it in GitHub Desktop.
uploadscript for uberload webspace
#!/bin/bash
# uberload
# usage: uberload <folder> <source>
# this script uploads a given file or folder to a folder on my uberspace host
# if the source is a folder it gets compressed using pbzip2
# the url of the file will be put into the clipboard (os x)
# notification when the file is uploaded using terminal-notifies
# this also works with any other ssh server
SSHUSER="sshuser"
SSHHOST="example.com"
TARGET="http://example.com/"
HOSTPATH="html"
if [ $# -ne 2 ]
then
echo "Upload to uberspace server\nUsage: `basename $0` {folder} {source}"
exit $E_BADARGS
fi
SOURCE=$2
FILENAME=$(basename $2)
TARGET=$1
TEMP=0
# compress if folder
if [[ -d $SOURCE ]]; then
echo "$FILENAME is a directory. compressing with pbzip2"
tar cf /tmp/$FILENAME.tar $SOURCE
pbzip2 /tmp/$FILENAME.tar
# rm /tmp/$FILENAME.tar
FILENAME="$FILENAME.tar.bz2"
SOURCE="/tmp/$FILENAME"
TEMP=1
elif [[ -f $SOURCE ]]; then
echo "$SOURCE is a file. uploading"
else
echo "$SOURCE is not valid"
exit 1
fi
FILEURL="$TARGET/$TARGET/$FILENAME"
# copy to server
scp $SOURCE $SSHUSER@$SSHHOST:~/$HOSTPATH/$TARGET/
# change file rights
ssh $SSHUSER@$SSHHOST "chmod 644 ~/$HOSTPATH/$TARGET/$FILENAME"
# copy url to clipboard
echo $FILEURL | pbcopy
# notify about successful upload
terminal-notifier -title "$FILENAME uploaded to $1" -message "$FILEURL" -open "$FILEURL"
# delete temporary file
if [ $TEMP = 1 ]; then
rm /tmp/$FILENAME
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment