summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--publish67
1 files changed, 32 insertions, 35 deletions
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 <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