Skip to content

Instantly share code, notes, and snippets.

@jb55
Created June 22, 2015 20:50
Show Gist options
  • Save jb55/c41efed0c7409d8bb670 to your computer and use it in GitHub Desktop.
Save jb55/c41efed0c7409d8bb670 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
name=""
OPTIND=1
show_help () {
echo "sharefile [-n newname.png] <FILE>"
echo ""
echo " -n NAME set the destination file name"
echo " -d DESTINATION set the destination folder. eg: me.com:files"
echo " export SHAREFILE_TO=me.com:files/ to set default"
echo ""
echo " -u URL set the destination folder. eg: me.com:files"
echo " export SHAREFILE_URL=http://me.com/files/ to set default"
}
while getopts "h?n:u:d:" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
n)
name="$OPTARG"
;;
d)
SHAREFILE_TO="$OPTARG"
;;
u)
SHAREFILE_URL="$OPTARG"
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
file="$1"
name=${name:-$(basename "$file")}
dest="${SHAREFILE_TO}${name}"
rsync -zq --chmod=a=r "$file" "$dest"
echo "${SHAREFILE_URL}${name}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment