~apt-fast/apt-fast/git-import

« back to all changes in this revision

Viewing changes to debian/config

  • Committer: lasserre.d at gmail
  • Date: 2017-11-11 04:01:23 UTC
  • Revision ID: lasserre.d@gmail.com-20171111040123-yav8n8gkt5j5lv3a
Initial import.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
 
 
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.
 
7
 
 
8
use strict;
 
9
use warnings;
 
10
 
 
11
use Debconf::Client::ConfModule ':all';
 
12
 
 
13
my $conffile="/etc/apt-fast.conf";
 
14
$_ = '' for my ($aptmanager, $downloader, $downloadcmd, $maxdownloads,
 
15
    $maxconpersrv, $maxconperfile, $minsplitsize, $piecealgo,
 
16
    $tmpdownloaddir, $tmpdownloadlist, $aptcache, $dlflag);
 
17
my $ok;
 
18
my $priority;
 
19
my ($customcmd, $dl_list) = (0, 0);
 
20
 
 
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';
 
22
 
 
23
version('2.0') or die "Failed to start debconf.\n";
 
24
 
 
25
# Check if aptitude is installed. If not set low priority to package manager
 
26
# question.
 
27
sub checkaptitude{
 
28
  return 1 if (`which aptitude`);
 
29
  return 0;
 
30
}
 
31
 
 
32
# Check if aptitude is installed. If not set low priority to package manager
 
33
# question.
 
34
sub checkapt{
 
35
  return 1 if (`which apt`);
 
36
  return 0;
 
37
}
 
38
 
 
39
# default debconf question loop
 
