aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Pipkin <j@dawnrazor.net>2012-09-01 02:14:32 -0500
committerJacob Pipkin <j@dawnrazor.net>2012-09-01 02:14:32 -0500
commit6be3ef603fefc5d04b506b17cbad140790698042 (patch)
tree75c60a074913d766ae1216f52ddbbf269a79aedd
parente0bfabea2f76f45f8bb1450221d0d10cbcc9a516 (diff)
downloadsbotools2-6be3ef603fefc5d04b506b17cbad140790698042.tar.xz
more cleanups and fixes and such
-rw-r--r--SBO-Lib/lib/SBO/Lib.pm6
-rwxr-xr-xsbocheck8
-rwxr-xr-xsboclean6
-rwxr-xr-xsboconfig38
-rwxr-xr-xsbofind6
-rwxr-xr-xsboinstall4
-rwxr-xr-xsbosnap6
-rwxr-xr-xsboupgrade6
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
diff --git a/sbocheck b/sbocheck
index d2e6f91..e85042a 100755
--- a/sbocheck
+++ b/sbocheck
@@ -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);
diff --git a/sboclean b/sboclean
index 558272b..d85b7bc 100755
--- a/sboclean
+++ b/sboclean
@@ -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 () {
diff --git a/sboconfig b/sboconfig
index 2065a27..aca2ad1 100755
--- a/sboconfig
+++ b/sboconfig
@@ -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;
diff --git a/sbofind b/sbofind
index 16ad1b1..63ef7e9 100755
--- a/sbofind
+++ b/sbofind
@@ -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 () {
diff --git a/sboinstall b/sboinstall
index 3637207..54459b9 100755
--- a/sboinstall
+++ b/sboinstall
@@ -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);
diff --git a/sbosnap b/sbosnap
index 076cfb9..d17b8c7 100755
--- a/sbosnap
+++ b/sbosnap
@@ -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);
diff --git a/sboupgrade b/sboupgrade
index 6633834..0403712 100755
--- a/sboupgrade
+++ b/sboupgrade
@@ -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 () {