diff options
-rw-r--r-- | SBO-Lib/lib/SBO/Lib.pm | 134 | ||||
-rwxr-xr-x | sboinstall | 2 | ||||
-rwxr-xr-x | sboupgrade | 78 |
3 files changed, 67 insertions, 147 deletions
diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm index 5f17928..5656d37 100644 --- a/SBO-Lib/lib/SBO/Lib.pm +++ b/SBO-Lib/lib/SBO/Lib.pm @@ -41,6 +41,7 @@ use Digest::MD5; use File::Copy; use File::Path qw(make_path remove_tree); use Fcntl; +use File::Find; $UID == 0 or print "This script requires root privileges.\n" and exit (1); @@ -182,132 +183,47 @@ sub clean_line { return $line; } -#sub get_available_updates { -# check_slackbuilds_txt(); -# my @updates; -# my @pkg_list = get_installed_sbos(); -# my $sb_txt = IO::File->new($slackbuilds_txt,"r"); -# FIRST: for my $c (keys @pkg_list) { -# my $name = $pkg_list[$c]{name}; -# my $version = $pkg_list[$c]{version}; -# my $regex = qr/$name_regex\Q$name\E\n\z/; -# my $found = "FALSE"; -# SECOND: while (my $line = <$sb_txt>) { -# if ($line =~ $regex) { -# $found = "TRUE"; -# next SECOND; -# } -# if ($found eq "TRUE") { -# if ($line =~ /VERSION/) { -# $found = "FALSE"; -# my @split = split(' ',$line); -# my $sbo_version = clean_line($split[2]); -# if (versioncmp($sbo_version,$version) == 1) { -# my %hash = ( -# name => $name, -# installed => $version, -# update => $sbo_version, -# ); -# push(@updates,\%hash); -# } -# $sb_txt->seek(0,0); -# next FIRST; -# } -# } -# } -# } -# $sb_txt->close; -# return @updates; -#} - -# much nicer version above does not work with perl 5.12, at last on Slackware -# 13.37 - the regex within the SECOND loop (while inside for) will never ever -# match, or at least I couldn't find a way to make it do so. switch which is -# inside which, and it works, so we use this method for now. -# -# iterate over all the lines! -# sub get_available_updates { check_slackbuilds_txt (); my (@updates,$index); my @pkg_list = get_installed_sbos (); - open my $sb_txt, '<', $slackbuilds_txt; - my $found = 'FALSE'; - FIRST: while (my $line = <$sb_txt>) { - if ($found eq 'TRUE') { - if ($line =~ /VERSION/) { - $found = 'FALSE'; - my $sbo_version = split_line ($line,' ',2); - if (versioncmp ($sbo_version,$pkg_list[$index]{version}) == 1) { + FIRST: for my $c (keys @pkg_list) { + my $location = get_sbo_location ($pkg_list[$c]{name}); + next FIRST unless defined $location; + my $regex = qr/^VERSION=/; + open my $info,'<',"$location/$pkg_list[$c]{name}.info"; + SECOND: while (my $line = <$info>) { + if ($line =~ $regex) { + my $sbo_version = split_equal_one ($line); + if (versioncmp ($sbo_version,$pkg_list[$c]{version}) == 1) { my %hash = ( - name => $pkg_list[$index]{name}, - installed => $pkg_list[$index]{version}, + name => $pkg_list[$c]{name}, + installed => $pkg_list[$c]{version}, update => $sbo_version, ); push (@updates,\%hash); } - } - } else { - SECOND: for my $c (keys @pkg_list) { - my $regex = qr/$name_regex\Q$pkg_list[$c]{name}\E\n\z/; - if ($line =~ $regex) { - $found = 'TRUE'; - $index = $c; - last SECOND; - } + last SECOND; } } + close ($info); } - close $sb_txt; return @updates; } -sub check_sbo_name_validity { - script_error ('check_sbo_name_validity requires an argument') - unless exists $_[0]; - my $sbo = shift; - check_slackbuilds_txt (); - my $valid = 'FALSE'; - my $regex = qr/$name_regex\Q$sbo\E\n\z/; - open my $sb_txt, '<', $slackbuilds_txt; - FIRST: while (my $line = <$sb_txt>) { - if ($line =~ $regex) { - $valid = 'TRUE'; - last FIRST; - } - } - close ($sb_txt); - unless ($valid eq 'TRUE') { - print "$sbo does not exist in the SlackBuilds tree. Exiting.\n"; - exit 1; - } - return 1; -} - sub get_sbo_location { script_error ('get_sbo_location requires an argument.Exiting.') unless exists $_[0]; my $sbo = shift; - check_slackbuilds_txt (); - my $found = 'FALSE'; my $location; - my $regex = qr/$name_regex\Q$sbo\E\n\z/; - open my $sb_txt, '<', $slackbuilds_txt; - FIRST: while (my $line = <$sb_txt>) { - if ($line =~ $regex) { - $found = 'TRUE'; - next FIRST; - } - if ($found eq 'TRUE') { - if ($line =~ /LOCATION/) { - my $loc_line = split_line ($line,' ',2); - $loc_line =~ s#^\./##; - $location = "$config{SBO_HOME}/$loc_line"; - last FIRST; - } - } - } - close ($sb_txt); + my $regex = qr#$config{SBO_HOME}/[^/]+/\Q$sbo\E\z#; + find ( + sub { + $location = $File::Find::dir if $File::Find::dir =~ $regex + }, + $config{SBO_HOME} + ); + return unless defined $location; return $location; } @@ -501,9 +417,8 @@ sub check_multilib { sub do_slackbuild { script_error ('do_slackbuild requires two arguments.') unless exists $_[1]; - my ($jobs,$sbo) = @_; + my ($jobs,$sbo,$location) = @_; my $sbo_home = $config{SBO_HOME}; - my $location = get_sbo_location ($sbo); my $arch = get_arch (); my $x32; if ($arch eq 'x86_64') { @@ -557,10 +472,9 @@ sub make_clean { sub make_distclean { script_error ('make_distclean requires two arguments.') unless exists $_[1]; - my ($sbo,$version) = @_; + my ($sbo,$version,$location) = @_; make_clean ($sbo,$version); print "Distcleaning for $sbo-$version...\n"; - my $location = get_sbo_location ($sbo); my @downloads = get_sbo_downloads ($sbo,$location); for my $dl (@downloads) { my $filename = get_filename_from_link ($dl); @@ -48,5 +48,5 @@ for (@ARGV) { $string .= " $_"; } -system ("/usr/sbin/sboupgrade -N $string"); +system ("/usr/sbin/sboupgrade -oN $string"); exit 0; @@ -41,7 +41,7 @@ EOF } my %options; -getopts ('hvacdfj:Nri',\%options); +getopts ('hvacdfj:Nrio',\%options); show_usage () && exit(0) if exists $options{h}; @@ -53,18 +53,25 @@ my $force = exists $options{f} ? 'TRUE' : 'FALSE'; my $jobs = 'FALSE'; 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 $no_install = exists $options{i} ? 'TRUE' : 'FALSE'; +my $only_new = exists $options{o} ? 'TRUE' : 'FALSE'; show_usage () and exit (1) unless exists $ARGV[0]; +my %locations; + for my $sbo_name (@ARGV) { - check_sbo_name_validity ($sbo_name); + $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 = get_sbo_location ($sbo); + my $location = $locations{$sbo}; return $location .'/README'; } @@ -89,7 +96,7 @@ sub process_sbos { readme_prompt ($sbo) unless $no_readme eq 'TRUE'; my $version; eval { - $version = do_slackbuild ($jobs,$sbo); + $version = do_slackbuild ($jobs,$sbo,$locations{$sbo}); }; if ($@) { push (@failures,$sbo); @@ -99,7 +106,7 @@ sub process_sbos { make_clean ($sbo,$version); } } else { - make_distclean ($sbo,$version); + make_distclean ($sbo,$version,$locations{$sbo}); } my $pkg; my $pkg_regex = qr/^(\Q$sbo\E-\Q$version\E-[^-]+-.*_SBo.t[xblg]z)$/; @@ -128,49 +135,48 @@ sub process_sbos { return @failures; } -# this can probably be redone to be faster overall. +my @installed = get_installed_sbos(); +my @failed; -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}); +sub print_failures { + if (exists $failed[0]) { + print "Failures:\n"; + print " $_\n" for (@failed); + exit (1); } } -my @installed = get_installed_sbos(); - -my @todo_upgrade; -unless ($force eq 'TRUE') { - for (@ARGV) { - if ($_ ~~ @updates) { - push (@todo_upgrade,$_); +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}); } } -} else { - for (@ARGV) { - SECOND: for my $c (keys @installed) { - if ($_ eq $installed[$c]{name}) { + + my @todo_upgrade; + unless ($force eq 'TRUE') { + for (@ARGV) { + if ($_ ~~ @updates) { push (@todo_upgrade,$_); - last SECOND; + } + } + } else { + for (@ARGV) { + SECOND: for my $c (keys @installed) { + if ($_ eq $installed[$c]{name}) { + push (@todo_upgrade,$_); + last SECOND; + } } } } -} -my @failed; -@failed = process_sbos (@todo_upgrade) if exists $todo_upgrade[0]; - -sub print_failures { - if (exists $failed[0]) { - print "Failures:\n"; - print " $_\n" for (@failed); - exit (1); - } + @failed = process_sbos (@todo_upgrade) if exists $todo_upgrade[0]; + print_failures () unless $install_new eq 'TRUE'; } -print_failures () unless $install_new eq 'TRUE'; - my @todo_install; my $has = 'FALSE'; for (@ARGV) { |