3
# This package doesn't depend on perl, so make sure that everything done
4
# in this script can be done with perl-base. In particular, using any
5
# Perl modules other than the Debconf modules and the basic pragmata
6
# probably isn't valid.
11
use Debconf::Client::ConfModule ':all';
13
my $conffile="/etc/apt-fast.conf";
14
$_ = '' for my ($aptmanager, $downloader, $downloadcmd, $maxdownloads,
15
$maxconpersrv, $maxconperfile, $minsplitsize, $piecealgo,
16
$tmpdownloaddir, $tmpdownloadlist, $aptcache, $dlflag);
19
my ($customcmd, $dl_list) = (0, 0);
21
my $ariacmd = 'aria2c --no-conf -c -j ${_MAXNUM} -x ${_MAXCONPERSRV} -s ${_SPLITCON} --min-split-size=${_MINSPLITSZ} --stream-piece-selector=${_PIECEALGO} -i ${DLLIST} --connect-timeout=600 --timeout=600 -m0';
23
version('2.0') or die "Failed to start debconf.\n";
25
# Check if aptitude is installed. If not set low priority to package manager
28
return 1 if (`which aptitude`);
32
# Check if aptitude is installed. If not set low priority to package manager
35
return 1 if (`which apt`);
39
# default debconf question loop
44
my $val = shift || '';
45
my $switch = shift; # optional switch to num or cmd
46
my $maxval = shift; # optional maximum value for num
47
my $suffix = shift; # optional suffix string
50
if (defined $suffix) {
51
$val =~ s/\Q$suffix\E$//;
54
if ((defined $switch) && ($switch eq "num")){
55
$val = '' unless ($val =~ /(^\d+$)/ && !(defined $maxval && $val > $maxval));
58
if ((length ($val // '')) &&
59
((! ((defined $switch) && ($switch eq "num"))) || ($val > 0)) &&
60
((! ((defined $switch) && ($switch eq "cmd"))) || (`which $val`))){
62
if (input($priority, "apt-fast/$type") eq "question will be asked"){
63
set("apt-fast/$type", $val);
67
$priority = "high" unless (($priority eq "critical") or not $ok);
68
if (input($priority, "apt-fast/$type") eq "question will be asked"){
69
reset("apt-fast/$type");
73
$val = get("apt-fast/$type");
74
if (defined $suffix && not $val =~ /\Q$suffix\E$/) {
75
set("apt-fast/$type", $val . $suffix);
84
open(FILE, $conffile) or die "Could not open config file: $conffile\n$!";
86
if (!/^[\s]*(#.*|)$/){ # omit empty or commented lines
87
#FIXME: (quoted) '#' characters (within values) break parsing.
88
if (/^[\s]*([^#]+)/){ # get regular lines without comments
91
if ($line =~ /([^=]*[^\s=]+)=([\s]*|[^\s]+.*)$/){ # split key and value
92
my ($val, $res) = ($1, $2);
94
$res =~ s/^'(.*)'$/$1/ or $res =~ s/^"(.*)"$/$1/; # remove quotes
95
#print STDERR "||$val||$res||\n";
97
if ($val eq "_MAXNUM"){
100
elsif ($val eq "_MAXCONPERSRV"){
101
$maxconpersrv = $res;
103
elsif ($val eq "_SPLITCON"){
104
$maxconperfile = $res;
106
elsif ($val eq "_MINSPLITSZ"){
107
$minsplitsize = $res;
109
elsif ($val eq "_PIECEALGO"){
112
elsif ($val eq "_APTMGR"){
115
elsif ($val eq "_DOWNLOADER"){
118
elsif ($val eq "DOWNLOADBEFORE"){
121
elsif ($val eq "DLDIR"){
122
$tmpdownloaddir = $res;
124
elsif ($val eq "DLLIST"){
125
$tmpdownloadlist = $res;
127
elsif ($val eq "APTCACHE"){
130
} else {die "Error parsing config file $conffile line $..\n";}
138
# analyse parsed values and set questions with debconf
140
if (&checkaptitude or &checkapt) {
146
&debconfloop("aptmanager", $priority, $aptmanager, "cmd");
151
# Compatibility check for upgrades from < 1.8.
152
if (get("apt-fast/downloader") eq "axel") {
153
fset("apt-fast/downloader", "seen", "false");
154
fset("apt-fast/downloadcmd", "seen", "false");
159
$priority = "medium";
161
# Transition to new aria2c command
162
if($downloadcmd eq 'aria2c -c -j ${_MAXNUM} -i ${DLLIST} --connect-timeout=600 --timeout=600 -m0') {
163
$downloadcmd = $ariacmd;
165
elsif($downloadcmd eq 'aria2c -c -j ${_MAXNUM} -x ${_MAXNUM} -s ${_MAXNUM} --min-split-size=1M -i ${DLLIST} --connect-timeout=600 --timeout=600 -m0') {
166
$downloadcmd = $ariacmd;
169
if (length ($downloadcmd // '')){
171
if ($downloadcmd eq $ariacmd){ # just a very simple comparison
172
if (input($priority, "apt-fast/downloader") eq "question will be asked"){
173
set("apt-fast/downloader", "aria2c");
175
($downloadcmd, $downloader) = ($ariacmd, "aria2c");
178
if (input($priority, "apt-fast/downloader") eq "question will be asked"){
179
set("apt-fast/downloader", "custom");
181
$downloader = "custom";
185
($downloadcmd, $downloader) = ($ariacmd, "aria2c");
186
$priority = "high" if $ok;
187
if (input($priority, "apt-fast/downloader") eq "question will be asked"){
188
set("apt-fast/downloader", $downloader);
192
$downloader = get("apt-fast/downloader");
195
set("apt-fast/downloadcmd", $downloadcmd) unless ($downloader eq "custom");
199
if ($downloader eq "aria2c"){
200
$downloadcmd = $ariacmd;
203
$customcmd = 1; # remember if custom command is used
205
$priority = $customcmd ? "critical" : "low";
207
if (length ($downloadcmd // '')){
209
if (input($priority, "apt-fast/downloadcmd") eq "question will be asked"){
210
set("apt-fast/downloadcmd", $downloadcmd);
214
if ($downloader eq "aria2c"){
215
$downloadcmd = $ariacmd;
218
($downloadcmd, $downloader) = ($ariacmd, "aria2c");
220
$priority = "high" unless (($priority eq "critical") or not $ok);
221
if ((input($priority, "apt-fast/downloadcmd") eq "question will be asked")
222
# This is needed to fix LP #1064656 (endless loop if DEBIAN_PRIORITY is
223
# critical or frontend noninteractive).
224
or (fget("apt-fast/downloadcmd", "seen") eq "false")){
225
set("apt-fast/downloader", $downloader);
226
set("apt-fast/downloadcmd", $downloadcmd);
230
$downloadcmd = get("apt-fast/downloadcmd");
235
# skip if it is not used in _DOWNLOADER
236
if ($downloadcmd =~ /\$\{_MAXNUM}/){
237
&debconfloop("maxdownloads", $customcmd ? "critical" : "high", $maxdownloads, "num");
240
set("apt-fast/maxdownloads", "");
244
# skip if it is not used in _DOWNLOADER
245
if ($downloadcmd =~ /\$\{_MAXCONPERSRV}/){
246
&debconfloop("maxconpersrv", $customcmd ? "critical" : "medium", $maxconpersrv, "num", 16);
249
set("apt-fast/maxconpersrv", "");
253
# skip if it is not used in _DOWNLOADER
254
if ($downloadcmd =~ /\$\{_SPLITCON}/){
255
&debconfloop("maxconperfile", $customcmd ? "critical" : "medium", $maxconperfile, "num");
258
set("apt-fast/maxconperfile", "");
262
# skip if it is not used in _DOWNLOADER
263
if ($downloadcmd =~ /\$\{_MINSPLITSZ}/){
264
&debconfloop("minsplitsize", $customcmd ? "critical" : "medium", $minsplitsize, "num", 1024, "M");
267
set("apt-fast/minsplitsize", "");
271
# skip if it is not used in _DOWNLOADER
272
if ($downloadcmd =~ /\$\{_PIECEALGO}/){
273
&debconfloop("piecealgo", $customcmd ? "critical" : "medium", $piecealgo);
276
set("apt-fast/piecealgo", "");
280
$dl_list = 1 if ($downloadcmd ne $ariacmd);
281
&debconfloop("tmpdownloadlist", ($customcmd or $dl_list) ? "critical" : "low", $tmpdownloadlist);
284
&debconfloop("dlflag", "high", $dlflag);
287
&debconfloop("tmpdownloaddir", "low", $tmpdownloaddir);
290
# Set archive directory:
291
my $archivedir = `apt-config shell var Dir::Cache::archives/d`;
292
$archivedir =~ s/^var='(.+)'\n/$1/;
297
if (length ($aptcache // '')){
299
if (input($priority, "apt-fast/aptcache") eq "question will be asked"){
300
set("apt-fast/aptcache", $aptcache);
304
$priority = "high" if $ok;
305
if (input($priority, "apt-fast/aptcache") eq "question will be asked"){
306
set("apt-fast/aptcache", $archivedir);
310
$aptcache = get("apt-fast/aptcache");