Add files via upload
This commit is contained in:
parent
7d20baf07d
commit
6ec1d7eff4
3 changed files with 162 additions and 0 deletions
103
bootup.pl
Normal file
103
bootup.pl
Normal file
|
@ -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");
|
||||
}
|
||||
|
49
stepper.pl
Normal file
49
stepper.pl
Normal file
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# step maker for bootup.pl
|
||||
|
||||
use Storable;
|
||||
|
||||
%steps = ();
|
||||
|
||||
open(steps,"<steps");
|
||||
@lines = <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';
|
10
steps
Normal file
10
steps
Normal file
|
@ -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
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue