From fd7fa9102a50dedb2f1cbad4993fa2c7427407aa Mon Sep 17 00:00:00 2001 From: Alex Legler Date: Mon, 4 Jan 2016 02:18:48 +0100 Subject: Add initial set of tools - rsync-cat: rsync-to-stdout utility - gm-lag: displays the current lag of a mirror --- bin/gm-lag | 27 +++++++++++++++++++++++++++ bin/rsync-cat | 14 ++++++++++++++ 2 files changed, 41 insertions(+) create mode 100755 bin/gm-lag create mode 100755 bin/rsync-cat (limited to 'bin') diff --git a/bin/gm-lag b/bin/gm-lag new file mode 100755 index 0000000..ae81875 --- /dev/null +++ b/bin/gm-lag @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# Displays the number of seconds a mirror is lagging behind + +require 'optparse' +require 'time' +require 'uri' +require 'net/http' +require_relative '../lib/mirror_toolkit' + +options = {} +OptionParser.new do |opts| + opts.on('-h', '--human', 'Display human times') { |v| options[:human] = v } + opts.on('-d', '--distfiles', 'Treat as distfiles mirror') { |v| options[:distfiles] = v } + opts.on('-r', '--rsync', 'Treat as rsync mirror') { |v| options[:rsync] = v } +end.parse! + +abort '-d and -r are exclusive.' if options[:distfiles] && options[:rsync] + +lag = MirrorToolkit.get_lag(ARGV[0], options[:rsync] ? MirrorToolkit::TYPE_RSYNC : MirrorToolkit::TYPE_DISTFILES) + +if lag.nil? + puts 'unknown' +elsif options[:human] + puts MirrorToolkit.humanize_seconds(lag) +else + puts lag.to_i +end diff --git a/bin/rsync-cat b/bin/rsync-cat new file mode 100755 index 0000000..e2b7c3c --- /dev/null +++ b/bin/rsync-cat @@ -0,0 +1,14 @@ +#!/bin/bash +# Prints an rsync file to stdout + +me=$(basename $0) +TMPFILE=$(mktemp /tmp/${me}.XXXXXX) || exit 1 +trap "rm ${TMPFILE}" EXIT + +if [ -z "${1}" ]; then + echo "Usage: ${0} " + exit 1 +fi + +rsync -q "${1}" "${TMPFILE}" || exit 1 +cat "${TMPFILE}" -- cgit v1.2.3-65-gdbad