diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..bf82a70 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,19 @@ +Copyright (c) 2013 The puush-linux Team + +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/README.md b/README.md index 4f38781..83ff185 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,10 @@ A Bash script for uploading files to puush.me from Linux. Many thanks to @Westie Using ----- -* Get puush from here: http://b3.blha303.com.au/puush-linux/files/puush -* Copy 'puush' to /usr/bin. -* Use it with `puush file.name`. +* Get curl if you don't have it already. Most package managers have it as `curl` (apt-get install curl, yum install curl), or check this page: http://curl.haxx.se/download.html +* Get puush from here: https://github.com/blha303/puush-linux/raw/master/puush +* Copy 'puush' to /usr/local/bin, and use `chmod +x /usr/local/bin/puush`. +* For uploading a file, use `puush file.ext`. +* For uploading from stdin, use `cat file.ext | puush - ext`. -You'll need to set up an environment variable, PUUSH_API_KEY. You can do this per-session with `export PUUSH_API_KEY="apiKeyHere"`, or by putting that command in `~/.bashrc`. +You'll need to set up an environment variable, PUUSH_API_KEY. You can get this key from your puush client in Settings, or from [puush.me](http://puush.me/account/settings). You can set the environment variable per-session with `export PUUSH_API_KEY="apiKeyHere"`, or by putting that command in `~/.bashrc`. diff --git a/apiDocumentation.md b/apiDocumentation.md index e789dfe..a2d2237 100644 --- a/apiDocumentation.md +++ b/apiDocumentation.md @@ -3,40 +3,47 @@ puush API documentation ###Authentication - URL: `/api/auth` - - Request: - - - e = email address - - - p = password + - Request (two methods, key authentication takes priority): + - With login credentials: + - e = email address + - p = password + - With API key: + - k = apikey - Response (authenticated, success): `{premium},{apikey},[expire],{size-sum}` - Response (failure): `-1` ###Deletion - - URL: `/api/hist` + - URL: `/api/del` - Request: - - - k = apikey - - - i = file identifier - on puush.me, is base10 of file hash - - Response (history, success): `{id},{YYYY-MM-DD HH:MM:SS},{url},{filename},{views},{unknown}` + - k = apikey + - i = file identifier - on puush.me, is SEQUENTIAL + - Response (success): `0` - Response (failure): `-1` ###History - URL: `/api/hist` - Request: - - - k = apikey - - Response (history, success): `{id},{YYYY-MM-DD HH:MM:SS},{url},{filename},{views},{unknown}` + - k = apikey + - Response (history, success): up to 10 lines of `{id},{YYYY-MM-DD HH:MM:SS},{url},{filename},{views},{unknown}` - Response (failure): `-1` ###Thumbnail - URL: `/api/thumb` - Request: - - - k = apikey - - - i = file identifier - on puush.me, is base10 of file hash - - Response (success): image, resized - - Response (failure): `-1` + - k = apikey + - i = file identifier - on puush.me, is SEQUENTIAL + - Response (success): image, 100x100 png + - Response (failure): nothing ###Upload - URL: `/api/up` + - `Content-Disposition` header needs filename - Request: - - - k = apikey - - - z = "poop" - - - f = file + - k = apikey + - z = "poop" + - f = file + - c = MD5 hash of file (optional, will only be used if present in the request) - Response (upload, success): `0,{url},{id},{size}` - - Response (failure): `-1` + - Response (failure, upload): `-1` + - Response (failure, no filename header): `-2` + - Response (failure, hash didn't match): `-3` diff --git a/puush b/puush index 232f95a..685e3ad 100755 --- a/puush +++ b/puush @@ -1,15 +1,41 @@ #!/bin/bash -PUUSH_API_KEY="" +if [ "$1" = "-" ] +then + if [ "$2" != "" ] + then + EXT=$2 + else + EXT="txt" + fi + _IFS=$IFS + IFS='' # to preserve spacing + while read p + do + echo $p >> /tmp/puush-tmp.$EXT + done + IFS=$_IFS + FN="/tmp/puush-tmp.$EXT" +else + FN="$1" +fi if [ -z "$PUUSH_API_KEY" ] then - echo "Set the variable PUUSH_API_KEY in $0 or with 'export PUUSH_API_KEY=\"apiKeyHere\"" - exit -elif ! [ -r "$1" ] + echo "Please enter your API key:" + read PUUSH_API_KEY + echo "export PUUSH_API_KEY=$PUUSH_API_KEY" >> ~/.bashrc + echo "Added API key to ~/.bashrc" +fi +if [ -z "$FN" ] +then + echo "Specify a file to be uploaded (or use - for stdin)" + exit 2 +elif ! [ -f "$FN" -a -r "$FN" ] then - echo "Specify a file to be uploaded" - exit + echo "File '$FN' is not valid (it is not a file or it is not readable)" + exit 3 fi -curl "https://puush.me/api/up" -# -F "k=$PUUSH_API_KEY" -F "z=poop" -F "f=@$1" | sed -E 's/^.+,(.+),.+,.+$/\1\n/' +curl "https://puush.me/api/up" -# -F "k=$PUUSH_API_KEY" -F "z=poop" -F "f=@$FN" | sed -E 's/^.+,(.+),.+,.+$/\1\n/' +rm /tmp/puush-tmp.* 2>/dev/null