Update logging, path, docker scripts
This commit is contained in:
40
install.pl
40
install.pl
@@ -4,6 +4,7 @@ use warnings;
|
||||
use autodie;
|
||||
|
||||
use Cwd;
|
||||
use File::Path qw( make_path );
|
||||
|
||||
# Prevent running as root
|
||||
if ($< == 0) {
|
||||
@@ -13,25 +14,40 @@ if ($< == 0) {
|
||||
|
||||
my $dir = getcwd;
|
||||
|
||||
# Generate unique logfile
|
||||
my $uuid = `uuidgen`;
|
||||
chomp $uuid;
|
||||
my $log_path = "$dir/.install.$uuid.log";
|
||||
print "Logs: $log_path\n";
|
||||
my $log_target = $ENV{'LOG_TARGET'} // '';
|
||||
my $log_path = '';
|
||||
if ($log_target ne 'STDOUT') {
|
||||
# Generate unique logfile
|
||||
my $log_dir = "$dir/logs";
|
||||
make_path $log_dir or die "Failed to create path: $log_dir";
|
||||
my $uuid = `uuidgen`;
|
||||
chomp $uuid;
|
||||
$log_path = "$log_dir/$uuid.log";
|
||||
print "Logs: $log_target\n";
|
||||
}
|
||||
|
||||
# Execute given command and log appropriately
|
||||
# @arg 0 command to run
|
||||
sub execute {
|
||||
my $command = $log_path ne ''
|
||||
? "$_[0] &> $log_path"
|
||||
: $_[0];
|
||||
return system($command);
|
||||
}
|
||||
|
||||
|
||||
# Ensure dependencies installed
|
||||
`sudo apt-get update -y && sudo apt-get install -y liblocal-lib-perl cpanminus stow >> $log_path 2>&1`;
|
||||
execute("sudo apt-get update -qqy && sudo apt-get install -qqy liblocal-lib-perl cpanminus stow");
|
||||
|
||||
# Bootstrap files
|
||||
my $exit_status = `./bootstrap.pl >> $log_path 2>&1`;
|
||||
print $exit_status;
|
||||
execute("./bootstrap.pl");
|
||||
|
||||
# Read scripts to be installed
|
||||
my $install_dir = "$dir/install";
|
||||
print "Installing $install_dir\n";
|
||||
opendir(DIR, $install_dir) or die "Could not open $install_dir\n";
|
||||
my @files = readdir(DIR);
|
||||
closedir(DIR);
|
||||
opendir($dir, $install_dir) or die "Could not open $install_dir\n";
|
||||
my @files = readdir($dir);
|
||||
closedir($dir);
|
||||
@files = grep(/^\d{2}-.*\.sh$/, @files);
|
||||
@files = sort { lc($a) cmp lc($b) } @files;
|
||||
|
||||
@@ -42,7 +58,7 @@ if ($target ne 'all') {
|
||||
}
|
||||
foreach my $file (@files) {
|
||||
print "Running $file...\r";
|
||||
my $exit_status = system("/bin/bash -l $install_dir/$file >> $log_path 2>&1");
|
||||
my $exit_status = execute("/bin/bash -l $install_dir/$file");
|
||||
if ($exit_status != 0) {
|
||||
print "Failure in $file, see above and logs for more detail.\n";
|
||||
exit ($exit_status);
|
||||
|
||||
Reference in New Issue
Block a user