40
sub debconfloop{
 
41
  my $ok = 0;
 
42
  my $type = shift;
 
43
  my $priority = shift;
 
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
 
48
 
 
49
  while (1){
 
50
    if (defined $suffix) {
 
51
      $val =~ s/\Q$suffix\E$//;
 
52
    }
 
53
 
 
54
    if ((defined $switch) && ($switch eq "num")){
 
55
      $val = '' unless ($val =~ /(^\d+$)/ && !(defined $maxval && $val > $maxval));
 
56
    }
 
57
 
 
58
    if ((length ($val // '')) &&
 
59
        ((! ((defined $switch) && ($switch eq "num"))) || ($val > 0)) &&
 
60
        ((! ((defined $switch) && ($switch eq "cmd"))) || (`which $val`))){
 
61
      last if $ok;
 
62
      if (input($priority, "apt-fast/$type") eq "question will be asked"){
 
63
        set("apt-fast/$type", $val);
 
64
      }
 
65
    }
 
66
    else {
 
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");
 
70
      }
 
71
    }
 
72
    go();
 
73
    $val = get("apt-fast/$type");
 
74
    if (defined $suffix && not $val =~ /\Q$suffix\E$/) {
 
75
      set("apt-fast/$type", $val . $suffix);
 
76
    }
 
77
    $ok = 1;
 
78
  }
 
79
}
 
80
 
 
81
 
 
82
# parse config file
 
83
if (-f $conffile){
 
84
  open(FILE, $conffile) or die "Could not open config file: $conffile\n$!";
 
85
  while(<FILE>){
 
86
    if (!/^[\s]*(#.*|)$/){  # omit empty or commented lines
 
87
      #FIXME: (quoted) '#' characters (within values) break parsing.
 
88
      if (/^[\s]*([^#]+)/){ # get regular lines without comments
 
89
        my $line = $1;
 
90
        chomp($line);
 
91
        if ($line =~ /([^=]*[^\s=]+)=([\s]*|[^\s]+.*)$/){ # split key and value
 
92
          my ($val, $res) = ($1, $2);
 
93
          $res =~ s/\s+$//;
 
94
          $res =~ s/^'(.*)'$/$1/ or $res =~ s/^"(.*)"$/$1/;  # remove quotes
 
95
          #print STDERR "||$val||$res||\n";
 
96
 
 
97
          if ($val eq "_MAXNUM"){
 
98
            $maxdownloads = $res;
 
99
          }
 
100
          elsif ($val eq "_MAXCONPERSRV"){
 
101
            $maxconpersrv = $res;
 
102
          }
 
103
          elsif ($val eq "_SPLITCON"){
 
104
            $maxconperfile = $res;
 
105
          }
 
106
          elsif ($val eq "_MINSPLITSZ"){
 
107
            $minsplitsize = $res;
 
108
          }
 
109
          elsif ($val eq "_PIECEALGO"){
 
110
            $piecealgo = $res;
 
111
          }
 
112
          elsif ($val eq "_APTMGR"){
 
113
            $aptmanager = $res;
 
114
          }
 
115
          elsif ($val eq "_DOWNLOADER"){
 
116
            $downloadcmd = $res;
 
117
          }
 
118
          elsif ($val eq "DOWNLOADBEFORE"){
 
119
            $dlflag = $res;
 
120
          }
 
121
          elsif ($val eq "DLDIR"){
 
122
            $tmpdownloaddir = $res;
 
123
          }
 
124
          elsif ($val eq "DLLIST"){
 
125
            $tmpdownloadlist = $res;
 
126
          }
 
127
          elsif ($val eq "APTCACHE"){
 
128
            $aptcache = $res;
 
129
          }
 
130
        } else {die "Error parsing config file $conffile line $..\n";}
 
131
      }
 
132
    }
 
133
  }
 
134
  close(FILE);
 
135
}
 
136
 
 
137
 
 
138
# analyse parsed values and set questions with debconf
 
139
# _APTMGR
 
140
if (&checkaptitude or &checkapt) {
 
141
  $priority = "high";
 
142
}
 
143
else {
 
144
  $priority = "low";
 
145
}
 
146
&debconfloop("aptmanager", $priority, $aptmanager, "cmd");
 
147
 
 
148
# _DOWNLOADER
 
149
# downloader
 
150
$ok = 0;
 
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");
 
155
  $downloadcmd = "";
 
156
  $priority = "high";
 
157
}
 
158
else {
 
159
  $priority = "medium";
 
160
}
 
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;
 
164
}
 
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;
 
167
}
 
168
while (1){
 
169
  if (length ($downloadcmd // '')){
 
170
    last if $ok;
 
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");
 
174
      }
 
175
      ($downloadcmd, $downloader) = ($ariacmd, "aria2c");
 
176
    }
 
177
    else {
 
178
      if (input($priority, "apt-fast/downloader") eq "question will be asked"){
 
179
        set("apt-fast/downloader", "custom");
 
180
      }
 
181
      $downloader = "custom";
 
182
    }
 
183
  }
 
184
  else {
 
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);
 
189
    }
 
190
  }
 
191
  go();
 
192
  $downloader = get("apt-fast/downloader");
 
193
  $ok = 1;
 
194
}
 
195
set("apt-fast/downloadcmd", $downloadcmd) unless ($downloader eq "custom");
 
196
 
 
197
# downloadcmd
 
198
$ok = 0;
 
199
if ($downloader eq "aria2c"){
 
200
  $downloadcmd = $ariacmd;
 
201
}
 
202
else {
 
203
  $customcmd = 1; # remember if custom command is used
 
204
}
 
205
$priority = $customcmd ? "critical" : "low";
 
206
while (1){
 
207
  if (length ($downloadcmd // '')){
 
208
    last if $ok;
 
209
    if (input($priority, "apt-fast/downloadcmd") eq "question will be asked"){
 
210
      set("apt-fast/downloadcmd", $downloadcmd);
 
211
    }
 
212
  }
 
213
  else {
 
214
    if ($downloader eq "aria2c"){
 
215
      $downloadcmd = $ariacmd;
 
216
    }
 
217
    else {
 
218
      ($downloadcmd, $downloader) = ($ariacmd, "aria2c");
 
219
    }
 
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);
 
227
    }
 
228
  }
 
