diff options
author | Jacob Pipkin <j@dawnrazor.net> | 2012-09-01 02:14:32 -0500 |
---|---|---|
committer | Jacob Pipkin <j@dawnrazor.net> | 2012-09-01 02:14:32 -0500 |
commit | 6be3ef603fefc5d04b506b17cbad140790698042 (patch) | |
tree | 75c60a074913d766ae1216f52ddbbf269a79aedd | |
parent | e0bfabea2f76f45f8bb1450221d0d10cbcc9a516 (diff) | |
download | sbotools2-6be3ef603fefc5d04b506b17cbad140790698042.tar.xz |
more cleanups and fixes and such
-rw-r--r-- | SBO-Lib/lib/SBO/Lib.pm | 6 | ||||
-rwxr-xr-x | sbocheck | 8 | ||||
-rwxr-xr-x | sboclean | 6 | ||||
-rwxr-xr-x | sboconfig | 38 | ||||
-rwxr-xr-x | sbofind | 6 | ||||
-rwxr-xr-x | sboinstall | 4 | ||||
-rwxr-xr-x | sbosnap | 6 | ||||
-rwxr-xr-x | sboupgrade | 6 |
8 files changed, 42 insertions, 38 deletions
diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm index 94ce3be..c5acbd3 100644 --- a/SBO-Lib/lib/SBO/Lib.pm +++ b/SBO-Lib/lib/SBO/Lib.pm @@ -36,6 +36,10 @@ our @EXPORT = qw( get_from_info get_tmp_extfn get_tmp_perlfn + $tempdir + $conf_dir + $conf_file + %config ); $< == 0 or die "This script requires root privileges.\n"; @@ -539,7 +543,7 @@ sub get_tmp_extfn ($) { sub get_tmp_perlfn ($) { exists $_[0] or script_error 'get_tmp_perlfn requires an argument.'; my $fh = clear_coe_bit shift; - return '+<=&'. fileno $fh; + return "+<=&". fileno $fh; } # prep and run .SlackBuild @@ -10,15 +10,11 @@ # license: WTFPL <http://sam.zoy.org/wtfpl/COPYING> use 5.16.0; +use strict; +use warnings FATAL => 'all'; use SBO::Lib; -use File::Basename; use Getopt::Std; use Text::Tabulate; -use warnings FATAL => 'all'; -use strict; - -my %config = %SBO::Lib::config; -my $self = basename ($0); my %options; getopts ('v',\%options); @@ -10,14 +10,14 @@ # license: WTFPL <http://sam.zoy.org/wtfpl/COPYING> use 5.16.0; +use strict; +use warnings FATAL => 'all'; use SBO::Lib; use File::Basename; use Getopt::Std; use File::Path qw(remove_tree); -use strict; -use warnings FATAL => 'all'; -my %config = %SBO::Lib::config; +#my %config = %SBO::Lib::config; my $self = basename ($0); sub show_usage () { @@ -19,7 +19,7 @@ use File::Copy; use File::Path qw(make_path); use File::Temp qw(tempfile);; -my %config = %SBO::Lib::config; +#my %config = %SBO::Lib::config; my $self = basename ($0); sub show_usage () { @@ -80,11 +80,11 @@ if (exists $changes{JOBS}) { ($changes{JOBS} =~ /^\d+$/ || $changes{JOBS} eq 'FALSE'); } -my $conf_dir = $SBO::Lib::conf_dir; -my $conf_file = $SBO::Lib::conf_file; +#my $conf_dir = $SBO::Lib::conf_dir; +#my $conf_file = $SBO::Lib::conf_file; -# safely modify our conf file; copy to a temp location, edit the temp file, -# move the edited file into place +# safely modify our conf file; write its contents to a temp file, modify the +# temp file, write the contents of the temp file back to the conf file sub config_write ($$) { exists $_[1] or script_error 'config_write requires two arguments.'; my ($key, $val) = @_; @@ -92,12 +92,14 @@ sub config_write ($$) { mkdir $conf_dir or die "Unable to create $conf_dir. Exiting.\n"; } if (-f $conf_file) { - my $tempfh = tempfile (DIR => $SBO::Lib::tempdir); - my $tempfn = get_tmp_perlfn $tempfh; - copy ($conf_file, $tempfn); +# my $tempfh = tempfile (DIR => $SBO::Lib::tempdir); + my $tempfh = tempfile (DIR => $tempdir); + my $conffh = open_read $conf_file; + my $conftents = do {local $/; <$conffh>}; + print {$tempfh} $conftents; # tie the file so that if $key is already there, we just change that # line and untie it - tie my @temp, 'Tie::File', $tempfn; + tie my @temp, 'Tie::File', $tempfh; my $has; my $regex = qr/\A\Q$key\E=/; FIRST: for my $tmpline (@temp) { @@ -105,16 +107,18 @@ sub config_write ($$) { } untie @temp; # otherwise, append our new $key=$value pair - unless ($has) { - my $fh = open_fh ($tempfn, '>>'); - print {$fh} "$key=$val\n"; - close $fh; - } - move ($tempfn, $conf_file) || return; + print {$tempfh} "$key=$val\n" unless $has; + seek $tempfh, 0, 0; + my $contents = do {local $/; <$tempfh>}; + close $conffh; + eval { $conffh = open_fh $conf_file, '>>' }; + warn "Cannot write configuration: $@\n", return if $@; + print {$conffh} $contents or return; + close $conffh, close $tempfh; } else { # no config file, easiest case of all. - my $fh = open_fh $conf_file, '>' || return; - say {$fh} "$key=$val"; + my $fh = open_fh $conf_file, '>' or return; + print {$fh} "$key=$val\n"; close $fh; } return 1; @@ -10,13 +10,13 @@ # license: WTFPL <http://sam.zoy.org/wtfpl/COPYING> use 5.16.0; +use strict; +use warnings FATAL => 'all'; use SBO::Lib; use File::Basename; use Getopt::Std; -use strict; -use warnings FATAL => 'all'; -my %config = %SBO::Lib::config; +#my %config = %SBO::Lib::config; my $self = basename ($0); sub show_usage () { @@ -10,11 +10,11 @@ # license: WTFPL <http://sam.zoy.org/wtfpl/COPYING> use 5.16.0; +use strict; +use warnings FATAL => 'all'; use SBO::Lib; use Getopt::Std; use File::Basename; -use strict; -use warnings FATAL => 'all'; my $self = basename ($0); @@ -13,13 +13,13 @@ # .01: initial creation. use 5.16.0; +use strict; +use warnings FATAL => 'all'; use SBO::Lib; use File::Basename; use Getopt::Std; -use warnings FATAL => 'all'; -use strict; -my %config = %SBO::Lib::config; +#my %config = %SBO::Lib::config; my $sbo_home = $config{SBO_HOME}; my $self = basename ($0); @@ -10,14 +10,14 @@ # license: WTFPL <http://sam.zoy.org/wtfpl/COPYING> use 5.16.0; +use strict; +use warnings FATAL => 'all'; use SBO::Lib; use File::Basename; use Getopt::Std; use File::Copy; -use strict; -use warnings FATAL => 'all'; -my %config = %SBO::Lib::config; +#my %config = %SBO::Lib::config; my $self = basename ($0); sub show_usage () { |