elastichosts-utils-20090817/000755 001751 001751 00000000000 11147327423 020415 5ustar00elastic-wwwelastic-www000000 000000 elastichosts-utils-20090817/COPYING000644 001751 001751 00000002052 11147327423 021447 0ustar00elastic-wwwelastic-www000000 000000 Copyright (C) 2008-2009 ElasticHosts Ltd 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. elastichosts-utils-20090817/elastichosts000755 001751 001751 00000003051 11242333747 023051 0ustar00elastic-wwwelastic-www000000 000000 #!/bin/bash usage() { cat >&2 </dev/null; then echo "This tool requires curl, available from http://curl.haxx.se/" >&2 elif [ ! -n "$EHAUTH" ]; then echo "Please set EHAUTH=:" >&2 exit 1 fi DATA="" EHURI="${EHURI:-https://api.lon-b.elastichosts.com/}" TYPE="" VERBOSE="" while getopts cf:jv OPTION; do case "$OPTION" in c) DATA="-" ;; f) if [ -e "$OPTARG" ]; then case "$OPTARG" in /*) DATA="$OPTARG" ;; *) DATA="$PWD/$OPTARG" ;; esac else echo "$OPTARG not found" >&2 exit 1 fi ;; j) TYPE="application/json" ;; v) VERBOSE=-v ;; *) usage ;; esac done shift $(($OPTIND - 1)) [ $# -gt 0 ] || usage EHURI="$EHURI`tr \ / <<< "$*"`" EHAUTH="user = \"$EHAUTH\"" if [ -z "$DATA" ]; then curl --data-binary '' -K <(echo "$EHAUTH") -s $VERBOSE \ ${TYPE:+-H "Accept: $TYPE"} "$EHURI" else cat "$DATA" | curl --data-binary @- -K <(echo "$EHAUTH") -s $VERBOSE \ -H "Content-Type: ${TYPE:-application/octet-stream}" \ ${TYPE:+-H "Accept: $TYPE"} -H 'Expect:' "$EHURI" fi elastichosts-utils-20090817/elastichosts-upload000755 001751 001751 00000005533 11242333761 024336 0ustar00elastic-wwwelastic-www000000 000000 #!/bin/bash shopt -s extglob die() { echo "$@" >&2 exit 1 } usage() { cat >&2 </dev/null; then die "This tool requires curl, available from http://curl.haxx.se/" fi [ -n "$EHAUTH" ] || die "Please set EHAUTH=:" CHUNK=5242880 DRIVE="" GUNZIP=0 OFFSET=0 while getopts c:d:n:o:z OPTION; do case "$OPTION" in c) case "$OPTARG" in [1-9]*([0-9])) OFFSET="$OPTARG" ;; *) usage ;; esac ;; d) DRIVE="$OPTARG" ;; n) NAME="$OPTARG" ;; o) case "$OPTARG" in 0|[1-9]*([0-9])) OFFSET="$OPTARG" ;; *) usage ;; esac ;; z) GUNZIP=1 ;; *) usage ;; esac done shift $(($OPTIND - 1)) [ $# -eq 1 ] || usage NAME="${NAME:-`basename "$1"`}" if [ $GUNZIP -gt 0 ]; then SIZE=`gzip -lq "$1" | awk '{ print $2 }'` || die "$1: Not in gzip format" else [ -f "$1" ] && SIZE=`stat -L -c '%s' "$1"` [ -b "$1" ] && SIZE=`blockdev --getsize64 "$1"` [ -n "$SIZE" ] && [ $SIZE -gt 0 ] || die "$1: No such file or directory" fi EHURI="${EHURI:-https://api.lon-b.elastichosts.com/}" EHAUTH="user = \"$EHAUTH\"" if [ -n "$DRIVE" ]; then echo "Using existing drive $DRIVE" elif POSTDATA=`echo "name $NAME"; echo "size $SIZE"` \ && DRIVE=`curl --data-ascii "$POSTDATA" -K <(echo "$EHAUTH") -f -s \ -H 'Content-Type: text/plain' -H 'Expect:' \ "${EHURI}drives/create"` \ && DRIVE=`sed -n 's/^drive *//p' <<< "$DRIVE"` && [ -n "$DRIVE" ]; then echo "Created drive $DRIVE of size $SIZE" else die "Failed to create drive of size $SIZE" fi upload() { local COUNT=$((($SIZE - $OFFSET + $CHUNK - 1)/$CHUNK)) echo -n "Uploading $COUNT chunks of $CHUNK bytes: " for ((OFFSET = OFFSET/CHUNK; OFFSET*CHUNK < SIZE; OFFSET++)); do head -c $CHUNK | gzip -c \ | curl --data-binary @- -K <(echo "$EHAUTH") -f -s \ -H 'Content-Type: application/octet-stream' \ -H 'Content-Encoding: gzip' -H 'Expect:' \ "${EHURI}drives/$DRIVE/write/$(($OFFSET*$CHUNK))" [ $? -eq 0 ] && echo -n . && continue || echo E cat <&2 Failed to write chunk $OFFSET of $COUNT: aborting Restart with '-d $DRIVE -o $(($OFFSET*$CHUNK))' to resume the upload EOF exit 1 done echo " completed" } if [ $GUNZIP -gt 0 ]; then gzip -c -d "$1" 2>/dev/null | upload else upload <"$1" fi