diff options
author | Alex Legler <alex@a3li.li> | 2016-01-04 02:18:48 +0100 |
---|---|---|
committer | Alex Legler <alex@a3li.li> | 2016-01-04 02:18:48 +0100 |
commit | fd7fa9102a50dedb2f1cbad4993fa2c7427407aa (patch) | |
tree | 7ca0f15a86f6a84599f076e01e8a27a8e22ec8d2 /bin | |
download | mirror-toolkit-fd7fa9102a50dedb2f1cbad4993fa2c7427407aa.tar.gz mirror-toolkit-fd7fa9102a50dedb2f1cbad4993fa2c7427407aa.tar.bz2 mirror-toolkit-fd7fa9102a50dedb2f1cbad4993fa2c7427407aa.zip |
Add initial set of tools
- rsync-cat: rsync-to-stdout utility
- gm-lag: displays the current lag of a mirror
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/gm-lag | 27 | ||||
-rwxr-xr-x | bin/rsync-cat | 14 |
2 files changed, 41 insertions, 0 deletions
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} <rsync url>" + exit 1 +fi + +rsync -q "${1}" "${TMPFILE}" || exit 1 +cat "${TMPFILE}" |