diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm index 8d22ecd..862886c 100644 --- a/SBO-Lib/lib/SBO/Lib.pm +++ b/SBO-Lib/lib/SBO/Lib.pm @@ -38,7 +38,9 @@ our @EXPORT = qw( do_upgradepkg get_sbo_location get_sbo_locations + get_slack_version get_from_info + get_info_from_slackbuilds_txt get_tmp_extfn get_arch get_build_queue @@ -50,6 +52,7 @@ our @EXPORT = qw( get_opts ask_opts user_prompt + get_slackbuild process_sbos print_failures usage_error @@ -234,17 +237,29 @@ sub rsync_sbo_tree { say 'Finished.' and return $out; } +# Use wget to retreive Slackbuilds list. +sub wget_slackbuilds_txt { + my $slk_version = get_slack_version(); + chdir $config{SBO_HOME}; + my @arg = ('wget', '--no-check-certificate', "https://slackbuilds.org/slackbuilds/$slk_version/SLACKBUILDS.TXT.gz"); + my $out = system @arg; + @arg = ('gunzip', '-f', 'SLACKBUILDS.TXT.gz'); + $out = system @arg; +} + # wrappers for differing checks and output sub fetch_tree { check_home(); say 'Pulling SlackBuilds tree...'; - rsync_sbo_tree(), return 1; + # rsync_sbo_tree(), return 1; + wget_slackbuilds_txt(), return 1; } sub update_tree { fetch_tree(), return() unless chk_slackbuilds_txt(); say 'Updating SlackBuilds tree...'; - rsync_sbo_tree(), return 1; + # rsync_sbo_tree(), return 1; + wget_slackbuilds_txt(), return 1; } # if the SLACKBUILDS.TXT is not in $config{SBO_HOME}, we assume the tree has @@ -384,10 +399,62 @@ sub get_from_info { return $store->{$args{GET}}; } +# pull piece(s) of data, GET, from the SLACKBUILDS.TXT file. +sub get_info_from_slackbuilds_txt { + my %args = ( + NAME => '', + GET => '', + @_ + ); + unless ($args{NAME} && $args{GET}) { + script_error('get_info_from_slackbuilds_txt requires NAME and GET.'); + } + my $search = $args{NAME}; + my ($name, $found); + my $store = {}; + my $name_regex = qr/NAME:\s+(\Q$search\E)$/i; + my $loc_regex = qr/LOCATION:\s+(.*)$/; + my $version_regex = qr/VERSION:\s+(.*)$/; + my $requires_regex = qr/REQUIRES:\s+(.*)$/; + my $shortdesc_regex = qr/SHORT DESCRIPTION:\s+(.*)$/; + my ($fh, $exit) = open_read "$config{SBO_HOME}/SLACKBUILDS.TXT"; + if ($exit) { + warn $fh; + exit $exit; + } + FIRST: while (my $line = <$fh>) { + unless ($found) { + $found++, next FIRST if $name = ($line =~ $name_regex)[0]; + } else { + if (my ($location) = ($line =~ $loc_regex)[0]) { + $location =~ s#^\.##; + push @{ $store->{LOCATION} }, $location; + $found++, next FIRST; + } + if (my ($version) = ($line =~ $version_regex)[0]) { + push @{ $store->{VERSION} }, $version; + $found++, next FIRST; + } + if (my ($requires) = ($line =~ $requires_regex)[0]) { + push @{ $store->{REQUIRES} }, ($requires ? split(' ', $requires) : $requires); + $found++, next FIRST; + } + if (my ($shortdesc) = ($line =~ $shortdesc_regex)[0]) { + $found = 0; + push @{ $store->{SHORTDESC} }, $shortdesc; + } + } + } + + return $store->{$args{GET}}; +} + # find the version in the tree for a given sbo (provided a location) sub get_sbo_version { exists $_[0] or script_error('get_sbo_version requires an argument.'); - my $version = get_from_info(LOCATION => shift, GET => 'VERSION'); + #my $version = get_from_info(LOCATION => shift, GET => 'VERSION'); + my $sbo = get_sbo_from_loc(shift); + my $version = get_info_from_slackbuilds_txt(NAME => $sbo, GET => 'VERSION'); return $$version[0] ? $$version[0] : undef; } @@ -942,7 +1009,9 @@ sub do_upgradepkg { sub get_requires { my $location = get_sbo_location(shift); return() unless $location; - my $info = get_from_info(LOCATION => $location, GET => 'REQUIRES'); + #my $info = get_from_info(LOCATION => $location, GET => 'REQUIRES'); + my $sbo = get_sbo_from_loc($location); + my $info = get_info_from_slackbuilds_txt(NAME => $sbo, GET => 'REQUIRES'); return $$info[0] ne '' ? $info : undef; } @@ -959,6 +1028,7 @@ sub _build_queue { while (my $sbo = shift @queue) { next if $sbo eq "%README%"; my $reqs = get_requires($sbo); + if (defined $reqs) { push @result, _build_queue($reqs, $warnings); foreach my $req (@$reqs) { @@ -1077,8 +1147,11 @@ sub ask_opts { sub user_prompt { exists $_[1] or script_error('user_prompt requires two arguments.'); my ($sbo, $location) = @_; - my ($readme, $exit) = get_readme_contents($location); - return $readme, undef, $exit if $exit; + # my ($readme, $exit) = get_readme_contents($location); + # return $readme, undef, $exit if $exit; + my $info = get_info_from_slackbuilds_txt(NAME => $sbo, GET => "SHORTDESC"); + my $data = $$info[0] ne '' ? $info : undef; + my $readme = $$data[0]; # check for user/group add commands, offer to run any found my $user_group = get_user_group($readme); my $cmds; @@ -1095,6 +1168,30 @@ sub user_prompt { return $cmds, $opts; } +# Download the Slackbuild archives and extract it to SBO_HOME. +sub get_slackbuild { + my $build_queue = $_[0]; + my $info = {}; + my $data = {}; + my $location = ""; + my @arr = (); + for my $sbo (@$build_queue) { + $info = get_info_from_slackbuilds_txt(NAME => $sbo, GET => "LOCATION"); + $data = $$info[0] ne '' ? $info : undef; + $location = $$data[0]; + @arr = split('/',$location); + chdir $config{SBO_HOME}; + mkdir $arr[1] unless -d $arr[1]; + chdir $arr[1]; + my $slk_version = get_slack_version(); + my @arg = ('wget', '--no-check-certificate', "https://slackbuilds.org/slackbuilds/$slk_version/".$arr[1]."/".$sbo.".tar.gz"); + system @arg; + @arg = ('tar', '-xf', $sbo.".tar.gz"); + system @arg; + unlink $sbo.".tar.gz"; + } +} + # do the things with the provided sbos - whether upgrades or new installs. sub process_sbos { my %args = ( diff --git a/sbocheck b/sbocheck index cb56266..b329fb9 100755 --- a/sbocheck +++ b/sbocheck @@ -27,18 +27,20 @@ Options: this screen. -v|--version: version information. + -o|--offline: + offline check for updates (use current SLACKBUILDS.TXT). EOF } -my ($help, $vers); +my ($help, $vers, $offline); -GetOptions('help|h' => \$help, 'version|v' => \$vers); +GetOptions('help|h' => \$help, 'version|v' => \$vers, 'offline|o' => \$offline); show_usage() and exit 0 if $help; show_version() and exit 0 if $vers; -update_tree(); +update_tree() if !$offline; # retrieve and format list of available updates sub get_update_list { diff --git a/sbofind b/sbofind index c37c464..48ccbdb 100755 --- a/sbofind +++ b/sbofind @@ -28,10 +28,8 @@ Options: this screen. -v|--verison: version information. - -i|--info: - show the .info for each found item. - -r|--readme: - show the README for each found item. + -d|--desc: + show package description. -q|--queue: show the build queue for each found item. @@ -41,13 +39,12 @@ Example: EOF } -my ($help, $vers, $show_info, $show_readme, $show_queue); +my ($help, $vers, $show_desc, $show_queue); GetOptions( 'help|h' => \$help, 'version|v' => \$vers, - 'info|i' => \$show_info, - 'readme|r' => \$show_readme, + 'desc|d' => \$show_desc, 'queue|q' => \$show_queue, ); @@ -117,11 +114,12 @@ if (exists $$findings[0]) { for my $hash (@$findings) { for my $key (keys %$hash) { my $val = $hash->{$key}; - say "SBo: $key"; - say "Path: $val"; - say "info: ". get_file_contents("$val/$key.info") if $show_info; - say "README: ". get_file_contents("$val/README") if $show_readme; - say "Queue: ". show_build_queue("$key") if $show_queue; + my $info = get_info_from_slackbuilds_txt(NAME => $key, GET => 'SHORTDESC'); + my $data = $$info[0] ne '' ? $info : undef; + say "SBo: $key"; + say "Path: $val"; + say "Description: ". $$data[0] if $show_desc; + say "Queue: ". show_build_queue("$key") if $show_queue; say ''; } } diff --git a/sboinstall b/sboinstall index dcf5a6f..a6999fd 100755 --- a/sboinstall +++ b/sboinstall @@ -179,6 +179,8 @@ unless ($non_int) { exit 0 unless =~ /^[Yy\n]/; } +get_slackbuild($build_queue); + my ($failures, $exit) = process_sbos( TODO => $build_queue, CMDS => \%commands, diff --git a/sboupgrade b/sboupgrade index 8735b1c..c2f7de4 100755 --- a/sboupgrade +++ b/sboupgrade @@ -218,6 +218,8 @@ unless ($non_int) { exit 0 unless =~ /^[Yy\n]/; } +get_slackbuild($upgrade_queue); + my ($failures, $exit) = process_sbos( TODO => $upgrade_queue, CMDS => \%commands,