Commit f101fa21 authored by Matt Travers's avatar Matt Travers

Replace wget and sed with a perl script

parent 2e1dab5c
......@@ -3,7 +3,7 @@
# Install access to the NeuroDebian snapshot repository that allows access
# to old packages based on dates and version numbers.
# The date/time format sent to NeuroDebian to get the repo info is in the
# The UTC date/time format sent to NeuroDebian to get the repo info is in the
# format yyyymmddThhmmssz or yyymmdd. However, the script will handle and
# reformat a number of date/time formats. Quotes are required if there is a
# space between the date and time components:
......@@ -19,12 +19,17 @@
# Browse available snapshots here:
# If there is no import at the exact time you specified you will get the latest
# available timestamp which is before the time you specified.
# If there is no import at the exact time you specified you will get both the
# previous and next available timestamped repos of the one you specified to make
# available versions that may have been placed in the repo before your
# selected time but after the previous snapshot.
set -e
# Change into the directory of the script.
cd "$(dirname "$0")"
# Check for date command line argument
if [ -z "$1" ]; then
......@@ -53,24 +58,6 @@ exit 1
# Check for existence of required command line utilities
programs='wget sed'
for program in $programs
if [ -z `which ${program}` ]; then
cat << EOT
ERROR: ${program} not found on this system. It is required to configure the snapshot repos.
To install:
sudo apt-get update
sudo apt-get install -y ${program}
exit 1
set -u
# Format date provided by user
......@@ -130,16 +117,13 @@ if [ -z "$codename" ]; then
exit 1
# Knock on snapshot's door. This is temporarily necessary until the production
# version of the site is made available.
wget -O /dev/null -q 80 _files/knock-snapshots
# Add "next" snapshot to cover package updates made after the previous snapshot
# but before the user provided date.
next_line=`wget -qO-${previous_timestamp}/ | sed -n '/>next<\/a>/p'`
next_timestamp=`echo "$next_line" | sed -E 's/^.*\/archive\/neurodebian\/([0-9TZ]+)\/">next.*$/\1/'`
next_timestamp=` 5002 archive/neurodebian/${previous_timestamp}/`
if [ -z "$next_timestamp" ]; then
echo ERROR: Unable to determine the next snapshot timestamp.
exit 1
......@@ -153,6 +137,11 @@ cat << EOT >> $APT_SOURCE_PATH
# NeuroDebian
deb${stamp}/ ${codename} main contrib non-free
deb-src${stamp}/ ${codename} main contrib non-free
# NeuroDebian data
deb${stamp}/ data main contrib non-free
deb-src${stamp}/ data main contrib non-free
# Main Debian repository
deb${stamp}/ ${codename} main
deb-src${stamp}/ ${codename} main
......@@ -162,6 +151,16 @@ deb-src${stamp}/ ${codename}
# Refresh apt cache if possible
sudo_path=`which sudo`
if [ "$username" == "root" ]; then
apt-get update
elif [ ! -z "$sudo_path" ]; then
sudo apt-get update
echo Run \"apt-get update\" to make the snapshot packages available.
echo NeuroDebian snapshot repo source information saved to $APT_SOURCE_PATH
echo Run \"sudo apt-get update\" to make the snapshot packages available.
exit 0
# Simple web client for retrieving neurodebian snapshot information.
# Code adapted from:
# This script covers the duties normally performed by wget, curl, and/or sed,
# any of which may not be installed on the target OS.
require 5.002;
use Socket;
sub get_www_content {
my ($dest, $port, $file) = @_;
my $proto = getprotobyname('tcp');
socket(F, PF_INET, SOCK_STREAM, $proto);
my $sin = sockaddr_in($port,inet_aton($dest));
connect(F, $sin) || return undef;
my $old_fh = select(F);
$| = 1;
print F "GET /$file HTTP/1.0\n\n";
$/ = undef;
$contents = <F>;
return $contents;
if ($#ARGV != 2) {
print "Usage: $0 hostname port file\n";
print "\n Returns the HTTP output from a web server.\n\n";
$contents = get_www_content($ARGV[0], $ARGV[1], $ARGV[2]);
# This is a knock on the snapshot door. Nothing of value in the content.
if ($ARGV[0] eq '') {
# If the target page is redirected, get the contents of the new page.
if ($contents =~ /The resource has been moved to http:\/\/[0-9\.]+:5002\/(archive\/neurodebian\/\d{8}T\d{6}Z\/)/) {
$contents = get_www_content($ARGV[0], $ARGV[1], $1);
# Search for and return the timestamp of the next snapshot after this one.
if ($contents =~ /\/archive\/neurodebian\/([0-9TZ]+)\/">next/) {
print $1;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment