From db2de78c110f279b7d33ea9a2fc8f131a0e70839 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Thu, 19 Nov 2009 14:14:27 +0000 Subject: Support uploading multiple files at once git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@417 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- publish | 67 +++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 32 insertions(+), 35 deletions(-) (limited to 'publish') diff --git a/publish b/publish index 3add6de..af9483a 100644 --- a/publish +++ b/publish @@ -35,15 +35,14 @@ base_rsync=marvin.example.com:/var/www/www.example.comhtdocs/pub usage() { cat << EOF -usage: $0 +usage: $0 [ ...] copy the file 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 -- cgit v1.2.3