commit:ddd9aa223badf4b13c58a0563930778c9e664163
author:Chip Black
committer:Chip Black
date:Tue Aug 12 01:14:31 2008 -0500
parents:e4cebbfd0e61c931d89450c1fe4e084d06a326e7
Improvements to install script

Changed install script to use perl File::Copy and File::Path routines
instead of system("cp ...") so that it will still work despite the
historical relics OpenBSD ships in its /bin directory.  Also changed
configuration writing to autodetect the location of gpg, or warn you
if it can't find it.
diff --git a/install.pl b/install.pl
line changes: +27/-5
index 1aa90b6..a8897df
--- a/install.pl
+++ b/install.pl
@@ -5,6 +5,8 @@ use warnings;
 
 use Config;
 use Sys::Hostname;
+use File::Copy;
+use File::Path;
 
 my $etc = '/etc';
 my $bin = '/usr/bin';
@@ -75,18 +77,27 @@ print "Installing user binaries...\n";
 # No user binaries, LOL!
 
 print "Installing superuser binaries...\n";
-system("cp -fv ag-export ag-flush ag-import ag-keyring ag-listusers ag-passwd ag-update-shadow ag-useradd ag-userdel $sbin/");
+mkpath($sbin) unless -d $sbin;
+for my $file (qw/ag-export ag-flush ag-import ag-keyring ag-listusers ag-passwd ag-update-shadow ag-useradd ag-userdel/) {
+	print "$file => $sbin/$file\n";
+	copy($file, "$sbin/");
+	chmod 0700, "$sbin/$file";
+}
 
 print "Installing perl libraries...\n";
-system("mkdir -p $perllib/AwesomeGrid") unless -d "$perllib/AwesomeGrid";
-system("cp -rfv lib/AwesomeGrid.pm $perllib/");
-system("cp -rfv lib/AwesomeGrid/{Config,Keyring,User}.pm $perllib/AwesomeGrid/");
+mkpath("$perllib/AwesomeGrid") unless -d "$perllib/AwesomeGrid";
+print "lib/AwesomeGrid.pm => $perllib/AwesomeGrid.pm\n";
+copy("lib/AwesomeGrid.pm", "$perllib/");
+for my $file (qw/Config Keyring User/) {
+	print "lib/AwesomeGrid/$file.pm => $perllib/AwesomeGrid/$file.pm\n";
+	copy "lib/AwesomeGrid/$file.pm", "$perllib/AwesomeGrid/";
+}
 
 # Be extra careful for configuration bits
 umask 0077;
 
 print "Installing configuration...\n";
-mkdir "$etc/awesomegrid" unless -d "$etc/awesomegrid";
+mkpath("$etc/awesomegrid") unless -d "$etc/awesomegrid";
 unless (-f "$etc/awesomegrid/admins") {
 	open ADMINS, ">$etc/awesomegrid/admins";
 	print ADMINS <<EOD;
@@ -120,6 +131,16 @@ homedir: /home
 # The shell to give imported users if they don't specify one
 default-shell: /bin/bash
 EOD
+	my $gpg = `which gpg`;
+	if ($? >> 8 != 0) {
+		print <<EOD;
+I couldn't find gpg on your system. You'll have to edit
+$etc/awesomegrid/awesomegrid.conf and put in the
+location of gpg yourself.
+EOD
+	} else {
+		print CONF "gpg: $gpg\n";
+	}
 	close CONF;
 }
 mkdir "$etc/awesomegrid/users" unless -d "$etc/awesomegrid/users";
@@ -133,6 +154,7 @@ EOD
 	print "Shall I run 'ag-keyring initialize' to generate a new keyring? [Y/n] ";
 	my $ans = <STDIN>;
 	if ($ans =~ /^([Yy]|)$/) {
+		$ENV{AWESOMEGRID_CONFDIR} = "$etc/awesomegrid";
 		system("$sbin/ag-keyring initialize");
 	}
 }