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
|
#!/usr/bin/perl
#
# $Id: apt-config,v 1.2 2000/10/18 07:24:49 bod Exp $
#
# Example: apt-config in perl. See apt-config(8).
#
use AptPkg::Config '$_config';
(my $self = $0) =~ s#.*/##;
# initialise the global config object with the default values
$_config->init;
# parse the command line
@ARGV = $_config->parse_cmdline([
[ 'h', 'help', 'help' ],
[ 'v', 'version', 'version' ],
[ 'c', 'config-file', '', 'ConfigFile' ],
[ 'o', 'option', '', 'ArbItem' ],
], @ARGV);
if (my $v_opt = $_config->get_bool('version') or # --version
$_config->get_bool('help') or # --help
!@ARGV) # no args
{
# we don't have the PACKAGE/VERSION &c apt-config has... punt
print "$self (using AptPkg $AptPkg::VERSION, built for ",
"$_config->{APT::Architecture})\n";
print <<EOT unless $v_opt;
Usage: $self [options] command
$self is a simple tool to read the APT config file
Commands:
shell - Shell mode
dump - Show the configuration
Options:
-h This help text.
-c=? Read this configuration file
-o=? Set an arbitary configuration option, eg -o dir::cache=/tmp
EOT
exit;
}
# dispatch args
my $op = shift;
if ($op eq 'dump')
{
$_config->dump;
exit;
}
die "$self: invalid operation `$op'\n" unless $op eq 'shell';
while (@ARGV)
{
my $var = shift;
my $cname = shift or die "$self: arguments not in pairs\n";
local $_;
# check if the caller has requested a directory path in the old format
$cname .= 'd' if $cname =~ m#/$#;
$_ = $_config->get($cname) if $_config->exists($cname);
next unless defined;
if (m#[^\w@+,./:=-]#)
{
# quote
s/'/'\\''/g;
$_ = "'$_" unless s/^'//;
$_ = "$_'" unless s/'$//;
}
print "$var=$_\n";
}
|