From 4ad091b2f4f61d5ba0f8c7b8b942fc48c40b49d0 Mon Sep 17 00:00:00 2001 From: Tzafrir Cohen Date: Mon, 13 Jun 2011 17:04:46 +0000 Subject: rapid-tunneling: rt_handle_uploaded_key rt_handle_uploaded_key is a script we use on a remote web server to provide a simple URL to download the tarballs. git-svn-id: svn+ssh://xorcom/home/svn/debs/components/rapid-tunneling@9418 283159da-0705-0410-b60c-f2062b4bb6ad --- rt_handle_uploaded_key | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 rt_handle_uploaded_key diff --git a/rt_handle_uploaded_key b/rt_handle_uploaded_key new file mode 100755 index 0000000..87b5151 --- /dev/null +++ b/rt_handle_uploaded_key @@ -0,0 +1,83 @@ +#!/bin/sh + +# rt_handle_uploaded_key: A script to publish tarballs to a web directory +# +# This script (its 'put' command) should be the command of a public +# ssh key used by the support user to upload tarballs to a public web +# server. +# To use it, create a SSH key for the support user and add it to some ssh +# user on the server with a command field: +# command="/usr/local/bin/rt_handle_uploaded_key put" ssh-rsa [...] +# +# On the server side, set the script to copy the tarballs to some +# directory on the wer server, and configure it to allow getting files +# from there (but not browse. E.g. the apache configuration snippet: +# +# Alias /k $TARBALLS_DIR +# +# Options None +# AllowOverride None +# Order allow,deny +# allow from all +# +# +# Be sure to also delete old tarballs. E.g. a cron job that runs: +# +# find $TARBALLS_DIR -ctime +3 -exec rm -f '{}' \; +# +# To list all current tarballs, run the command with no extra parameter. +# it will list current tarballs (with the name, and creation time). + +set -e + +# Required: +TARGET_DIR=$HOME/ra-tarballs +# The URL under which tarballs are accessible (for printing it) +BASE_URL="http://updates.xorcom.com/k" + +# Emit a random-enough string +rand() { + dd if=/dev/urandom count=16 2>/dev/null | md5sum | cut -c1-8 +} + +tar_name() { + tar xOzf "$1" basename 2>/dev/null || echo NONAME | tr -d -c 'a-zA-Z0-9_' +} + +tar_time() { + LANG=C tar tvzf ra-tarballs/3d32382e.tgz port | awk '{print $4,$5}' +} + +put_tarball() { +# FIXME: this assumes there will be no collisions +# and no concurrent runs + rand_str=`rand` + tar_name="$rand_str.tgz" + tar_full="$TARGET_DIR/$tar_name" + tar_url="$BASE_URL/$tar_name" + + dd of="$tar_full" bs=10k count=1 2>/dev/null + if ! tar tzf "$tar_full" >/dev/null; then + echo >&2 "Failed upload. Deleting." + rm "$tar_full" + fi + name=`tar_name "$tar_full"` + echo "$name: $tar_url" +} + +list() { + for tarball in $TARGET_DIR/*.tgz; do + tar xOzf $tarball port >/dev/null 2>&1 || continue + name=`tar_name "$tarball"` + base_name="${tarball##*/}" + url="$BASE_URL/$base_name" + time=`tar_time "$tarball"` + printf "$name\t$time $url\n" + + done +} + +case "$1" in + put) put_tarball ;; + *) list ;; +esac -- cgit v1.2.3