forked from sonick13/PerlProjects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapt-download-deps
106 lines (84 loc) · 2.59 KB
/
apt-download-deps
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
#!/usr/bin/env perl
#cito M:755 O:0 G:0 T:/usr/bin/apt-download-deps
#------------------------------------------------------------------------------
# Project Name - PerlProjects/source/apt-download-deps
# Started On - Sat 4 Jan 21:55:31 GMT 2020
# Last Change - Thu 26 Nov 04:58:18 GMT 2020
# Author E-Mail - [email protected]
# Author GitHub - https://github.com/terminalforlife
#------------------------------------------------------------------------------
# Dependencies:
#
# libapt-pkg-perl (>= 0.1.29build7)
# perl (>= 5.22.1-9)
#----------------------------------------------------------------------------------
use strict;
use warnings;
use autodie;
use AptPkg::Cache;
my $CurVer = '2020-11-26';
my $Progrm = 'apt-download-deps';
sub Usage {
print(qq{Usage: $Progrm [OPTS] [PKG_1 [PKG_2] ...]
-h, --help - Display this help information.
-v, --version - Output the version datestamp.
--include-base|-b - Also download base package(s).
This program, written in Perl, is ideal for situations in
which the user wishes to transfer to or store packages on
another machine for later offline use.
} =~ tr/\t//dr)
}
my $BaseToo = 'false';
while (defined($ARGV[0])) {
if ($ARGV[0] =~ '^(--help|-h|-\?)$') {
Usage(1); exit(0)
} elsif ($ARGV[0] =~ '^(--version|-v)$') {
print("$CurVer\n"); exit(0)
} elsif ($ARGV[0] =~ '^(--include-base|-b)$') {
$BaseToo = 'true'
} elsif ($ARGV[0] =~ '^-') {
die("Incorrect argument(s) specified")
} else {
last
}
shift()
}
scalar(@ARGV) == 0 and die('At least one package is required');
my $Cache = AptPkg::Cache->new();
my $MissingPKG = '';
sub FetchDeps{
my $Get = $Cache->get($_[0]);
my $Vers = $Get->{'VersionList'};
unless (defined($Vers)){
warn("Package '$_[0]' not found");
$MissingPKG = 'true';
return(0)
}
my $Deps = $Vers->[0]->{'DependsList'};
my @Packages;
my $Iter = 0;
while ($Iter < scalar(@{$Deps})){
my $Dep = $Deps->[$Iter++];
next unless $Dep->{'DepType'} eq 'Depends';
push(@Packages, $Dep->{'TargetPkg'}->{'Name'})
}
return(@Packages)
}
my @Executables;
foreach my $Dir (split(':', $ENV{'PATH'})) {
-d $Dir or next;
opendir(my $DH, $Dir) or next;
push(@Executables, readdir($DH));
closedir($DH);
}
grep({$_ eq 'apt-get'} @Executables) or die("Dependency 'apt-get' not met");
my @ToDL;
while (scalar(@ARGV) > 0){
push(@ToDL, FetchDeps($ARGV[0]));
if ($BaseToo eq 'true'){
system("apt-get download $ARGV[0] @ToDL") unless $MissingPKG eq 'true';
}else{
system("apt-get download @ToDL") unless $MissingPKG eq 'true';
}
shift()
}