forked from pink-mist/sbotools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sboupgrade
executable file
·286 lines (254 loc) · 7.92 KB
/
sboupgrade
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/usr/bin/perl
#
# vim: ts=4:noet
#
# sboupgrade
# script to upgrade (a) SlackBuild(s) by name
#
# authors: Jacob Pipkin <[email protected]>
# Luke Williams <[email protected]>
# Andreas Guldstrand <[email protected]>
# maintainer: K. Eugene Carlson <[email protected]>
# license: MIT License
use 5.16.0;
use strict;
use warnings FATAL => 'all';
use SBO::Lib qw/ get_available_updates prompt usage_error slackbuilds_or_fetch uniq get_sbo_location get_inst_names get_installed_packages get_build_queue get_sbo_locations in merge_queues user_prompt process_sbos print_failures verify_gpg %config show_version lint_sbo_config wrapsay /;
use Getopt::Long qw(:config bundling);
use File::Basename;
use File::Copy;
my $self = basename($0);
sub show_usage {
print <<"EOF";
Usage: $self (options) [package]
Options (defaults shown first where applicable):
-h|--help:
this screen.
-v|--version:
version information.
--all
this flag will upgrade everything reported by sbocheck(1).
-b|--build-ignore (FALSE|TRUE):
if TRUE, only offer to upgrade on version changes (not build number changes).
-c|--noclean (FALSE|TRUE):
if TRUE, do not clean working directories after building.
-d|--distclean (TRUE|FALSE):
if TRUE, delete downloaded source archives after building.
-f|--force:
force an upgrade, even if the version and build number are the same.
-i|--noinstall:
do not run upgradepkg at the end of the build process.
-j|--jobs (FALSE|#):
specify the number of parallel jobs (make).
-p|--compat32:
install a -compat32 package (multilib systems only).
-r|--nointeractive:
non-interactive; skips README and all prompts.
-S|--strict-upgrades (FALSE|TRUE):
if TRUE, SBo upgrades only when the version or build number is higher.
-z|--force-reqs:
rebuild dependencies as well.
EOF
return 1;
}
my $noclean = $config{NOCLEAN};
my $distclean = $config{DISTCLEAN};
my $jobs = $config{JOBS};
my $build_ignore = $config{BUILD_IGNORE};
my $gpg = $config{GPG_VERIFY};
my $strict_upgrades = $config{STRICT_UPGRADES};
my ($help, $vers, $force, $no_install, $non_int, $force_reqs, $all);
GetOptions(
'help|h' => \$help,
'version|v' => \$vers,
'noclean|c=s' => \$noclean,
'distclean|d=s' => \$distclean,
'force|f' => \$force,
'noinstall|i' => \$no_install,
'jobs|j=s' => \$jobs,
'nointeractive|r' => \$non_int,
'force-reqs|z' => \$force_reqs,
'build-ignore|b=s' => \$build_ignore,
'all' => \$all,
'strict-upgrades|S=s' => \$strict_upgrades,
);
if ($help) { show_usage(); exit 0 }
if ($vers) { show_version(); exit 0 }
lint_sbo_config($self, %config);
# invalid parameters may have been passed from the command line
if ($noclean) {
usage_error("You have provided an invalid value for -c|--noclean")
unless ($noclean =~ /^(TRUE|FALSE)$/);
}
if ($distclean) {
usage_error("You have provided an invalid value for -d|--distclean")
unless ($distclean =~ /^(TRUE|FALSE)$/);
}
if ($build_ignore) {
usage_error("You have provided an invalid value for -b|--build-ignore")
unless ($build_ignore =~ /^(TRUE|FALSE)$/);
}
if ($strict_upgrades) {
usage_error("You have provided an invalid value for -S|--strict-upgrades")
unless ($strict_upgrades =~ /^(TRUE|FALSE)$/);
}
if ($jobs) {
usage_error("You have provided an invalid value for -j|--jobs")
unless ($jobs =~ /^\d+$/ || $jobs eq 'FALSE');
}
$noclean = $noclean eq 'TRUE' ? 1 : 0;
$distclean = $distclean eq 'TRUE' ? 1 : 0;
$build_ignore = $build_ignore eq 'TRUE' ? 1 : 0;
$gpg = $gpg eq 'TRUE' ? 1 : 0;
# from here, only Pkgs.pm uses STRICT_UPGRADES
$config{STRICT_UPGRADES} = $strict_upgrades if $strict_upgrades;
if ($gpg) { verify_gpg(); }
my $updates;
if ($all) {
slackbuilds_or_fetch();
print "Checking for updated SlackBuilds...\n";
if ($build_ignore) {
$updates = get_available_updates('VERS');
} else {
$updates = get_available_updates('BOTH');
}
push @ARGV, map { $_->{name} } @$updates;
if (!@ARGV) { print "Nothing to update.\n"; exit 0 }
}
if (!@ARGV) { show_usage(); exit 1 }
usage_error("-r|--nointeractive and -z|--force-reqs can not be used together.")
if $non_int && $force_reqs;
# if we can't find SLACKBUILDS.TXT in $config{SBO_HOME}, prompt to fetch the tree
slackbuilds_or_fetch();
my @sbos = uniq @ARGV;
# Filter out standard packages
my $std_installs = get_inst_names(get_installed_packages('STD'));
my %std_names;
$std_names{$_} = 1 for @$std_installs;
@sbos = grep { not $std_names{$_} } @sbos;
# pull locations for everything specified on command line.
my %locations;
for my $sbo (@sbos) {
my $name = $sbo;
$name =~ s/-compat32//;
$locations{$sbo} = get_sbo_location($name);
if (not $locations{$sbo} and in(@ARGV, $sbo)) {
usage_error("Unable to locate $sbo in the SlackBuilds.org tree.");
}
if ($sbo =~ /-compat32$/) {
usage_error("compat32 Perl SBos are not supported.")
if $locations{$sbo} =~ qr|/perl/[^/]+$|;
}
}
# get a list of installed SBos to check upgradability against
my $inst_names = get_inst_names(get_installed_packages('SBO'));
my %inst_names;
$inst_names{$_} = 1 for @$inst_names;
my %updates;
if (not $non_int or not $force) {
if ($build_ignore) {
$updates = get_available_updates('VERS') if not defined $updates;
} else {
$updates = get_available_updates('BOTH') if not defined $updates;
}
$updates{$$_{name}} = 1 for @$updates;
}
my $upgrade_queue = [];
my %warnings;
# doesn't matter what's updatable and what's not if force is specified,
# but without force, we only want to update what there are updates for
if ($non_int) {
if ($force) {
for my $sbo (@sbos) {
push @$upgrade_queue, $sbo if $inst_names{$sbo};
}
} else {
for my $sbo (@sbos) {
push @$upgrade_queue, $sbo if $updates{$sbo};
}
}
} else {
for my $sbo (@sbos) {
my $name = $sbo;
$name =~ s/-compat32$//;
next if not $name;
unless ($force_reqs or $force) {
next unless $updates{$name};
}
my $queue = get_build_queue([$name], \%warnings);
if (not $force_reqs) {
@$queue = grep { !$inst_names{$_} or $updates{$_} } @$queue;
}
push @$queue, $name if $force;
my $cqueue;
# get locations for all the things
my %locs = get_sbo_locations($queue);
my %clocs;
# -compat32-ify the queue and locations if appropriate
if ($sbo =~ /-compat32$/) {
$cqueue = $queue;
s/$/-compat32/g for @$cqueue;
$queue = $cqueue;
for my $key (keys %locs) {
my $val = $locs{$key};
$key =~ s/$/-compat32/;
$clocs{$key} = $val;
}
%locs = %clocs;
}
@locations{keys %locs} = values %locs;
$upgrade_queue = merge_queues($upgrade_queue, $queue);
}
}
# Get user input regarding upgrades
my (@temp_queue, %commands, %options);
FIRST: for my $sbo (@$upgrade_queue) {
next FIRST if $std_names{$sbo};
if (defined $warnings{$sbo} and $warnings{$sbo} eq 'nonexistent') {
wrapsay "Unable to locate $sbo in the SlackBuilds.org tree.";
if (not $non_int) {
exit 0 unless prompt("Do you want to ignore it and continue?", default => 'yes');
}
next FIRST;
}
unless ($non_int) {
my ($cmds, $opts, $exit) = user_prompt($sbo, $locations{$sbo});
if ($exit) {
warn "Unable to open README for $sbo.\n";
exit $exit;
}
if ($cmds) {
next FIRST if $cmds eq 'N';
}
push(@temp_queue, $sbo);
$commands{$sbo} = $cmds;
$options{$sbo} = $opts;
say "$sbo added to upgrade queue.";
} else {
push(@temp_queue, $sbo);
say "\n$sbo added to upgrade queue.";
}
}
@$upgrade_queue = @temp_queue;
exit 0 unless exists $$upgrade_queue[0];
wrapsay "\nUpgrade queue: ". join(' ', @$upgrade_queue);
unless ($non_int) {
exit 0 unless prompt("\nAre you sure you wish to continue?", default => 'yes');
}
my ($failures, $exit) = process_sbos(
TODO => $upgrade_queue,
CMDS => \%commands,
OPTS => \%options,
JOBS => $jobs,
LOCATIONS => \%locations,
NOINSTALL => $no_install,
NOCLEAN => $noclean,
DISTCLEAN => $distclean,
NON_INT => $non_int,
);
print_failures($failures);
if ($exit) {
exit $exit;
} else {
exit 0;
}