diff options
author | Peter Palfrader <peter@palfrader.org> | 2009-11-19 14:14:27 +0000 |
---|---|---|
committer | weasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede> | 2009-11-19 14:14:27 +0000 |
commit | db2de78c110f279b7d33ea9a2fc8f131a0e70839 (patch) | |
tree | 2fd2032168ce68f991ff18ea9a647dcfe1a7509c | |
parent | 8de05b44087dc7271a073295a48268ddc6df4eeb (diff) |
Support uploading multiple files at once
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@417 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
-rw-r--r-- | publish | 67 |
1 files changed, 32 insertions, 35 deletions
@@ -35,15 +35,14 @@ base_rsync=marvin.example.com:/var/www/www.example.comhtdocs/pub usage() { cat << EOF -usage: $0 <src> +usage: $0 <src> [<src> ...] copy the file <src> to a server an report the URL. OPTIONS: -h Show this message - -s source, file/directory - -t test, just display the result -d include directlink to src in url + -n no-do. Just print what would have been done EOF } @@ -55,59 +54,57 @@ get_random() { head -c 8 /dev/urandom | base64 | tr '/+' '-_' | tr -d '=' } -TEST=false +NODO="" DIRECTLINK=false -while getopts "hs:td" OPTION +while getopts "hn" OPTION do case $OPTION in h) usage exit 1 ;; - s) - SRC="$OPTARG" + n) + NODO="echo" ;; - t) - TEST=true - ;; - d) - DIRECTLINK=true - ;; - ?) - usage - exit + *) + usage >&2 + exit 1 ;; esac done +shift $(($OPTIND - 1)) -if [[ -z "$SRC" ]]; then - usage - exit 1 -fi - -if [[ ! -r "$SRC" ]]; then - echo "'$SRC' is not readable or does not exist" +if [[ "$#" = 0 ]]; then + echo "No files to copy" >&2 exit 2 fi d_date=$(date +'%Y-%m-%k') d_random=$(get_random) -d_server=$d_date'-'$d_random - +d_server="$d_date-$d_random" rsync_args="--partial --recursive --compress" -if [[ "$DIRECTLINK" = "false" ]]; then - d_server_http=$( echo -n "$d_server" | uri_encode ) +d_server_http_base=$( echo -n "$d_server" | uri_encode ) + +if [ "$#" = 1 ]; then + only_one=1 else - d_server_http=$( echo -n "$d_server" | uri_encode )'/'$( echo -n "$SRC" | uri_encode ) + only_one=0 + echo "$base_http/$d_server_http_base/" fi -http_url=$base_http"/"$d_server_http +while [ "$#" -gt 0 ]; do + file="$1" + shift -if [[ "$TEST" = "false" ]]; then - rsync $rsync_args "$SRC" $base_rsync"/$d_server/" -else - echo rsync $rsync_args "$SRC" $base_rsync"/$d_server/" -fi -echo $http_url + if [ -d "$file" ] && [ "$only_one" = 1 ]; then + trail="/" + else + trail="" + fi + + $NODO rsync $rsync_args "$file$trail" $base_rsync"/$d_server/" + + echo "$base_http/$d_server_http_base/$( echo -n "$file" | uri_encode )" +done |