#!/usr/bin/perl # use warnings; use strict; use Digest::MD5 qw(md5_hex); my $myNode = $ARGV[0]; sub getNodes { my $nodelist = "../nodelist"; open(my $data, '<', $nodelist) or die ("Cannot open nodelist"); print("Generating files\n"); while (my $line = <$data>) { chomp $line; my @fields = split(",", $line); my $nodeName = $fields[0]; my $nodeAddress = $fields[1]; generatePort($nodeName,$nodeAddress); generateSys($nodeName); generateCall($nodeName); generatePasswd($nodeName); getKeys($nodeAddress); generateConfig($myNode); print("System ".$nodeName." added successfully\n"); } print("Done\n\n"); } sub generatePort { my $nodeName = shift; my $nodeAddress = shift; my $currentNode = ucfirst($nodeName); my $template = qq{ port $currentNode type pipe command /usr/bin/ssh -a -x -q -i /var/spool/uucp/.ssh/id_rsa -l uucp $nodeAddress reliable true protocol etyig }; my $portFile = "port"; open(FH, '>', $portFile); print FH $template; } sub generateSys { my $nodeName = shift; my $currentNode = ucfirst($nodeName); my $template = qq{ system $nodeName call-login * call-password * local-send / local-receive /var/spool/uucppublic remote-send / remote-receive /var/spool/uucppublic time any forward ANY chat \"\" \\d\\d\\r\\c login: \\d\\L word: \\P chat-timeout 60 protocol t port $currentNode }; my $sysFile = "sys"; open(FH, '>', $sysFile); print FH $template; } sub generateConfig { my $nodeName = shift; my $confFile = "config"; open(FH, '>',$confFile); my $nodeConfig = "nodename\t\t".$nodeName; print FH $nodeConfig; } sub getKeys { my $address = shift; my $cmd = "/usr/bin/ssh-keyscan -H $address >> /var/spool/uucp/.ssh/known_hosts"; system($cmd); } sub generateCall{ my $nodeName = shift; my $callFile = "call"; my $password = $nodeName.$myNode; my $callHash = md5_hex($password); my $callPasswd = $nodeName."\t"."U".$myNode."\t".$callHash."\n"; open(FH, '>', $callFile); print FH $callPasswd; } sub generatePasswd { my $nodeName = shift; my $passwdFile = "passwd"; my $password = $myNode.$nodeName; my $passwdHash = md5_hex($password); my $authPasswd = "U".$nodeName."\t".$passwdHash."\n"; open(FH, '>', $passwdFile); print FH $authPasswd; } sub preCheck() { print("Updating git repo\n"); chdir("../"); system("git pull"); print("Installing authorized_keys\n"); rename("authorized_keys",".ssh/authorized_keys"); chdir("./utils"); print("Pre-flight checks done\n"); getNodes(); } preCheck(); print("\n\n"); print("This setup script has finished. Please move the generated configuration files as ROOT to /etc/uucp\n");