From 6ec1d7eff480b04f6491750f3a6281b28609cf07 Mon Sep 17 00:00:00 2001 From: Paul M Date: Sun, 1 Nov 2020 22:05:28 -0600 Subject: [PATCH] Add files via upload --- bootup.pl | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++ stepper.pl | 49 +++++++++++++++++++++++++ steps | 10 ++++++ 3 files changed, 162 insertions(+) create mode 100644 bootup.pl create mode 100644 stepper.pl create mode 100644 steps diff --git a/bootup.pl b/bootup.pl new file mode 100644 index 0000000..3eef407 --- /dev/null +++ b/bootup.pl @@ -0,0 +1,103 @@ +#!/usr/bin/perl + +# script for pibakery startup stuffs +# or other automated deployment + +# hooks into rc.local + +use Cwd; +use Storable; + +($arg) = @ARGV; +$dir = getcwd; +chomp($arg); +$steps = retrieve('/etc/stpcomp'); + +# network test is automatic +$result = eval { `ping -c 3 google.com` }; +unless($result) { + # If we get here it failed + #print $@; + $isonline = 0; +}else{ + $isonline = 1; +} + +if($arg eq "setup"){ + # Yes, this lazy + $rclocal = `cat /etc/rc.local`; + $rclocal =~ s/exit 0//g; + $rclocal .= "\n$^X $dir/$0 run"; # Don't try and comprehend this + $rclocal .= "\nexit 0;"; + #print "$rclocal"; + open(rct,">rc.local"); + print rct "$rclocal"; + close rct; + system("cp /etc/rc.local /etc/rc.local.orig"); + system("cp rc.local /etc/rc.local"); + + +} + +if($arg eq "run"){ + # Prepare for main execution loop + # main event loop + for $step ( sort(keys %{ $steps } )) { + # print "Step # ${$steps->{$step}} "; + print "Step = $step \n"; + for $substep ( sort(keys %{ $steps->{$step} } )) { + # print "substep = $substep\n"; + for $exeord ( keys %{ $steps->{$step}->{$substep} }){ + $lstep = $step; + $lsubstep = $substep; + + if($steps->{$step}->{$substep}->{$exeord} =~ /reboot/i){ + # reboot handler + print "REBOOT\n"; + delete $steps->{$step}->{$substep}; + store \%$steps, 'stpcomp'; + exec("reboot"); + exit(0); + + } + + if($steps->{$step}->{$substep}->{$exeord} =~ /wifi/i){ + open(wifis,">/etc/wpa_supplicant/wpa_supplicant.conf"); + print wifis "country=US\n"; + print wifis "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\n"; + print wifis "update_config=1\n"; + print wifis "\n\n"; + print wifis "network={\n"; + print wifis " ssid=\"yourwifissid\"\n"; + print wifis " scan_ssid=1\n"; + print wifis " key_mgmt=WPA-PSK\n"; + print wifis " psk=\"yourpassword\"\n"; + print wifis "}\n"; + close(wifis); + delete $steps->{$step}->{$substep}; + }else{ + system("$steps->{$step}->{$substep}->{$exeord}"); + delete $steps->{$step}->{$substep}; + } + + } + + } +delete $steps->{$step}; +} + # end of main event loop +} + +if($arg eq "remove"){ + # Yes, this lazy + $rclocal = `cat /etc/rc.local`; + $rclocal =~ s/exit 0;//g; + $rclocal =~ s/$^X $dir\/$0 run//g; # Don't try and comprehend this + $rclocal .= "\nexit 0;"; + #print "$rclocal"; + open(rct,">rc.local"); + print rct "$rclocal"; + close rct; + system("cp rc.local /etc/rc.local"); +} + diff --git a/stepper.pl b/stepper.pl new file mode 100644 index 0000000..31e980d --- /dev/null +++ b/stepper.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +# step maker for bootup.pl + +use Storable; + +%steps = (); + +open(steps,"; +close steps; + +# First item must be total number of steps + +# each step consists of actions, can be multiple + +foreach(@lines){ + + if($_ =~ /(step)/i){ + #print "New step number $sc\n"; + $sc++; + $substep = 1; + next; + }else{ + @lp = split(/ /,$_); + #print " Step num = $sc\n"; + for (my $i=1; $i <= scalar(@lp); $i++) { + $cmd .= "@lp[$i] "; + } + #print "CMD = $cmd"; + $steps{$sc}{$substep}{@lp[0]} = $cmd; + #print "LP = @lp\n"; + undef(@lp); + undef($cmd); + $substep++; + } +} + +for $family ( keys %steps ) { + #print "Step # $family: "; + for $role ( keys %{ $steps{$family} } ) { + for $exeord ( keys %{ $steps{$family}{$role}}){ + # print "sub hashex $exeord $role=$steps{$family}{$role}{$exeord} "; + } + #print "sub hash $role=$steps{$family}{$role} "; + } + # print "\n"; +} +store \%steps, 'stpcomp'; diff --git a/steps b/steps new file mode 100644 index 0000000..85dc816 --- /dev/null +++ b/steps @@ -0,0 +1,10 @@ +step 1 +run apt-get update +run apt-get upgrade -y +step 2 +run curl -sSL https://get.docker.com | sh +step 3 +run apt install python3-pip -y +run apt install docker-compose -y +step 4 +