/usr/bin/xt-guess-suite-and-mirror is in xen-tools 4.2.1-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | #!/usr/bin/perl -w
=head1 NAME
xt-guess-suite-and-mirror - Tries to guess the most suitable suite and
mirror for DomUs on Debian and Ubuntu Dom0s.
=cut
=head1 SYNOPSIS
--suite Show suite
--mirror Show mirror
Shows both if no parameter is given.
Help Options:
--help Show the help information for this script.
--manual Show the manual for this script.
--version Show the version number and exit.
=cut
=head1 DESCRIPTION
xt-guess-suite-and-mirror tries to find the mirror and suite the Xen
Dom0 is currently using and returns them in a way suitable for
xen-create-image(1) or the backticks feature in xen-tools.conf.
=cut
=head1 AUTHORS
Axel Beckert, http://noone.org/abe/
Stéphane Jourdois
=cut
=head1 LICENSE
Copyright (C) 2010 by The Xen-Tools Development Team. All rights
reserved.
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself. The LICENSE file contains the
full text of the license.
=cut
###
### Configuration
###
# Fallback to Debian or Ubuntu in case we can't find anything
my $fallback = 'Debian';
# Which mirrors to use if everything else fails (cdn.debian.net uses
# GeoIP, see http://wiki.debian.org/DebianGeoMirror)
my %fallback_mirror = ( Debian => 'http://cdn.debian.net/debian/',
Ubuntu => 'http://archive.ubuntu.com/ubuntu/' );
# Which suite to use if everything else fails. For Debian "stable"
# should be the best choice independent of the time. Ubuntu does not
# have aliases like stable or testing, so we take the nearest LTS
# release which is 10.04 at the time of writing.
my %fallback_suite = ( Debian => 'stable',
Ubuntu => 'lucid' );
# Where to look for the sources.list to parse
my $sources_list_file = '/etc/apt/sources.list';
use File::Slurp;
use Getopt::Long;
use Pod::Usage;
use strict;
#
# Release number.
#
my $RELEASE = '4.2.1';
# Init
my $mirror = '';
my $suite = '';
my $found = 0;
# Parsing command line options
my $want_mirror = 0;
my $want_suite = 0;
my $want_version = 0;
my $want_help = 0;
my $want_manual = 0;
my $result = GetOptions( 'mirror|m' => \$want_mirror,
'suite|s' => \$want_suite,
'version' => \$want_version,
'manual' => \$want_manual,
'help' => \$want_help );
if ($want_help) {
pod2usage(0);
}
if ($want_manual) {
pod2usage( -verbose => 2 );
}
if (-r $sources_list_file) {
# sources.list exists, so it's something debianoid.
# read sources.list and split it into lines
my @sources_list = read_file($sources_list_file);
# Find the first line which is a Debian or Ubuntu mirror but not
# an updates, backports, volatile or security mirror.
foreach my $sources_list_entry (@sources_list) {
# Normalize line
chomp($sources_list_entry);
$sources_list_entry =~ s/^\s*(.*?)\s*$/$1/;
# Skip definite non-entries
next if $sources_list_entry =~ /^\s*($|#)/;
# Split up into fields
my @source_components = split(/\s+/, $sources_list_entry);
# Minimum number of components is 4
next if $#source_components < 3;
# Don't use deb-src entries.
next if $source_components[0] eq 'deb-src';
# Skip updates, backports, volatile or security mirror.
next if $source_components[2] !~ /^[a-z]+$/;
if ($source_components[1] =~ m(/debian/?$|/ubuntu/?$)) {
# Seems a typical mirror. Let's use that one
$mirror = $source_components[1];
$suite = $source_components[2];
$found = 1;
last;
}
}
warn "Couldn't parse $sources_list_file of the Dom0.\n" unless $found;
}
my $lsb_release = `which lsb_release`;
chomp($lsb_release);
if (!$found and $lsb_release and -x $lsb_release) {
my $vendor = `$lsb_release -s -i`;
if ($vendor eq 'Debian' or $vendor eq 'Ubuntu') {
$suite = `$lsb_release -s -c`;
chomp($suite);
unless ($suite) {
$suite = $fallback_suite{$vendor};
warn "Dom0 seems to be $vendor, but couldn't determine suite. Falling back to $suite.\n";
}
$mirror = $fallback_mirror{$vendor};
$found = 1;
}
}
if ($found) {
unless ($want_help || $want_version || $want_suite || $want_mirror) {
print "$mirror $suite\n";
} else {
if ($want_mirror) {
print "$mirror";
}
if ($want_suite) {
print "$suite";
}
print "\n";
}
} else {
$suite = $fallback_suite{$fallback};
$mirror = $fallback_mirror{$fallback};
}
|