diff options
author | Peter Palfrader <peter@palfrader.org> | 2009-11-19 13:48:53 +0000 |
---|---|---|
committer | weasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede> | 2009-11-19 13:48:53 +0000 |
commit | e5d8a3cdb428b93f23056342f47cdde240742f69 (patch) | |
tree | 8e28d663b02bb033e220425ccb41e075763b580b /publish | |
parent | d8b95bfda569dea5f86392e8fb9f31445275fb22 (diff) |
Add Flo's publish script
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@413 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'publish')
-rw-r--r-- | publish | 114 |
1 files changed, 114 insertions, 0 deletions
@@ -0,0 +1,114 @@ +#!/bin/bash + +# Copyright (c) 2009 Florian Reitmeir +# +# 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. + +# Author: Florian Reitmeir +# E-mail: florian@reitmeir.org + +base_http=http://www.example.com/pub +base_rsync=marvin.example.com:/var/www/www.example.comhtdocs/pub + +usage() +{ +cat << EOF +usage: $0 <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 +EOF +} + +uri_encode() { + perl -MURI::Escape -ne 'print uri_escape($_)' +} + +base64_encode() { + perl -MMIME::Base64 -ne 'print encode_base64($_,'')' +} + +get_random() { + head -c 128 /dev/urandom | base64_encode | sed -e 's/[^a-zA-Z0-9]//g' | head -c 16 +} + +TEST=false +DIRECTLINK=false + +while getopts "hs:td" OPTION +do + case $OPTION in + h) + usage + exit 1 + ;; + s) + SRC="$OPTARG" + ;; + t) + TEST=true + ;; + d) + DIRECTLINK=true + ;; + ?) + usage + exit + ;; + esac +done + +if [[ -z "$SRC" ]]; then + usage + exit 1 +fi + +if [[ ! -r "$SRC" ]]; then + echo "'$SRC' is not readable or does not exist" + exit 2 +fi + +d_date=$(date +'%Y-%m-%k') +d_random=$(get_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 ) +else + d_server_http=$( echo -n "$d_server" | uri_encode )'/'$( echo -n "$SRC" | uri_encode ) +fi + +http_url=$base_http"/"$d_server_http + +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 |