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
|
#!/usr/bin/perl
#
# Common.pl: Holds routines common to a few scripts of
# localization-config
# Based on the example apt-cache in libapt-pkg-perl
#
use AptPkg::Config '$_config';
use AptPkg::System '$_system';
use AptPkg::Cache;
use AptPkg::Version;
require '/usr/lib/localization-config/common/log.pl';
my $cache;
my $vs;
sub init {
# initialise the global config object with the default values and
# setup the $_system object
$_config->init;
$_system = $_config->system;
# supress cache building messages
$_config->{quiet} = 2;
# set up the cache
$cache = AptPkg::Cache->new;
$vs = $_system->versioning;
}
sub is_installed($) {
my ($pack) = @_;
my $p = $cache->{$pack};
unless ($p)
{
return 0;
}
if ($p->{CurrentVer}) {
return 1;
} else {
return 0;
}
}
sub is_available($) {
my ($pack) = @_;
my $p = $cache->{$pack};
my $res = 0;
log_msg("$0: Package: $pack");
if (my $available = $p->{VersionList})
{
# Check the first available version in package version list
# we only care about the latest package anyway.
$curver = @$available[0]->{VerStr};
log_msg("$0: Package $p is available");
$res = 1;
}
return $res;
}
# We only use this subroutine from the scripts.
# It takes the package name and it's version map
# and it returns the most probable release name for
# this package.
# According to this release name, we execute the
# appropriate configuration script.
sub get_release($) {
my ($pack, %vermap) = @_;
my $p = $cache->{$pack};
my $rel;
unless ($p)
{
log_msg("$0: Fallback to /etc/debian_version");
$rel = get_debian_version();
log_msg("$0: Release to be used: $release");
return $rel;
}
log_msg("$0: Package: $pack");
if ($p->{CurrentVer}) {
my $curver = $p->{CurrentVer}{VerStr};
$rel = check_vermap($curver, %vermap);
log_msg("$0: CurrentVer: $curver");
} else {
log_msg("$0: Not Installed");
log_msg("$0: Checking Available versions");
if (my $available = $p->{VersionList})
{
# Check the first available version in package version list
# we only care about the latest package anyway.
$curver = @$available[0]->{VerStr};
$rel = check_vermap($curver, %vermap);
}
}
if ($rel eq "") {
$rel = get_debian_version();
}
log_msg("$0: Release to be used: $rel");
return $rel;
}
# This subroutine does the actual retrieval of the
# release name in the version map.
sub check_vermap($) {
my ($ver, %vermap) = @_;
my $rel;
for $v (sort keys %vermap) {
if ($ver ge $v) {
# print "$v\t".$vermap{$v}->{'RELEASE'}."\n";
$rel = $vermap{$v}->{'RELEASE'};
}
}
return $rel;
}
# Will return the first correct supported Debian version
# according to the value in /etc/debian_version
# This is used only as last resort.
sub get_debian_version {
my %supported_versions = ( 'woody' => { RELEASE => 'woody' },
'sarge' => { RELEASE => 'sarge' },
'testing/unstable' => { RELEASE => 'etch' },
'3.1' => { RELEASE => 'sarge' }
);
my $debver_file= "/etc/debian_version";
my $version, my $found, my $folder;
open(DAT, $debver_file) || log_die("$0: Could not open /etc/debian_version!");
my @raw_data=<DAT>;
close(DAT);
foreach $version (@raw_data) {
chop($version);
if (defined($found = $supported_versions{$version})) {
return $found->{'RELEASE'};
}
}
}
sub get_subarch() {
my $subarch = 'none';
my $proc_arch = `grep ^machine /proc/cpuinfo`;
if ($proc_arch =~ /PReP.Blackhawk/) {
$subarch = 'ppcbug';
} elsif ($proc_arch =~ /PReP/ ) {
$subarch = 'prep';
} elsif ($proc_arch =~ /CHRP/ ) {
$subarch = 'chrp';
} elsif ($proc_arch =~ /NewWorld/ ) {
$subarch = 'pmac_newworld';
} elsif ($proc_arch =~ /OldWorld/ ) {
$subarch = 'pmac_oldworld';
} elsif ($proc_arch =~ /Amiga/ ) {
$subarch = 'amiga';
}
return $subarch;
}
1;
|