From 7aaf156cc9ed999466461e6b12c0f3aedfa850ff Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sun, 29 Nov 2009 15:44:56 +0000 Subject: History support from flo git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@424 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- publish | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'publish') diff --git a/publish b/publish index bb34c4a..08a7e0f 100755 --- a/publish +++ b/publish @@ -30,6 +30,9 @@ base_http=http://www.example.com/pub base_rsync=marvin.example.com:/var/www/www.example.com/htdocs/pub +history_file=false +history_lines=1000 + [ -e ~/.publish.cfg ] && . ~/.publish.cfg usage() @@ -50,12 +53,25 @@ uri_encode() { } get_random() { - head -c 8 /dev/urandom | base64 | tr '/+' '-_' | tr -d '=' + head -c 8 /dev/urandom | base64 | tr '/+' 'xx' | tr -d '=' +} + +history_append() { + time=$(date --utc --rfc-3339='seconds') + echo $time $1 >>"$history_file" + + history_tmp=$( tempfile ) + cat "$history_file" | tail --lines="$history_lines" >"$history_tmp" + mv "$history_tmp" "$history_file" +} + +history_show() { + cat "$history_file" } NODO="" -while getopts "hn" OPTION +while getopts "hns" OPTION do case $OPTION in h) @@ -65,6 +81,15 @@ do n) NODO="echo" ;; + s) + if [ -r "$history_file" ]; then + history_show + exit 0 + else + echo "history file: '$history_file' not found" + exit 3 + fi + ;; *) usage >&2 exit 1 @@ -92,6 +117,14 @@ else echo "$base_http/$d_server_http_base/" fi +for file in "$@"; do + uri="$base_http/$d_server_http_base/$( echo -n "$file" | uri_encode )" + echo "$uri" + if [ -w "$history_file" ]; then + history_append "$uri" + fi +done + while [ "$#" -gt 0 ]; do file="$1" shift @@ -103,6 +136,4 @@ while [ "$#" -gt 0 ]; do 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