From d71c5ad7b6cd7f3aa697864a3aa32ff3162906d7 Mon Sep 17 00:00:00 2001 From: Dave Bucklin Date: Sat, 6 Apr 2019 02:03:19 +0000 Subject: [PATCH] Add command-line options -h and -t for help and truncate existing files, respectively. --- utils/bootstrap.pl | 51 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/utils/bootstrap.pl b/utils/bootstrap.pl index ba021bd..11798b0 100755 --- a/utils/bootstrap.pl +++ b/utils/bootstrap.pl @@ -3,14 +3,29 @@ use warnings; use strict; use Digest::MD5 qw(md5_hex); - -my $myNode = $ARGV[0] || die("usage: ./bootstrap.pl node-id\n"); +use Getopt::Std; +my $myNode = ""; +my $passwdFile = "passwd"; +my $callFile = "call"; +my $confFile = "config"; +my $sysFile = "sys"; +my $portFile = "port"; +my %options = (); sub getNodes { my $nodelist = "../nodelist"; open(my $data, '<', $nodelist) or die ("Cannot open nodelist"); + if ($options{t}) { + print("Truncating existing files\n"); + truncate($passwdFile,0); + truncate($callFile,0); + truncate($confFile,0); + truncate($sysFile,0); + truncate($portFile,0); + } + print("Generating files\n"); while (my $line = <$data>) { chomp $line; @@ -48,7 +63,6 @@ sub generatePort { protocol etyig }; - my $portFile = "port"; open(FH, '>>', $portFile); print FH $template; } @@ -75,8 +89,6 @@ sub generateSys { port $currentNode }; - my $sysFile = "sys"; - open(FH, '>>', $sysFile); print FH $template; } @@ -84,7 +96,6 @@ sub generateSys { sub generateConfig { my $nodeName = shift; - my $confFile = "config"; open(FH, '>>',$confFile); my $nodeConfig = "nodename\t\t".$nodeName."\n"; @@ -102,7 +113,6 @@ sub getKeys { sub generateCall{ my $nodeName = shift; - my $callFile = "call"; my $password = $nodeName.$myNode; my $callHash = md5_hex($password); @@ -115,7 +125,6 @@ sub generateCall{ sub generatePasswd { my $nodeName = shift; - my $passwdFile = "passwd"; my $password = $myNode.$nodeName; my $passwdHash = md5_hex($password); @@ -130,14 +139,36 @@ sub preCheck() { print("Updating git repo\n"); chdir("../"); - system("git pull"); + #system("git pull"); print("Installing authorized_keys\n"); - rename("authorized_keys",".ssh/authorized_keys"); + #rename("authorized_keys",".ssh/authorized_keys"); chdir("./utils"); print("Pre-flight checks done\n"); getNodes(); } +sub showHelp() +{ + print("Usage: bootstrap.pl [OPTION...] node-id\n"); + print("Generate uucp configuration files.\n\n"); + print(" -t truncate files before appending config\n"); + print(" -h display this help and exit\n"); +} + +getopts("ht", \%options); + +if ($ARGV[0]) { + my $myNode=$ARGV[0]; +} else { + showHelp(); + exit; +} + +if ($options{h}) { + showHelp(); + exit; +} + preCheck(); print("\n\n"); print("This setup script has finished. Please move the generated configuration files as ROOT to /etc/uucp\n");