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
|
#!/usr/bin/env perl
#
# sboupgrade
# script to update an installed SlackBuild.
#
# author: Jacob Pipkin <j@dawnrazor.net>
# date: Boomtime, the 39th day of Discord in the YOLD 3178
# license: WTFPL <http://sam.zoy.org/wtfpl/COPYING>
use SBO::Lib;
use File::Basename;
use Getopt::Std;
use Text::Tabulate;
use File::Copy;
use strict;
use warnings FATAL => 'all';
my %config = %SBO::Lib::config;
my $self = basename ($0);
sub show_usage {
print <<EOF
Usage: $self (options) [package]
Options:
-h: this screen.
-v: version information.
-c: do not clean working files/directories after the build.
-d: clean distfiles afterward.
-f: force an update, even if the "upgrade" version is the same or lower.
-i: do not run installpkg at the end of the build process.
-j: specify "-j" setting to make, for SMP systems; overrides conf file.
-N: install any new SBo's listed.
-r: skip viewing of the SBo README.
Example:
$self -d libsexy
$self -ca
EOF
}
my %options;
getopts ('hvacdfj:Nriop',\%options);
show_usage () && exit (0) if exists $options{h};
show_version () && exit (0) if exists $options{v};
my $noclean = exists $options{c} ? 'FALSE' : $config{NOCLEAN};
my $distclean = exists $options{d} ? 'TRUE' : $config{DISTCLEAN};
my $force = exists $options{f} ? 'TRUE' : 'FALSE';
my $jobs = exists $options{j} ? $options{j} : $config{JOBS};
my $install_new = exists $options{N} ? 'TRUE' : 'FALSE';
my $no_readme = exists $options{r} ? 'TRUE' : 'FALSE';
my $no_install = exists $options{i} ? 'TRUE' : 'FALSE';
my $only_new = exists $options{o} ? 'TRUE' : 'FALSE';
my $compat32 = exists $options{p} ? 'TRUE' : 'FALSE';
show_usage () and exit (1) unless exists $ARGV[0];
slackbuilds_or_fetch ();
my %locations;
for my $sbo_name (@ARGV) {
$locations{$sbo_name} = get_sbo_location ($sbo_name);
unless (defined $locations{$sbo_name}) {
print "Unable to locate $sbo_name in the SlackBuilds.org tree.\n";
exit 1;
}
}
sub get_readme_path {
script_error ('get_readme_path requires an argument.') unless exists $_[0];
my $sbo = shift;
my $location = $locations{$sbo};
return $location .'/README';
}
sub readme_prompt {
script_error ('readme_prompt requires an argument.') unless exists $_[0];
my $sbo = shift;
my $readme_path = get_readme_path ($sbo);
open my $readme,'<',$readme_path;
print "\n",<$readme>;
close ($readme);
print "\nProceed with $sbo? [yn]: ";
my $test = <STDIN>;
exit (0) unless $test =~ /^[Yy]/;
return 1;
}
sub process_sbos {
script_error ('process_sbos requires an argument.') unless exists $_[0];
my (@todo) = @_;
my @failures;
for my $sbo (@todo) {
readme_prompt ($sbo) unless $no_readme eq 'TRUE';
$compat32 = 'TRUE' if $sbo =~ /-compat32$/;
my $version;
eval {
$version = do_slackbuild ($jobs,$sbo,$locations{$sbo},$compat32);
};
if ($@) {
push (@failures,$sbo);
} else {
unless ($distclean eq 'TRUE') {
if ($noclean eq 'FALSE') {
make_clean ($sbo,$version);
}
} else {
make_distclean ($sbo,$version,$locations{$sbo});
}
my $pkg = get_pkg_name ($sbo,$version,$compat32);
do_upgradepkg ($pkg) unless $no_install eq 'TRUE';
unless ($config{PKG_DIR} eq 'FALSE') {
unless (-d $config{PKG_DIR}) {
mkdir ($config{PKG_DIR}) or
warn "Unable to create $config{PKG_DIR}\n";
}
if (-d $config{PKG_DIR}) {
move ($pkg,$config{PKG_DIR});
print "$pkg stored in $config{PKG_DIR}\n";
} else {
warn "$pkg left in /tmp\n";
}
} elsif ($distclean eq 'TRUE') {
unlink ($pkg);
}
}
}
return @failures;
}
my @installed = get_installed_sbos();
my @failed;
sub print_failures {
if (exists $failed[0]) {
print "Failures:\n";
print " $_\n" for (@failed);
exit 1;
}
}
unless ($only_new eq 'TRUE') {
my @updates unless $force eq 'TRUE';
unless ($force eq 'TRUE') {
my @updates_array = get_available_updates ();
for my $index (keys @updates_array) {
push(@updates,$updates_array[$index]{name});
}
}
my @todo_upgrade;
unless ($force eq 'TRUE') {
for (@ARGV) {
if ($_ ~~ @updates) {
push (@todo_upgrade,$_);
}
}
} else {
for (@ARGV) {
SECOND: for my $c (keys @installed) {
if ($_ eq $installed[$c]{name}) {
push (@todo_upgrade,$_);
last SECOND;
}
}
}
}
@failed = process_sbos (@todo_upgrade) if exists $todo_upgrade[0];
print_failures () unless $install_new eq 'TRUE';
}
if ($install_new eq 'TRUE') {
my @todo_install;
my $has = 'FALSE';
for my $sbo (@ARGV) {
my $name = $compat32 eq 'TRUE' ? "$sbo-compat32" : $sbo;
SECOND: for my $index (keys @installed) {
if ($name eq $installed[$index]{name}) {
$has = 'TRUE';
last SECOND;
}
}
unless ($has eq 'TRUE') {
push (@todo_install,$sbo);
} else {
print "$name already installed.\n";
}
$has = 'FALSE';
}
@failed = process_sbos (@todo_install) if exists $todo_install[0];
print_failures ();
}
exit 0;
|