diff options
author | Jacob Pipkin <j@dawnrazor.net> | 2012-09-01 07:56:24 -0500 |
---|---|---|
committer | Jacob Pipkin <j@dawnrazor.net> | 2012-09-01 07:56:24 -0500 |
commit | b182d3c89554828478d8d24fd31a87ba629e75fc (patch) | |
tree | 36b141bf6605d155f1d3e0166f4ceb23fb2b8a8d | |
parent | 8b08c603ae79c145bc3b344f6dca4f0a95ed6201 (diff) | |
download | sbotools2-b182d3c89554828478d8d24fd31a87ba629e75fc.tar.xz |
more of the same...
-rw-r--r-- | SBO-Lib/lib/SBO/Lib.pm | 57 | ||||
-rwxr-xr-x | sboupgrade | 34 | ||||
-rwxr-xr-x | t/test.t | 6 |
3 files changed, 65 insertions, 32 deletions
diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm index 2325153..79a2946 100644 --- a/SBO-Lib/lib/SBO/Lib.pm +++ b/SBO-Lib/lib/SBO/Lib.pm @@ -416,9 +416,18 @@ sub check_multilib () { } # make a backup of the existent SlackBuild, and rewrite the original as needed -sub rewrite_slackbuild ($$%) { - exists $_[1] or script_error 'rewrite_slackbuild requires two arguments.'; - my ($slackbuild, $tempfn, %changes) = @_; +sub rewrite_slackbuild (%) { + my %args = ( + SLACKBUILD => '', + TEMPFN => '', + CHANGES => {}, + @_ + ); + unless ($args{SLACKBUILD} && $args{TEMPFN}) { + script_error 'rewrite_slackbuild requires SLACKBUILD and TEMPFN.'; + } + my $slackbuild = $args{SLACKBUILD}; + my $changes = $args{CHANGES}; copy ($slackbuild, "$slackbuild.orig") or die "Unable to backup $slackbuild to $slackbuild.orig\n"; my $tar_regex = qr/(un|)tar .*$/; @@ -432,17 +441,17 @@ sub rewrite_slackbuild ($$%) { # get the output of the tar and makepkg commands. hope like hell that v # is specified among tar's arguments if ($line =~ $tar_regex || $line =~ $makepkg_regex) { - $line = "$line | tee -a $tempfn"; + $line = "$line | tee -a $args{TEMPFN}"; } - # then check for and apply any other %changes - if (exists $changes{libdirsuffix}) { - $line =~ s/64/$changes{libdirsuffix}/ if $line =~ $libdir_regex; + # then check for and apply any other %$changes + if (exists $$changes{libdirsuffix}) { + $line =~ s/64/$$changes{libdirsuffix}/ if $line =~ $libdir_regex; } - if (exists $changes{make}) { - $line =~ s/make/make $changes{make}/ if $line =~ $make_regex; + if (exists $$changes{make}) { + $line =~ s/make/make $$changes{make}/ if $line =~ $make_regex; } - if (exists $changes{arch_out}) { - $line =~ s/\$ARCH/$changes{arch_out}/ if $line =~ $arch_regex; + if (exists $$changes{arch_out}) { + $line =~ s/\$ARCH/$$changes{arch_out}/ if $line =~ $arch_regex; } } untie @sb_file; @@ -562,7 +571,11 @@ sub perform_sbo (%) { $cmd = "$args{OPTS} $cmd" if $args{OPTS}; my $tempfh = tempfile (DIR => $tempdir); my $fn = get_tmp_extfn $tempfh; - rewrite_slackbuild "$location/$sbo.SlackBuild", $fn, %changes; + rewrite_slackbuild ( + SLACKBUILD => "$location/$sbo.SlackBuild", + TEMPFN => $fn, + CHANGES => \%changes, + ); chdir $location, my $out = system $cmd; revert_slackbuild "$location/$sbo.SlackBuild"; die "$sbo.SlackBuild returned non-zero ext status\n" unless $out == 0; @@ -636,13 +649,21 @@ sub do_slackbuild (%) { } # remove work directories (source and packaging dirs under /tmp/SBo) -sub make_clean ($$$) { - exists $_[2] or script_error 'make_clean requires three arguments.'; - my ($sbo, $src, $version) = @_; - say "Cleaning for $sbo-$version..."; +sub make_clean (%) { + my %args = ( + SBO => '', + SRC => '', + VERSION => '', + @_ + ); + unless ($args{SBO} && $args{SRC} && $args{VERSION}) { + script_error 'make_clean requires three arguments.'; + } + say "Cleaning for $args{SBO}-$args{VERSION}..."; my $tmpsbo = "/tmp/SBo"; - remove_tree ("$tmpsbo/$src") if -d "$tmpsbo/$src"; - remove_tree ("$tmpsbo/package-$sbo") if -d "$tmpsbo/package-$sbo"; + remove_tree ("$tmpsbo/$args{SRC}") if -d "$tmpsbo/$args{SRC}"; + remove_tree ("$tmpsbo/package-$args{SBO}") if + -d "$tmpsbo/package-$args{SBO}"; return 1; } @@ -113,25 +113,32 @@ sub get_requires ($$) { } # ask to install any requirements found -sub ask_requires ($$$) { - exists $_[2] or script_error 'ask_requires requires three arguments.'; - my ($requires, $readme, $sbo) = shift; - FIRST: for my $req (@$requires) { +sub ask_requires (%) { + my %args = ( + REQUIRES => '', + README => '', + SBO => '', + @_ + ); + unless ($args{REQUIRES} && $args{README} && $args{SBO}) { + script_error 'ask_requires requires three arguments.'; + } + FIRST: for my $req (@{$args{REQUIRES}}) { my $name = $compat32 ? "$req-compat32" : $req; my $inst = get_installed_sbos; my $inst_names = get_inst_names $inst; next FIRST if $name ~~ @$inst_names; - say $readme; - say "$sbo has $name listed as a requirement."; + say $args{README}; + say "$args{SBO} has $name listed as a requirement."; print "Shall I attempt to install it first? [y] "; if (<STDIN> =~ /^[Yy\n]/) { - my @args = ('/usr/sbin/sboupgrade', '-oN'); + my @cmd_args = ('/usr/sbin/sboupgrade', '-oN'); # populate args so that they carry over correctly for my $arg (qw(c d p)) { - push @args, "-$arg" if exists $options{$arg}; + push @cmd_args, "-$arg" if exists $options{$arg}; } - push @args, "-j $options{j}" if exists $options{j}; - system (@args, $req) == 0 or die "$name failed to install.\n"; + push @cmd_args, "-j $options{j}" if exists $options{j}; + system (@cmd_args, $req) == 0 or die "$name failed to install.\n"; } } return; @@ -321,7 +328,12 @@ FIRST: for my $sbo (@ARGV) { print " yet installed. Shall I install it first? [y] "; if (<STDIN> =~ /^[Yy\n]/) { my @args = ('/usr/sbin/sboupgrade', '-oN', $sbo); - system (@args) == 0 or exit 1; + # populate args so that they carry over correctly + for my $arg (qw(c d)) { + push @args, "-$arg" if exists $options{$arg}; + } + push @args, "-j $options{j}" if exists $options{j}; + system (@args) == 0 or die "$sbo failed to install.\n"; } else { warn "Please install $sbo\n" and exit 0; } @@ -162,8 +162,8 @@ copy ("$sbo_home/system/ifuse/ifuse.SlackBuild", $rewrite_dir); my $slackbuild = "$rewrite_dir/ifuse.SlackBuild"; $tempfh = tempfile (DIR => $rewrite_dir); my $tempfn = get_tmp_extfn $tempfh; -my %changes; -is (rewrite_slackbuild ($slackbuild, $tempfn, %changes), 1, 'rewrite_slackbuild with no %changes good'); +my %changes = (); +is (rewrite_slackbuild (SLACKBUILD => $slackbuild, TEMPFN => $tempfn, CHANGES => \%changes), 1, 'rewrite_slackbuild with no %changes good'); ok (-f "$slackbuild.orig", 'rewrite_slackbuild backing up original is good.'); my $expected_out = "67c67 < tar xvf \$CWD/\$PRGNAM-\$VERSION.tar.bz2 @@ -179,7 +179,7 @@ is (revert_slackbuild $slackbuild, 1, 'revert_slackbuild is good'); $changes{libdirsuffix} = ''; $changes{make} = '-j 5'; $changes{arch_out} = 'i486'; -is (rewrite_slackbuild ($slackbuild, $tempfn, %changes), 1, 'rewrite_slackbuild with all %changes good'); +is (rewrite_slackbuild (SLACKBUILD => $slackbuild, TEMPFN => $tempfn, CHANGES => \%changes), 1, 'rewrite_slackbuild with all %changes good'); ok (-f "$slackbuild.orig", 'rewrite_slackbuild backing up original is good.'); $expected_out = "55c55 < LIBDIRSUFFIX=\"64\" |