sharefile

scripts for quickly sharing data to servers
git clone git://jb55.com/sharefile
Log | Files | Refs | README

commit 80f710499cdf1d829cbaa12801f60b22a4696dcb
Author: William Casarin <bill@casarin.me>
Date:   Mon, 22 Jun 2015 14:08:33 -0700

Initial commit

Diffstat:
AREADME.md | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asharefile | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 115 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -0,0 +1,59 @@ + +# sharefile + + Simple script that uploads a file to your server and spits out a corresponding + url + +## Installation + + Git + + $ git clone https://github.com/jb55/sharefile /tmp/sharefile && cp /tmp/sharefile/sharefile ~/bin + + Or just download it directly and put it in your `PATH`, I don't care + +## Setup + + Put these in your `.profile` or `.bashrc` or `.zshrc` or something + + export SHAREFILE_HOST=me.com:/www/public/share/ + export SHAREFILE_URL=http://me.com/share/ + +## Example + + Set the upload name + + $ sharefile -n desktop.png ~/scrots/2015-blah-derp.png + http://me.com/share/desktop.png + + Copy link to clipboard + + $ sharefile ~/Documents/doc.txt | pbcopy + +## Reasons to use Dropbox for sharing now + + None + +## License + + The MIT License (MIT) + + Copyright (c) 2014 William Casarin + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. diff --git a/sharefile b/sharefile @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +set -e + +name="" +errord=0 +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_HOST=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" + exit 1 +} + +missing_env() { + >&2 echo "missing environment variable $1" + exit 1 +} + +while getopts "h?n:u:d:" opt; do + case "$opt" in + h|\?) + show_help + ;; + n) + name="$OPTARG" + ;; + d) + SHAREFILE_HOST="$OPTARG" + ;; + u) + SHAREFILE_URL="$OPTARG" + ;; + esac +done + +shift $((OPTIND-1)) +[ "$1" = "--" ] && shift + +file="$1" + +[[ -z $SHAREFILE_HOST ]] && missing_env "SHAREFILE_HOST, eg: me.com:public/files/" +[[ -z $SHAREFILE_URL ]] && missing_env "SHAREFILE_URL, eg: http://me.com/files/" +[[ -z $file ]] && show_help + +name=${name:-$(basename "$file")} +dest="${SHAREFILE_HOST}${name}" + +rsync -zq --chmod=a=r "$file" "$dest" +echo "${SHAREFILE_URL}${name}"