diff options
| -rw-r--r-- | SBO-Lib/lib/SBO/App/Remove.pm | 7 | ||||
| -rw-r--r-- | SBO-Lib/lib/SBO/App/Snap.pm | 7 | ||||
| -rw-r--r-- | SBO-Lib/lib/SBO/Lib.pm | 5 | ||||
| -rw-r--r-- | SBO-Lib/lib/SBO/Lib/Build.pm | 10 | ||||
| -rw-r--r-- | SBO-Lib/lib/SBO/Lib/Repo.pm | 4 | ||||
| -rwxr-xr-x | sbocheck | 7 | ||||
| -rwxr-xr-x | sboclean | 7 | ||||
| -rwxr-xr-x | sboconfig | 7 | ||||
| -rwxr-xr-x | sboinstall | 7 | ||||
| -rwxr-xr-x | sboupgrade | 7 | ||||
| -rwxr-xr-x | t/07-fail.t | 2 | ||||
| -rwxr-xr-x | t/16-clean.t | 2 | 
12 files changed, 49 insertions, 23 deletions
diff --git a/SBO-Lib/lib/SBO/App/Remove.pm b/SBO-Lib/lib/SBO/App/Remove.pm index 4c7dd31..b97cdf8 100644 --- a/SBO-Lib/lib/SBO/App/Remove.pm +++ b/SBO-Lib/lib/SBO/App/Remove.pm @@ -10,7 +10,7 @@ package SBO::App::Remove;  use 5.16.0;  use strict;  use warnings FATAL => 'all'; -use SBO::Lib qw/ get_inst_names get_installed_packages get_sbo_location get_build_queue merge_queues get_requires get_readme_contents prompt show_version in /; +use SBO::Lib qw/ _ERR_USAGE get_inst_names get_installed_packages get_sbo_location get_build_queue merge_queues get_requires get_readme_contents prompt show_version in /;  use Getopt::Long qw(GetOptionsFromArray :config bundling);  use parent 'SBO::App'; @@ -41,6 +41,11 @@ sub run {    if ($self->{vers}) { $self->show_version(); return 0; }    if (!@{ $self->{args} }) { $self->show_usage(); return 1; } +  unless ($< == 0) { +  	warn "This script requires root privileges.\n"; +  	exit _ERR_USAGE; +  } +    # current workflow:    # * get names of all installed SBo packages    # * compare commandline args to SBo packages as well as installed SBo packages diff --git a/SBO-Lib/lib/SBO/App/Snap.pm b/SBO-Lib/lib/SBO/App/Snap.pm index d2b0f57..f9e44a6 100644 --- a/SBO-Lib/lib/SBO/App/Snap.pm +++ b/SBO-Lib/lib/SBO/App/Snap.pm @@ -13,7 +13,7 @@ package SBO::App::Snap;  use 5.16.0;  use strict;  use warnings FATAL => 'all'; -use SBO::Lib qw/ fetch_tree import_gpg_key update_tree %config show_version /; +use SBO::Lib qw/ _ERR_USAGE fetch_tree import_gpg_key update_tree %config show_version /;  use Getopt::Long qw/ GetOptionsFromArray /;  use parent 'SBO::App'; @@ -64,6 +64,11 @@ sub run {    if ($self->{help}) { $self->show_usage(); return 0 }    if ($self->{vers}) { $self->show_version(); return 0 } +  unless ($< == 0) { +  	warn "This script requires root privileges.\n"; +  	exit _ERR_USAGE; +  } +    # check for a command and, if found, execute it    $args[0] //= ''; diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm index edb418a..fe96cde 100644 --- a/SBO-Lib/lib/SBO/Lib.pm +++ b/SBO-Lib/lib/SBO/Lib.pm @@ -94,11 +94,6 @@ our %EXPORT_TAGS = (  	config => $SBO::Lib::Util::EXPORT_TAGS{config},  ); -unless ($< == 0) { -	warn "This script requires root privileges.\n"; -	exit _ERR_USAGE; -} -  'ok';  __END__ diff --git a/SBO-Lib/lib/SBO/Lib/Build.pm b/SBO-Lib/lib/SBO/Lib/Build.pm index e6aa66b..ad760b7 100644 --- a/SBO-Lib/lib/SBO/Lib/Build.pm +++ b/SBO-Lib/lib/SBO/Lib/Build.pm @@ -37,7 +37,6 @@ our @EXPORT_OK = qw{    rewrite_slackbuild    run_tee -  $tempdir    $tmpd    $env_tmp  }; @@ -71,11 +70,6 @@ set.  Will be the same as C<$TMP> if it is set, otherwise it will be C</tmp/SBo>. -=head2 $tempdir - -This is a temporary directory created for sbotools' use, and it should be -cleaned up when sbotools exits. -  =cut  # get $TMP from the env, if defined - we use two variables here because there @@ -85,8 +79,6 @@ our $env_tmp = $ENV{TMP};  our $tmpd = $env_tmp ? $env_tmp : '/tmp/SBo';  make_path($tmpd) unless -d $tmpd; -our $tempdir = tempdir(CLEANUP => 1, DIR => $tmpd); -  =head1 SUBROUTINES  =cut @@ -729,6 +721,8 @@ output will be C<undef> and the exit status will hold a true value.  sub run_tee {    my $cmd = shift; +  my $tempdir = tempdir(CLEANUP => 1, DIR => $tmpd); +    my $out_fh = tempfile(DIR => $tempdir);    my $out_fn = get_tmp_extfn($out_fh);    return undef, _ERR_F_SETFD if not defined $out_fn; diff --git a/SBO-Lib/lib/SBO/Lib/Repo.pm b/SBO-Lib/lib/SBO/Lib/Repo.pm index 6c7babb..5337ea8 100644 --- a/SBO-Lib/lib/SBO/Lib/Repo.pm +++ b/SBO-Lib/lib/SBO/Lib/Repo.pm @@ -442,10 +442,10 @@ C<$repo_path>, and if not, offer to run C<sbosnap fetch> for you.  sub slackbuilds_or_fetch {    unless (chk_slackbuilds_txt()) {      say 'It looks like you haven\'t run "sbosnap fetch" yet.'; -    if (prompt("Would you like me to do this now?", default => 'yes')) { +    if (($< == 0) && prompt("Would you like me to do this now?", default => 'yes')) {        fetch_tree();      } else { -      say 'Please run "sbosnap fetch"'; +      say 'Please run "sbosnap fetch" as root';        exit 0;      }    } @@ -13,7 +13,7 @@  use 5.16.0;  use strict;  use warnings FATAL => 'all'; -use SBO::Lib qw/ update_tree get_available_updates script_error open_fh is_local show_version get_local_outdated_versions /; +use SBO::Lib qw/ _ERR_USAGE update_tree get_available_updates script_error open_fh is_local show_version get_local_outdated_versions /;  use Getopt::Long;  use File::Basename;  use List::Util 'max'; @@ -42,6 +42,11 @@ GetOptions('help|h' => \$help, 'version|v' => \$vers);  if ($help) { show_usage(); exit 0 }  if ($vers) { show_version(); exit 0 } +unless ($< == 0) { +	warn "This script requires root privileges.\n"; +	exit +} +  update_tree();  # retrieve and format list of available updates @@ -13,7 +13,7 @@  use 5.16.0;  use strict;  use warnings FATAL => 'all'; -use SBO::Lib qw/ prompt usage_error script_error in show_version %config /; +use SBO::Lib qw/ _ERR_USAGE prompt usage_error script_error in show_version %config /;  use File::Basename;  use Getopt::Long qw(:config bundling);  use File::Path qw(remove_tree); @@ -56,6 +56,11 @@ if ($vers) { show_version(); exit 0 }  usage_error("You must specify at least one of -d or -w.") unless  	($dist || $work); +unless ($< == 0) { +	warn "This script requires root privileges.\n"; +	exit _ERR_USAGE; +} +  sub rm_full {  	script_error('rm_full requires an argument.') unless @_ == 1;  	my $full = shift; @@ -13,7 +13,7 @@  use 5.16.0;  use strict;  use warnings FATAL => 'all'; -use SBO::Lib qw/ slurp usage_error script_error $tempdir open_fh %config $conf_dir $conf_file show_version /; +use SBO::Lib qw/ _ERR_USAGE slurp usage_error script_error open_fh %config $conf_dir $conf_file show_version /;  use File::Basename;  use Getopt::Long qw(:config no_ignore_case_always);  use File::Copy; @@ -136,6 +136,11 @@ if (exists $changes{SLACKWARE_VERSION}) {  	usage_error("$warn -V") unless $changes{SLACKWARE_VERSION} =~ m/^(\d+\.\d+|FALSE)$/;  } +unless ($< == 0) { +	warn "This script requires root privileges.\n"; +	exit _ERR_USAGE; +} +  sub config_write {  	script_error('config_write requires at least two arguments.') unless @_ >= 2; @@ -13,7 +13,7 @@  use 5.16.0;  use strict;  use warnings FATAL => 'all'; -use SBO::Lib qw/ %config _ERR_OPENFH get_arch get_build_queue get_installed_cpans get_installed_packages get_sbo_location get_sbo_locations in merge_queues open_fh print_failures process_sbos prompt show_version slackbuilds_or_fetch slurp usage_error user_prompt /; +use SBO::Lib qw/ %config _ERR_USAGE _ERR_OPENFH get_arch get_build_queue get_installed_cpans get_installed_packages get_sbo_location get_sbo_locations in merge_queues open_fh print_failures process_sbos prompt show_version slackbuilds_or_fetch slurp usage_error user_prompt /;  use Getopt::Long qw(:config bundling);  use File::Basename;  use JSON::PP; @@ -95,6 +95,11 @@ if ($compat32) {  	usage_error("compat32 only works on x86_64.") unless get_arch eq 'x86_64';  } +unless ($< == 0) { +	warn "This script requires root privileges.\n"; +	exit _ERR_USAGE; +} +  # if we can't find SLACKBUILDS.TXT in $config{HOME}, prompt to fetch the tree  slackbuilds_or_fetch(); @@ -13,7 +13,7 @@  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 %config show_version /; +use SBO::Lib qw/ _ERR_USAGE 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 %config show_version /;  use Getopt::Long qw(:config bundling);  use File::Basename;  use File::Copy; @@ -71,6 +71,11 @@ GetOptions(  if ($help) { show_usage(); exit 0 }  if ($vers) { show_version(); exit 0 } +unless ($< == 0) { +	warn "This script requires root privileges.\n"; +	exit _ERR_USAGE; +} +  my $updates;  if ($all) {  	slackbuilds_or_fetch(); diff --git a/t/07-fail.t b/t/07-fail.t index cd1fa7c..fd1db42 100755 --- a/t/07-fail.t +++ b/t/07-fail.t @@ -11,7 +11,7 @@ use Test::Sbotools qw/ make_slackbuilds_txt set_lo set_repo sboconfig sboinstall  use File::Temp 'tempdir';  if ($ENV{TEST_INSTALL}) { -	plan tests => 24; +	plan tests => 26;  } else {  	plan skip_all => 'Only run these tests if TEST_INSTALL=1';  } diff --git a/t/16-clean.t b/t/16-clean.t index b695ae8..f756963 100755 --- a/t/16-clean.t +++ b/t/16-clean.t @@ -86,6 +86,8 @@ sboclean '-d', { exit => 0, expected => "Nothing to do.\n" };  # 13-15: sboclean -w [-i] with TMP set  {  	local $ENV{TMP} = tempdir(CLEANUP => 1); +        set_sbo_home("/usr/sbo"); +        sboinstall qw/ -r nonexistentslackbuild /, { test => 0 };  	sboclean qw/ -w -i /, { input => "n", expected => qr!\QRemove $ENV{TMP}/\E.*\Q? [n]\E! };  	sboclean qw/ -w -i /, { input => "y\ny", expected => qr!\QRemove $ENV{TMP}/\E.*\Q? [n]\E! };  	sboclean '-w', { input => "y", expected => qr/This will remove the entire contents of \Q$ENV{TMP}\E/ };  | 
