/usr/sbin/update-cudf-solvers is in apt-cudf 3.1.3-7build1.
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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | #!/usr/bin/perl -w
#
# update-cudf-solvers: register available CUDF solvers and bind them to APT
#
# Copyright: © Stefano Zacchiroli 2011 <zack@debian.org>
# License: GNU Lesser General Public License, version 3 or above
use strict;
use File::Basename;
use File::Path qw(make_path);
use Getopt::Long;
use Pod::Usage;
# configuration
my $cudf_dir = "/usr/share/cudf/solvers";
my $edsp_dir = "/usr/lib/apt/solvers";
my $apt_cudf = "/usr/bin/apt-cudf";
# globals
my $debug = 0;
my $help_action = 0;
my $list_action = 0;
my $remove_action = 0;
sub warning($) {
my ($msg) = @_;
print STDERR "update-cudf-solvers: W: $msg\n";
}
sub debug($) {
my ($msg) = @_;
print STDERR "update-cudf-solvers: I: $msg\n" if $debug;
}
sub die_usage() {
my %podflags = ( "verbose" => 1,
"exitval" => 2 );
pod2usage(%podflags);
}
sub shallow_find($) {
my ($dir, $pred) = @_;
my @found = ();
foreach my $f (`find $dir -maxdepth 1 -mindepth 1 -type f -o -type l`) {
chomp $f;
push @found, basename $f;
}
return @found;
}
# check whether a given EDSP solver path originates from a CUDF solver
sub is_cudf_solver($) {
my ($path) = @_;
return (-l $path && readlink($path) eq $apt_cudf);
}
# install: act on new CUDF solvers; make them available as EDSP solvers
sub install_new($$) {
my ($cudf_solvers, $edsp_solvers) = @_;
foreach my $cudf_name (@$cudf_solvers) {
my $edsp_solver = "$edsp_dir/$cudf_name";
next if is_cudf_solver($edsp_solver);
if (-e $edsp_solver || -l $edsp_solver) {
# either existing non CUDF solver or dangling symlink
warning "refuse to overwrite $edsp_solver with a symlink to $apt_cudf, skipping";
} else { # file exists, but doesn't point to apt-cudf
debug "symlink $edsp_solver to $apt_cudf";
symlink $apt_cudf, $edsp_solver
or warning "cannot symlink $edsp_solver to $apt_cudf, skipping";
}
}
}
# garbage collection: act on old EDSP solvers; get rid of them
sub remove_old($$) {
my ($cudf_solvers, $edsp_solvers) = @_;
foreach my $edsp_name (@$edsp_solvers) {
my $edsp_solver = "$edsp_dir/$edsp_name";
next unless is_cudf_solver($edsp_solver);
if (! grep {"$_" eq "$edsp_name"} @$cudf_solvers) {
# EDSP && CUDF solver, no longer existing
debug "unlink (gone) $edsp_solver";
unlink $edsp_solver
or warning "cannot unlink $edsp_solver, skipping";
}
}
}
# remove all EDSP solvers originating from CUDF solvers
sub remove_all($$) {
my ($cudf_solvers, $edsp_solvers) = @_;
foreach my $edsp_name (@$edsp_solvers) {
my $edsp_solver = "$edsp_dir/$edsp_name";
if (is_cudf_solver($edsp_solver)) {
unlink $edsp_solver
or warning "cannot unlink $edsp_solver, skipping";
}
}
}
sub main() {
my $getopt = GetOptions(
"d|debug" => \$debug,
"h|help" => \$help_action,
"l|list" => \$list_action,
"r|remove" => \$remove_action,
);
die_usage if (! $getopt || $help_action);
-d $edsp_dir or make_path($edsp_dir, { mode => 0755 });
my @cudf_solvers = shallow_find($cudf_dir);
my @edsp_solvers = shallow_find($edsp_dir);
if ($debug) {
foreach my $s (@cudf_solvers) { debug "found cudf solver: $s"; }
foreach my $s (@edsp_solvers) { debug "found edsp solver: $s"; }
}
if ($list_action) {
foreach my $s (@cudf_solvers) { print "cudf: $s\n"; }
foreach my $s (@edsp_solvers) { print "edsp: $s\n"; }
} elsif ($remove_action) {
remove_all(\@cudf_solvers, \@edsp_solvers);
} else {
install_new(\@cudf_solvers, \@edsp_solvers);
remove_old(\@cudf_solvers, \@edsp_solvers);
}
exit 0;
}
main();
__END__
=head1 NAME
update-cudf-solvers - register available CUDF solvers as APT external solvers
=head1 SYNOPSIS
=over
=item B<update-cudf-solvers> [I<OPTION>]...
=item B<update-cudf-solvers> [I<OPTION>]... --remove
=item B<update-cudf-solvers> [I<OPTION>]... --list
=back
=head1 DESCRIPTION
update-cudf-solvers maintain the list of installed CUDF solvers and register
them as external solvers for APT.
The first form (without mandatory options) should be invoked each time a new
CUDF solver specification file is added to or removed from the CUDF solver
specification directory (by default F</usr/share/cudf/solvers>).
update-cudf-solvers will synchronize the differences with APT external solvers,
by installing suitable symlinks to the F</usr/bin/apt-cudf> wrapper under
F</usr/lib/apt/solvers>.
The second form (with the mandatory C<--remove> option) will remove all
installed external APT solvers that originated from CUDF solvers. It's a
cleanup operation meant to be used only upon removal of the apt-cudf package.
The third form just lists available solvers and exit.
Note that other, non-CUDF based, APT external solvers might be present under
F</usr/lib/apt/solvers>. update-cudf-solvers leaves the untouched and act only
on (present or past) APT solvers corresponding to CUDF solvers.
=head1 TRIGGER-BASED OPERATION
The directory F</usr/share/cudf/solvers> is monitored by a dpkg trigger that
invokes update-cudf-solvers as needed. In all but exceptional circumstances,
you should not be required to opearte update-cudf-solvers manually.
=head1 OPTIONS
=over 4
=item -d
=item --debug
Print debugging information during operation.
=item -h
=item --help
Show usage information and exit.
=item -l
=item --list
List available solvers and exit. Both CUDF and APT's external solvers (AKA
"EDSP solvers") will be listed.
=item -r
=item --remove
Unregister all CUDF solvers.
=back
=head1 SEE ALSO
apt-get(8), apt-cudf(8),
L<README.cudf-solvers|file:///usr/share/doc/apt-cudf/README.cudf-solvers>,
L<README.Debian|file:///usr/share/doc/apt-cudf/README.Debian>
=head1 AUTHOR
Copyright: (C) 2011 Stefano Zacchiroli <zack@debian.org>
License: GNU Lesser General Public License (GPL), version 3 or above
=cut
|