229
  go();
 
230
  $downloadcmd = get("apt-fast/downloadcmd");
 
231
  $ok = 1;
 
232
}
 
233
 
 
234
# _MAXNUM
 
235
# skip if it is not used in _DOWNLOADER
 
236
if ($downloadcmd =~ /\$\{_MAXNUM}/){
 
237
  &debconfloop("maxdownloads", $customcmd ? "critical" : "high", $maxdownloads, "num");
 
238
}
 
239
else {
 
240
  set("apt-fast/maxdownloads", "");
 
241
}
 
242
 
 
243
# _MAXCONPERSRV
 
244
# skip if it is not used in _DOWNLOADER
 
245
if ($downloadcmd =~ /\$\{_MAXCONPERSRV}/){
 
246
  &debconfloop("maxconpersrv", $customcmd ? "critical" : "medium", $maxconpersrv, "num", 16);
 
247
}
 
248
else {
 
249
  set("apt-fast/maxconpersrv", "");
 
250
}
 
251
 
 
252
# _SPLITCON
 
253
# skip if it is not used in _DOWNLOADER
 
254
if ($downloadcmd =~ /\$\{_SPLITCON}/){
 
255
  &debconfloop("maxconperfile", $customcmd ? "critical" : "medium", $maxconperfile, "num");
 
256
}
 
257
else {
 
258
  set("apt-fast/maxconperfile", "");
 
259
}
 
260
 
 
261
# _MINSPLITSZ
 
262
# skip if it is not used in _DOWNLOADER
 
263
if ($downloadcmd =~ /\$\{_MINSPLITSZ}/){
 
264
  &debconfloop("minsplitsize", $customcmd ? "critical" : "medium", $minsplitsize, "num", 1024, "M");
 
265
}
 
266
else {
 
267
  set("apt-fast/minsplitsize", "");
 
268
}
 
269
 
 
270
# _PIECEALGO
 
271
# skip if it is not used in _DOWNLOADER
 
272
if ($downloadcmd =~ /\$\{_PIECEALGO}/){
 
273
  &debconfloop("piecealgo", $customcmd ? "critical" : "medium", $piecealgo);
 
274
}
 
275
else {
 
276
  set("apt-fast/piecealgo", "");
 
277
}
 
278
 
 
279
# DLLIST
 
280
$dl_list = 1 if ($downloadcmd ne $ariacmd);
 
281
&debconfloop("tmpdownloadlist", ($customcmd or $dl_list) ? "critical" : "low", $tmpdownloadlist);
 
282
 
 
283
# DOWNLOADBEFORE
 
284
&debconfloop("dlflag", "high", $dlflag);
 
285
 
 
286
# DLDIR
 
287
&debconfloop("tmpdownloaddir", "low", $tmpdownloaddir);
 
288
 
 
289
# APTCACHE
 
290
# Set archive directory:
 
291
my $archivedir = `apt-config shell var Dir::Cache::archives/d`;
 
292
$archivedir =~ s/^var='(.+)'\n/$1/;
 
293
 
 
294
$ok = 0;
 
295
$priority = "low";
 
296
while (1){
 
297
  if (length ($aptcache // '')){
 
298
    last if $ok;
 
299
    if (input($priority, "apt-fast/aptcache") eq "question will be asked"){
 
300
      set("apt-fast/aptcache", $aptcache);
 
301
    }
 
302
  }
 
303
  else {
 
304
    $priority = "high" if $ok;
 
305
    if (input($priority, "apt-fast/aptcache") eq "question will be asked"){
 
306
      set("apt-fast/aptcache", $archivedir);
 
307
    }
 
308
  }
 
309
  go();
 
310
  $aptcache = get("apt-fast/aptcache");
 
311
  $ok = 1;
 
312
}