Commit 06104899 authored by Matt Travers's avatar Matt Travers

BF: Update apt-get policy parsing to be more robust. Added docker to travis config.

parent 60501dee
......@@ -4,6 +4,8 @@
language: erlang
cache:
- apt
services:
- docker
script:
# Test the ultimate one-liner setup for NeuroDebian repository
- bash tools/neurodebian-travis.sh
......
......@@ -199,16 +199,18 @@ sub get_sources {
}
info "Discovering installed repository sources ...";
for my $i (0 .. $#lines) {
if ($lines[$i] =~ /(http\S+\/)([\w\-]+)\/?\s+(\S+)/) {
if ($lines[$i] =~ /(http\S+)\s+([\w-\/]+)\/([\w\-]+)/) {
my $url = $1;
my $repo = $2;
$3 =~ /([\w-\/]+)\/([\w\-]+)/;
my $archive = $1;
my $type = $2;
chop($url) if (substr($url, -1) eq '/');
my $repo = '';
my $archive = $2;
my $type = $3;
$lines[$i+1] =~ /o=(\w+),/;
my $domain = $1;
$repo = 'debian' if ($domain eq 'Debian');
$repo = 'debian-security' if ($domain eq 'Debian' && $url =~ 'security');
$repo = 'neurodebian' if ($domain eq 'NeuroDebian');
if ($domain ne "Ubuntu") { # Skip Ubuntu repos because there are not snapshots.
if ($domain ne "Ubuntu") { # Skip Ubuntu repos because there are no snapshots available.
my $key = "$domain|$repo|$archive";
if (exists $sources{$key}) {
$sources{$key}{type} .= " $type";
......@@ -218,6 +220,7 @@ sub get_sources {
repo => $repo,
archive => $archive,
type => $type,
url => $url
);
}
}
......@@ -309,12 +312,11 @@ sub disable_lines {
}
my $found = 0;
# Loop through the sources from apt-cache policy for each line in the
# sources file to determine if it is one we need to comment out.
# sources file to determine if it is one we need to comment out.
for my $key (keys %sources) {
$_ =~ /http:\/\/[^\/]+\/(.*)$/;
my $file_line = join ' ', sort split /\s+/, $1;
$sources{$key}{repo} = 'debian' if $sources{$key}{repo} eq 'neurodebian';
my $source_line = join ' ', sort split /\s+/, "$sources{$key}{repo} $sources{$key}{archive} $sources{$key}{type}";
$_ =~ /(http:\S+)(.*)$/;
my $file_line = $1 . join ' ', sort split /\s+/, $2;
my $source_line = $sources{$key}{url} . ' ' . join ' ', sort split /\s+/, "$sources{$key}{archive} $sources{$key}{type}";
if ($file_line eq $source_line) {
$found = 1;
last;
......
......@@ -109,10 +109,10 @@ assert_line_in_file "snapshots.sources.list" "deb http://snapshot-neuro.debian.n
assert_line_in_file "snapshots.sources.list" "deb http://snapshot.debian.org/archive/debian/20170727T040550Z/ jessie main"
assert_line_in_file "snapshots.sources.list" "deb http://snapshot.debian.org/archive/debian-security/20170727T203455Z/ jessie/updates main"
assert_line_in_file "sources.list" "# deb http://deb.debian.org/debian jessie main"
assert_line_in_file "sources.list" "# deb http://security.debian.org/debian-security jessie/updates main"
assert_line_in_file "sources.list" "# deb http://security.debian.org" "partial_match"
assert_line_in_file "sources.list" "# deb http://deb.debian.org/debian jessie-updates main"
assert_line_in_file "sources.list.original" "deb http://deb.debian.org/debian jessie main"
assert_line_in_file "sources.list.original" "deb http://security.debian.org/debian-security jessie/updates main"
assert_line_in_file "sources.list.original" "deb http://security.debian.org" "partial_match"
assert_line_in_file "sources.list.original" "deb http://deb.debian.org/debian jessie-updates main"
test_teardown
......@@ -129,10 +129,10 @@ assert_line_in_file "snapshots.sources.list" "deb http://snapshot.debian.org/arc
assert_line_in_file "snapshots.sources.list" "deb http://snapshot.debian.org/archive/debian-security/20180103T134828Z/ wheezy/updates main"
assert_line_in_file "sources.list" "# deb http://deb.debian.org/debian wheezy main"
assert_line_in_file "sources.list" "# deb http://deb.debian.org/debian wheezy-updates main"
assert_line_in_file "sources.list" "# deb http://security.debian.org/debian-security wheezy/updates main"
assert_line_in_file "sources.list" "# deb http://security.debian.org" "partial_match"
assert_line_in_file "sources.list.original" "deb http://deb.debian.org/debian wheezy main"
assert_line_in_file "sources.list.original" "deb http://deb.debian.org/debian wheezy-updates main"
assert_line_in_file "sources.list.original" "deb http://security.debian.org/debian-security wheezy/updates main"
assert_line_in_file "sources.list.original" "deb http://security.debian.org" "partial_match"
test_teardown
echo "[ Test handling of request for a snapshot in the future ]"
......@@ -140,8 +140,8 @@ test_setup "neurodebian" "jessie" "20280827"
assert_line_in_file "neurodebian.sources.list" "deb http://neuro.debian.net/debian jessie main"
assert_line_in_file "sources.list" "deb http://deb.debian.org/debian jessie main"
assert_line_in_file "sources.list" "deb http://deb.debian.org/debian jessie-updates main"
assert_line_in_file "sources.list" "deb http://security.debian.org/debian-security jessie/updates main"
assert_line_in_file "stdout" 'I: WARNING: User specified time (20200827T000000Z) later than latest snapshot available' "partial_match"
assert_line_in_file "sources.list" "deb http://security.debian.org" "partial_match"
assert_line_in_file "stdout" 'I: WARNING: User specified time (20280827T000000Z) later than latest snapshot available' "partial_match"
test_teardown
echo "[ Test Ubuntu release ]"
......@@ -167,7 +167,7 @@ assert_line_in_file "snapshots.sources.list" "deb http://snapshot-neuro.debian.n
assert_line_in_file "snapshots.sources.list" "deb http://snapshot.debian.org/archive/debian/20170727T040550Z/ jessie main"
assert_line_in_file "snapshots.sources.list" "deb http://snapshot.debian.org/archive/debian-security/20170727T203455Z/ jessie/updates main"
assert_line_in_file "sources.list" "deb http://deb.debian.org/debian jessie main"
assert_line_in_file "sources.list" "deb http://security.debian.org/debian-security jessie/updates main"
assert_line_in_file "sources.list" "deb http://security.debian.org" "partial_match"
assert_line_in_file "sources.list" "deb http://deb.debian.org/debian jessie-updates main"
test_teardown
......
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