add older scripts, experiments
This commit is contained in:
parent
f72c728cfd
commit
81de8248c3
|
@ -0,0 +1,144 @@
|
||||||
|
#!/usr/bin/env perl
|
||||||
|
#
|
||||||
|
# Copyright (c) 2020 Mischa Peters <mischa @ openbsd.amsterdam>
|
||||||
|
#
|
||||||
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
# copyright notice and this permission notice appear in all copies.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
#
|
||||||
|
# vmm(4)/vmd(8) VM deploy notify script for OpenBSD Amsterdam
|
||||||
|
# 2020/05/12 initial release
|
||||||
|
#
|
||||||
|
use 5.024;
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use autodie;
|
||||||
|
|
||||||
|
my $email_template = "email-deploy.txt";
|
||||||
|
my $deployed_vmid = $ARGV[0];
|
||||||
|
|
||||||
|
# fuction to parse _deploy.conf and vm*.txt files
|
||||||
|
# all variables are stripped and added to either %vms or %conf
|
||||||
|
sub get_variables {
|
||||||
|
my ($hash_name, @files) = @_;
|
||||||
|
my %hash;
|
||||||
|
my $filename;
|
||||||
|
my $vm_name;
|
||||||
|
my $vm_number;
|
||||||
|
|
||||||
|
for my $file (@files) {
|
||||||
|
# When hash is 'vms' use the vm_name as key
|
||||||
|
# Otherwise use 'conf' as key
|
||||||
|
if ($hash_name eq "vms") {
|
||||||
|
($filename = $file) =~ s/.*\///;
|
||||||
|
($vm_name = $filename) =~ s/\.txt//;
|
||||||
|
($vm_number = $vm_name) =~ s/^vm//;
|
||||||
|
$hash{$vm_name}{'vm_number'} = $vm_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
open my $fh, "<", "$file";
|
||||||
|
while (my $row = <$fh>) {
|
||||||
|
next if ($row =~ /^\s*($|#)/);
|
||||||
|
chomp ($row);
|
||||||
|
(my $key, my $val) = split(/=/, $row, 2);
|
||||||
|
if ($hash_name eq "vms") {
|
||||||
|
($hash{$vm_name}{$key} .= $val) =~ s/^"+|"+$//g;
|
||||||
|
} else {
|
||||||
|
($hash{$hash_name}{$key} .= $val) =~ s/^"+|"+$//g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close $fh;
|
||||||
|
}
|
||||||
|
return %hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to notify people
|
||||||
|
sub notify {
|
||||||
|
my %conf = %{$_[0]};
|
||||||
|
my %vms = %{$_[1]};
|
||||||
|
my $_etc = $conf{'conf'}{'ETC'};
|
||||||
|
my $_server = $conf{'conf'}{'SERVER'};
|
||||||
|
my $_vms = $conf{'conf'}{'VMS'};
|
||||||
|
my $template = "$_vms/../$email_template";
|
||||||
|
|
||||||
|
for my $vm_name (sort keys %vms) {
|
||||||
|
my $_name = $vms{$vm_name}{'name'};
|
||||||
|
my $_email = $vms{$vm_name}{'email'};
|
||||||
|
my $_hostname = $vms{$vm_name}{'hostname'};
|
||||||
|
|
||||||
|
if ($deployed_vmid =~ /$vm_name/) {
|
||||||
|
(my $_firstname, my $_lastname) = split(/ /, $_name, 2);
|
||||||
|
my $_ipaddress = qx(grep -A2 $vm_name $_etc/dhcpd.conf | awk '/fixed-address/{print \$2}' | tr -d ';\n');
|
||||||
|
print "NOTIFIED: $_name, $_email, $_hostname, $_server ($vm_name), $_ipaddress\n";
|
||||||
|
|
||||||
|
open(my $fh, '<', $template) or die "Could not open file '$template' $!";
|
||||||
|
open my $fh_email, "|-", "/usr/sbin/sendmail -t";
|
||||||
|
|
||||||
|
printf $fh_email "To: %s\n", $_email;
|
||||||
|
|
||||||
|
while (my $row = <$fh>) {
|
||||||
|
chomp $row;
|
||||||
|
$row =~ s/NAME/$_firstname/g;
|
||||||
|
$row =~ s/IP$/$_ipaddress/g;
|
||||||
|
$row =~ s/VMID/$vm_name/g;
|
||||||
|
$row =~ s/SERVER/$_server/g;
|
||||||
|
print $fh_email "$row\n";
|
||||||
|
}
|
||||||
|
close $fh_email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to print all keys & values for debug purposes
|
||||||
|
sub debug_parse {
|
||||||
|
my %conf = %{$_[0]};
|
||||||
|
my %vms = %{$_[1]};
|
||||||
|
print "All VMs\n##\n";
|
||||||
|
for my $vm_name (sort keys %vms) {
|
||||||
|
my $_date = $vms{$vm_name}{'date'};
|
||||||
|
my $_payment = $vms{$vm_name}{'payment'};
|
||||||
|
my $_donated = $vms{$vm_name}{'donated'};
|
||||||
|
my $_name = $vms{$vm_name}{'name'};
|
||||||
|
my $_email = $vms{$vm_name}{'email'};
|
||||||
|
my $_hostname = $vms{$vm_name}{'hostname'};
|
||||||
|
print "$_date, $_payment, $_name, $_email, $_hostname, ($vm_name)\n";
|
||||||
|
}
|
||||||
|
print "##\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
# check if _deploy.conf exists
|
||||||
|
my $dev = $ENV{'HOME'} . "/openbsd.amsterdam/deploy.pl";
|
||||||
|
my $prod = $ENV{'HOME'};
|
||||||
|
my $dir;
|
||||||
|
my $debug;
|
||||||
|
my %conf;
|
||||||
|
my %vms;
|
||||||
|
if (-d "$dev") {
|
||||||
|
$dir = $dev;
|
||||||
|
$debug = 1;
|
||||||
|
} else {
|
||||||
|
$dir = $prod;
|
||||||
|
}
|
||||||
|
if (-e "$dir/_deploy.conf") {
|
||||||
|
%conf = get_variables('conf', "$dir/_deploy.conf");
|
||||||
|
} else {
|
||||||
|
printf "Unable to find config file in current directory (%s).\n", $dir;
|
||||||
|
printf "Create the config file _deploy.conf in %s.\n", $dir;
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
# parse all vm*.txt files in the VMS directory
|
||||||
|
my @files = glob "$conf{'conf'}{'VMS'}/*.txt";
|
||||||
|
%vms = get_variables('vms', @files);
|
||||||
|
|
||||||
|
# run all functions
|
||||||
|
if ($debug) { debug_parse(\%conf, \%vms); }
|
||||||
|
notify(\%conf, \%vms);
|
|
@ -0,0 +1,183 @@
|
||||||
|
#!/usr/bin/env perl
|
||||||
|
#
|
||||||
|
# Copyright (c) 2018-2020 Mischa Peters <mischa @ openbsd.amsterdam>
|
||||||
|
#
|
||||||
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
# copyright notice and this permission notice appear in all copies.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
#
|
||||||
|
# vmm(4)/vmd(8) VM renewal notify script for OpenBSD Amsterdam
|
||||||
|
# 2019/04/13 initial release
|
||||||
|
# 2019/11/29 changed: merged notify.pl and reminder.pl, match on month, calculate months automatically
|
||||||
|
# 2019/12/03 added: vm_name and _server to make it easier to identify which vm.
|
||||||
|
# 2020/05/11 added: use local relay to send out email
|
||||||
|
#
|
||||||
|
use 5.024;
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use autodie;
|
||||||
|
use POSIX qw(strftime);
|
||||||
|
|
||||||
|
my $week = $ARGV[0] || 3;
|
||||||
|
|
||||||
|
my $total_donated = qx(ftp -Vo- https://obsda.ms/index.html | grep "donated to OpenBSD" | awk -F';' '{print \$4}' | awk '{printf \$1}');
|
||||||
|
my $total_vms = qx(ftp -Vo- https://obsda.ms/index.html | grep "deployed" | awk -F '>' '{print \$3}' | awk '{printf \$1}');
|
||||||
|
my $total_hosts = qx(ftp -Vo- https://obsda.ms/servers.html | grep ">Server " | wc -l | tr -d ' ' | tr -d '\n');
|
||||||
|
|
||||||
|
# fuction to parse _deploy.conf and vm*.txt files
|
||||||
|
# all variables are stripped and added to either %vms or %conf
|
||||||
|
sub get_variables {
|
||||||
|
my ($hash_name, @files) = @_;
|
||||||
|
my %hash;
|
||||||
|
my $filename;
|
||||||
|
my $vm_name;
|
||||||
|
my $vm_number;
|
||||||
|
|
||||||
|
for my $file (@files) {
|
||||||
|
# When hash is 'vms' use the vm_name as key
|
||||||
|
# Otherwise use 'conf' as key
|
||||||
|
if ($hash_name eq "vms") {
|
||||||
|
($filename = $file) =~ s/.*\///;
|
||||||
|
($vm_name = $filename) =~ s/\.txt//;
|
||||||
|
($vm_number = $vm_name) =~ s/^vm//;
|
||||||
|
$hash{$vm_name}{'vm_number'} = $vm_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
open my $fh, "<", "$file";
|
||||||
|
while (my $row = <$fh>) {
|
||||||
|
next if ($row =~ /^\s*($|#)/);
|
||||||
|
chomp ($row);
|
||||||
|
(my $key, my $val) = split(/=/, $row, 2);
|
||||||
|
if ($hash_name eq "vms") {
|
||||||
|
($hash{$vm_name}{$key} .= $val) =~ s/^"+|"+$//g;
|
||||||
|
} else {
|
||||||
|
($hash{$hash_name}{$key} .= $val) =~ s/^"+|"+$//g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close $fh;
|
||||||
|
}
|
||||||
|
return %hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to notify people
|
||||||
|
sub notify {
|
||||||
|
my %conf = %{$_[0]};
|
||||||
|
my %vms = %{$_[1]};
|
||||||
|
my $_server = $conf{'conf'}{'SERVER'};
|
||||||
|
my $_vms = $conf{'conf'}{'VMS'};
|
||||||
|
|
||||||
|
my $year = strftime ("%Y", localtime);
|
||||||
|
my $month = strftime ("%m", localtime);
|
||||||
|
my $day = strftime ("%d", localtime);
|
||||||
|
my $timestamp = strftime "%a, %d %b %Y %H:%M:%S %z", localtime;
|
||||||
|
|
||||||
|
for my $vm_name (sort keys %vms) {
|
||||||
|
my $_date = $vms{$vm_name}{'date'};
|
||||||
|
my $_payment = $vms{$vm_name}{'payment'};
|
||||||
|
my $_donated = $vms{$vm_name}{'donated'};
|
||||||
|
my $_name = $vms{$vm_name}{'name'};
|
||||||
|
my $_email = $vms{$vm_name}{'email'};
|
||||||
|
my $_hostname = $vms{$vm_name}{'hostname'};
|
||||||
|
|
||||||
|
if ($_donated =~ /done/) { next; }
|
||||||
|
if ($_donated =~ /expire/) { next; }
|
||||||
|
if ($_donated =~ /sponsor/) { next; }
|
||||||
|
if ($_donated =~ /renewal/) { next; }
|
||||||
|
if ($_date =~ /$year\//) { next; }
|
||||||
|
if ($_date =~ /\/$month\//) {
|
||||||
|
(my $_year, my $_month, my $_day) = split(/\//, $_date, 3);
|
||||||
|
(my $_firstname, my $_lastname) = split(/ /, $_name, 2);
|
||||||
|
my $membership = ($year - $_year) * 12;
|
||||||
|
print "RENEW: $_date ($membership), $_payment, $_name, $_email, $_hostname, $_server ($vm_name)\n";
|
||||||
|
|
||||||
|
open my $fh_email, "|-", "/usr/sbin/sendmail -t";
|
||||||
|
printf $fh_email "To: <%s>\n", $_email;
|
||||||
|
printf $fh_email "From: Mischa <mischa\@openbsd.amsterdam>\n";
|
||||||
|
printf $fh_email "Date: %s\n", $timestamp;
|
||||||
|
if ($week == 3) {
|
||||||
|
printf $fh_email "Subject: OpenBSD Amsterdam Renewal $year\n\n";
|
||||||
|
} else {
|
||||||
|
printf $fh_email "Subject: OpenBSD Amsterdam Renewal $year Reminder\n\n";
|
||||||
|
}
|
||||||
|
printf $fh_email "Hi %s,\n\n", $_firstname;
|
||||||
|
printf $fh_email "First and foremost, we thank you for your continued support!\n\n";
|
||||||
|
printf $fh_email "Can you believe that it's been $membership months since you started with\n";
|
||||||
|
printf $fh_email "your VM?\n\n";
|
||||||
|
printf $fh_email "Since that time, your support has enabled us to reach the following\n";
|
||||||
|
printf $fh_email "milestones:\n\n";
|
||||||
|
printf $fh_email "1) Donate €$total_donated to the OpenBSD Foundation\n";
|
||||||
|
printf $fh_email "2) Deploy $total_vms VMs\n";
|
||||||
|
printf $fh_email "3) Deploy $total_hosts hosts\n\n";
|
||||||
|
printf $fh_email "We really hope you have been happy with the service provided, if so,\n";
|
||||||
|
printf $fh_email "please consider renewing now. You can find all the options to renew at:\n\n";
|
||||||
|
printf $fh_email "https://openbsd.amsterdam/pay.html\n\n";
|
||||||
|
printf $fh_email "Your renewal fee for %s on %s this year is €%d.\n", $vm_name, $_server, $_payment;
|
||||||
|
printf $fh_email "For every renewal we will donate €15 to the OpenBSD Foundation.\n\n";
|
||||||
|
printf $fh_email "When you want to cancel your VM please let us know, when we don't\n";
|
||||||
|
if ($week == 1) {
|
||||||
|
printf $fh_email "hear from you within the next week we will remove your VM.\n\n";
|
||||||
|
} else {
|
||||||
|
printf $fh_email "hear from you within the next $week weeks we will remove your VM.\n\n";
|
||||||
|
}
|
||||||
|
printf $fh_email "Mischa\n\n";
|
||||||
|
printf $fh_email "--\n";
|
||||||
|
printf $fh_email "OpenBSD Amsterdam\n";
|
||||||
|
printf $fh_email "https://obsda.ms\n";
|
||||||
|
close $fh_email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to print all keys & values for debug purposes
|
||||||
|
sub debug_parse {
|
||||||
|
my %conf = %{$_[0]};
|
||||||
|
my %vms = %{$_[1]};
|
||||||
|
print "All VMs\n##\n";
|
||||||
|
for my $vm_name (sort keys %vms) {
|
||||||
|
my $_date = $vms{$vm_name}{'date'};
|
||||||
|
my $_payment = $vms{$vm_name}{'payment'};
|
||||||
|
my $_donated = $vms{$vm_name}{'donated'};
|
||||||
|
my $_name = $vms{$vm_name}{'name'};
|
||||||
|
my $_email = $vms{$vm_name}{'email'};
|
||||||
|
my $_hostname = $vms{$vm_name}{'hostname'};
|
||||||
|
print "$_date, $_payment, $_name, $_email, $_hostname, ($vm_name)\n";
|
||||||
|
}
|
||||||
|
print "##\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
# check if _deploy.conf exists
|
||||||
|
my $dev = $ENV{'HOME'} . "/openbsd.amsterdam/deploy.pl";
|
||||||
|
my $prod = $ENV{'HOME'};
|
||||||
|
my $dir;
|
||||||
|
my $debug;
|
||||||
|
my %conf;
|
||||||
|
my %vms;
|
||||||
|
if (-d "$dev") {
|
||||||
|
$dir = $dev;
|
||||||
|
$debug = 1;
|
||||||
|
} else {
|
||||||
|
$dir = $prod;
|
||||||
|
}
|
||||||
|
if (-e "$dir/_deploy.conf") {
|
||||||
|
%conf = get_variables('conf', "$dir/_deploy.conf");
|
||||||
|
} else {
|
||||||
|
printf "Unable to find config file in current directory (%s).\n", $dir;
|
||||||
|
printf "Create the config file _deploy.conf in %s.\n", $dir;
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
# parse all vm*.txt files in the VMS directory
|
||||||
|
my @files = glob "$conf{'conf'}{'VMS'}/*.txt";
|
||||||
|
%vms = get_variables('vms', @files);
|
||||||
|
|
||||||
|
# run all functions
|
||||||
|
if ($debug) { debug_parse(\%conf, \%vms); }
|
||||||
|
notify(\%conf, \%vms);
|
|
@ -0,0 +1,152 @@
|
||||||
|
#!/usr/bin/env perl
|
||||||
|
#
|
||||||
|
# Copyright (c) 2020 Mischa Peters <mischa @ openbsd.amsterdam>
|
||||||
|
#
|
||||||
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
# copyright notice and this permission notice appear in all copies.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
#
|
||||||
|
# vmm(4)/vmd(8) VM not running notify script for OpenBSD Amsterdam
|
||||||
|
# 2020/05/03 initial release
|
||||||
|
# 2020/05/07 added: exception variable boot="no"
|
||||||
|
# 2020/05/11 added: use local relay to send out email
|
||||||
|
#
|
||||||
|
use 5.024;
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use autodie;
|
||||||
|
|
||||||
|
my $email_template = "email-stopped.txt";
|
||||||
|
|
||||||
|
# fuction to parse _deploy.conf and vm*.txt files
|
||||||
|
# all variables are stripped and added to either %vms or %conf
|
||||||
|
sub get_variables {
|
||||||
|
my ($hash_name, @files) = @_;
|
||||||
|
my %hash;
|
||||||
|
my $filename;
|
||||||
|
my $vm_name;
|
||||||
|
my $vm_number;
|
||||||
|
|
||||||
|
for my $file (@files) {
|
||||||
|
# When hash is 'vms' use the vm_name as key
|
||||||
|
# Otherwise use 'conf' as key
|
||||||
|
if ($hash_name eq "vms") {
|
||||||
|
($filename = $file) =~ s/.*\///;
|
||||||
|
($vm_name = $filename) =~ s/\.txt//;
|
||||||
|
($vm_number = $vm_name) =~ s/^vm//;
|
||||||
|
$hash{$vm_name}{'vm_number'} = $vm_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
open my $fh, "<", "$file";
|
||||||
|
while (my $row = <$fh>) {
|
||||||
|
next if ($row =~ /^\s*($|#)/);
|
||||||
|
chomp ($row);
|
||||||
|
(my $key, my $val) = split(/=/, $row, 2);
|
||||||
|
if ($hash_name eq "vms") {
|
||||||
|
($hash{$vm_name}{$key} .= $val) =~ s/^"+|"+$//g;
|
||||||
|
} else {
|
||||||
|
($hash{$hash_name}{$key} .= $val) =~ s/^"+|"+$//g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close $fh;
|
||||||
|
}
|
||||||
|
return %hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to notify people
|
||||||
|
sub notify {
|
||||||
|
my %conf = %{$_[0]};
|
||||||
|
my %vms = %{$_[1]};
|
||||||
|
my $_etc = $conf{'conf'}{'ETC'};
|
||||||
|
my $_server = $conf{'conf'}{'SERVER'};
|
||||||
|
my $_vms = $conf{'conf'}{'VMS'};
|
||||||
|
my $template = "$_vms/../$email_template";
|
||||||
|
|
||||||
|
my @stopped_vms = qx(vmctl show | grep stopped | awk '{print \$9}');
|
||||||
|
|
||||||
|
for my $vm_name (sort keys %vms) {
|
||||||
|
my $_name = $vms{$vm_name}{'name'};
|
||||||
|
my $_email = $vms{$vm_name}{'email'};
|
||||||
|
my $_hostname = $vms{$vm_name}{'hostname'};
|
||||||
|
my $_boot = $vms{$vm_name}{'boot'} || "yes";
|
||||||
|
|
||||||
|
if ($_boot =~ /no/) {
|
||||||
|
print "NOT NOTIFIED: $_name, $_email, $_hostname, $_server ($vm_name)\n";
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
if (grep(/$vm_name/, @stopped_vms)) {
|
||||||
|
(my $_firstname, my $_lastname) = split(/ /, $_name, 2);
|
||||||
|
my $_ipaddress = qx(grep -A2 $vm_name $_etc/dhcpd.conf | awk '/fixed-address/{print \$2}' | sed 's/;//' | tr -d '\n');
|
||||||
|
print "NOTIFIED: $_name, $_email, $_hostname, $_server ($vm_name), $_ipaddress\n";
|
||||||
|
|
||||||
|
open(my $fh, '<', $template) or die "Could not open file '$template' $!";
|
||||||
|
open my $fh_email, "|-", "/usr/sbin/sendmail -t";
|
||||||
|
|
||||||
|
printf $fh_email "To: %s\n", $_email;
|
||||||
|
|
||||||
|
while (my $row = <$fh>) {
|
||||||
|
chomp $row;
|
||||||
|
$row =~ s/NAME/$_firstname/g;
|
||||||
|
$row =~ s/IP$/$_ipaddress/g;
|
||||||
|
$row =~ s/VMID/$vm_name/g;
|
||||||
|
$row =~ s/SERVER/$_server/g;
|
||||||
|
print $fh_email "$row\n";
|
||||||
|
}
|
||||||
|
close $fh_email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to print all keys & values for debug purposes
|
||||||
|
sub debug_parse {
|
||||||
|
my %conf = %{$_[0]};
|
||||||
|
my %vms = %{$_[1]};
|
||||||
|
print "All VMs\n##\n";
|
||||||
|
for my $vm_name (sort keys %vms) {
|
||||||
|
my $_date = $vms{$vm_name}{'date'};
|
||||||
|
my $_payment = $vms{$vm_name}{'payment'};
|
||||||
|
my $_donated = $vms{$vm_name}{'donated'};
|
||||||
|
my $_name = $vms{$vm_name}{'name'};
|
||||||
|
my $_email = $vms{$vm_name}{'email'};
|
||||||
|
my $_hostname = $vms{$vm_name}{'hostname'};
|
||||||
|
print "$_date, $_payment, $_name, $_email, $_hostname, ($vm_name)\n";
|
||||||
|
}
|
||||||
|
print "##\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
# check if _deploy.conf exists
|
||||||
|
my $dev = $ENV{'HOME'} . "/openbsd.amsterdam/deploy.pl";
|
||||||
|
my $prod = $ENV{'HOME'};
|
||||||
|
my $dir;
|
||||||
|
my $debug;
|
||||||
|
my %conf;
|
||||||
|
my %vms;
|
||||||
|
if (-d "$dev") {
|
||||||
|
$dir = $dev;
|
||||||
|
$debug = 1;
|
||||||
|
} else {
|
||||||
|
$dir = $prod;
|
||||||
|
}
|
||||||
|
if (-e "$dir/_deploy.conf") {
|
||||||
|
%conf = get_variables('conf', "$dir/_deploy.conf");
|
||||||
|
} else {
|
||||||
|
printf "Unable to find config file in current directory (%s).\n", $dir;
|
||||||
|
printf "Create the config file _deploy.conf in %s.\n", $dir;
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
# parse all vm*.txt files in the VMS directory
|
||||||
|
my @files = glob "$conf{'conf'}{'VMS'}/*.txt";
|
||||||
|
%vms = get_variables('vms', @files);
|
||||||
|
|
||||||
|
# run all functions
|
||||||
|
if ($debug) { debug_parse(\%conf, \%vms); }
|
||||||
|
notify(\%conf, \%vms);
|
|
@ -0,0 +1,192 @@
|
||||||
|
#!/usr/bin/env perl
|
||||||
|
#
|
||||||
|
# Copyright (c) 2018-2019 Mischa Peters <mischa @ openbsd.amsterdam>
|
||||||
|
#
|
||||||
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
# copyright notice and this permission notice appear in all copies.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
#
|
||||||
|
# vmm(4)/vmd(8) VM notify script for OpenBSD Amsterdam
|
||||||
|
# 2019/04/13 Initial release
|
||||||
|
# 2019/11/29 Merged notify.pl and reminder.pl, match on month, calculate months automatically
|
||||||
|
# 2019/12/03 added vm_name and _server to make it easier to identify which vm.
|
||||||
|
#
|
||||||
|
use 5.024;
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use autodie;
|
||||||
|
use Cwd qw(cwd);
|
||||||
|
use POSIX qw(strftime);
|
||||||
|
|
||||||
|
my $week = $ARGV[0] || 3;
|
||||||
|
|
||||||
|
my $total_donated = qx(ftp -Vo- https://obsda.ms/index.html | grep "donated to OpenBSD" | awk -F';' '{print \$4}' | awk '{printf \$1}');
|
||||||
|
my $total_vms = qx(ftp -Vo- https://obsda.ms/index.html | grep "deployed" | awk -F '>' '{print \$3}' | awk '{printf \$1}');
|
||||||
|
my $total_hosts = qx(ftp -Vo- https://obsda.ms/servers.html | grep ">Server " | wc -l | tr -d ' ' | tr -d '\n');
|
||||||
|
|
||||||
|
# fuction to parse _deploy.conf and vm*.txt files
|
||||||
|
# all variables are stripped and added to either %vms or %conf
|
||||||
|
sub get_variables {
|
||||||
|
my ($hash_name, @files) = @_;
|
||||||
|
my %hash;
|
||||||
|
my $filename;
|
||||||
|
my $vm_name;
|
||||||
|
my $vm_number;
|
||||||
|
|
||||||
|
for my $file (@files) {
|
||||||
|
# When hash is 'vms' use the vm_name as key
|
||||||
|
# Otherwise use 'conf' as key
|
||||||
|
if ($hash_name eq "vms") {
|
||||||
|
($filename = $file) =~ s/.*\///;
|
||||||
|
($vm_name = $filename) =~ s/\.txt//;
|
||||||
|
($vm_number = $vm_name) =~ s/^vm//;
|
||||||
|
$hash{$vm_name}{'vm_number'} = $vm_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
open my $fh, "<", "$file";
|
||||||
|
while (my $row = <$fh>) {
|
||||||
|
next if ($row =~ /^\s*($|#)/);
|
||||||
|
chomp ($row);
|
||||||
|
(my $key, my $val) = split(/=/, $row, 2);
|
||||||
|
if ($hash_name eq "vms") {
|
||||||
|
($hash{$vm_name}{$key} .= $val) =~ s/^"+|"+$//g;
|
||||||
|
} else {
|
||||||
|
($hash{$hash_name}{$key} .= $val) =~ s/^"+|"+$//g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close $fh;
|
||||||
|
}
|
||||||
|
return %hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to notify people on their renewal
|
||||||
|
sub notify_renewal {
|
||||||
|
my %conf = %{$_[0]};
|
||||||
|
my %vms = %{$_[1]};
|
||||||
|
my $_server = $conf{'conf'}{'SERVER'};
|
||||||
|
my $_vms = $conf{'conf'}{'VMS'};
|
||||||
|
|
||||||
|
my $year = strftime ("%Y", localtime);
|
||||||
|
my $month = strftime ("%m", localtime);
|
||||||
|
my $day = strftime ("%d", localtime);
|
||||||
|
my $timestamp = strftime "%a, %d %b %Y %H:%M:%S %z", localtime;
|
||||||
|
|
||||||
|
open my $fh_email, ">", "$_vms/../renewal-email.txt";
|
||||||
|
printf $fh_email "HELO %s.openbsd.amsterdam\n", $_server;
|
||||||
|
|
||||||
|
for my $vm_name (sort keys %vms) {
|
||||||
|
my $_date = $vms{$vm_name}{'date'};
|
||||||
|
my $_payment = $vms{$vm_name}{'payment'};
|
||||||
|
my $_donated = $vms{$vm_name}{'donated'};
|
||||||
|
my $_name = $vms{$vm_name}{'name'};
|
||||||
|
my $_email = $vms{$vm_name}{'email'};
|
||||||
|
my $_hostname = $vms{$vm_name}{'hostname'};
|
||||||
|
|
||||||
|
#print "$_date ($week), $_payment, $_name, $_email, $_hostname, $_server ($vm_name)\n"; }
|
||||||
|
|
||||||
|
if ($_donated =~ /done/) { next; }
|
||||||
|
if ($_donated =~ /expire/) { next; }
|
||||||
|
if ($_donated =~ /sponsor/) { next; }
|
||||||
|
if ($_donated =~ /renewal/) { next; }
|
||||||
|
if ($_date =~ /$year\//) { next; }
|
||||||
|
if ($_date =~ /\/$month\//) {
|
||||||
|
(my $_year, my $_month, my $_day) = split(/\//, $_date, 3);
|
||||||
|
(my $_firstname, my $_lastname) = split(/ /, $_name, 2);
|
||||||
|
my $membership = ($year - $_year) * 12;
|
||||||
|
|
||||||
|
print "RENEW: $_date ($membership), $_payment, $_name, $_email, $_hostname, $_server ($vm_name)\n";
|
||||||
|
printf $fh_email "MAIL FROM: <mischa\@openbsd.amsterdam>\n";
|
||||||
|
printf $fh_email "RCPT TO: <%s>\n", $_email;
|
||||||
|
printf $fh_email "DATA\n";
|
||||||
|
printf $fh_email "From: <mischa\@openbsd.amsterdam>\n";
|
||||||
|
printf $fh_email "To: <%s>\n", $_email;
|
||||||
|
printf $fh_email "Date: %s\n", $timestamp;
|
||||||
|
if ($week == 3) {
|
||||||
|
printf $fh_email "Subject: OpenBSD Amsterdam Renewal $year\n\n";
|
||||||
|
} else {
|
||||||
|
printf $fh_email "Subject: OpenBSD Amsterdam Renewal $year Reminder\n\n";
|
||||||
|
}
|
||||||
|
printf $fh_email "Hi %s,\n\n", $_firstname;
|
||||||
|
printf $fh_email "First and foremost, we thank you for your continued support!\n\n";
|
||||||
|
printf $fh_email "Can you believe that it's been $membership months since you started with\n";
|
||||||
|
printf $fh_email "your VM?\n\n";
|
||||||
|
printf $fh_email "Since that time, your support has enabled us to reach the following\n";
|
||||||
|
printf $fh_email "milestones:\n\n";
|
||||||
|
printf $fh_email "1) Donate €$total_donated to the OpenBSD Foundation\n";
|
||||||
|
printf $fh_email "2) Deploy $total_vms VMs\n";
|
||||||
|
printf $fh_email "3) Deploy $total_hosts hosts\n\n";
|
||||||
|
printf $fh_email "We really hope you have been happy with the service provided, if so,\n";
|
||||||
|
printf $fh_email "please consider renewing now. You can find all the options to renew at:\n\n";
|
||||||
|
printf $fh_email "https://openbsd.amsterdam/pay.html\n\n";
|
||||||
|
printf $fh_email "Your renewal fee for %s on %s this year is €%d.\n", $vm_name, $_server, $_payment;
|
||||||
|
printf $fh_email "For every renewal we will donate €15 to the OpenBSD Foundation.\n\n";
|
||||||
|
printf $fh_email "When you want to cancel your VM please let us know, when we don't\n";
|
||||||
|
if ($week == 1) {
|
||||||
|
printf $fh_email "hear from you within the next week we will remove your VM.\n\n";
|
||||||
|
} else {
|
||||||
|
printf $fh_email "hear from you within the next $week weeks we will remove your VM.\n\n";
|
||||||
|
}
|
||||||
|
printf $fh_email "Mischa\n\n";
|
||||||
|
printf $fh_email "--\n";
|
||||||
|
printf $fh_email "OpenBSD Amsterdam\n";
|
||||||
|
printf $fh_email "https://obsda.ms\n";
|
||||||
|
printf $fh_email "\r\n.\r\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf $fh_email "QUIT\n";
|
||||||
|
close $fh_email;
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to print all keys & values for debug purposes
|
||||||
|
sub debug_parse {
|
||||||
|
my %conf = %{$_[0]};
|
||||||
|
my %vms = %{$_[1]};
|
||||||
|
print "All VMs\n##\n";
|
||||||
|
for my $vm_name (sort keys %vms) {
|
||||||
|
my $_date = $vms{$vm_name}{'date'};
|
||||||
|
my $_payment = $vms{$vm_name}{'payment'};
|
||||||
|
my $_donated = $vms{$vm_name}{'donated'};
|
||||||
|
my $_name = $vms{$vm_name}{'name'};
|
||||||
|
my $_email = $vms{$vm_name}{'email'};
|
||||||
|
my $_hostname = $vms{$vm_name}{'hostname'};
|
||||||
|
print "$_date, $_payment, $_name, $_email, $_hostname, ($vm_name)\n";
|
||||||
|
}
|
||||||
|
print "##\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
# check if _deploy.conf exists in current working directory
|
||||||
|
my $dev = "/home/mischa/openbsd.amsterdam/deploy.pl";
|
||||||
|
my $prod = "/home/mischa";
|
||||||
|
my $dir;
|
||||||
|
my $debug;
|
||||||
|
my %conf;
|
||||||
|
my %vms;
|
||||||
|
if (-d "$dev") {
|
||||||
|
$dir = $dev;
|
||||||
|
$debug = 1;
|
||||||
|
} else {
|
||||||
|
$dir = $prod;
|
||||||
|
}
|
||||||
|
if (-e "$dir/_deploy.conf") {
|
||||||
|
%conf = get_variables('conf', "$dir/_deploy.conf");
|
||||||
|
} else {
|
||||||
|
printf "Unable to find config file in current directory (%s).\n", $dir;
|
||||||
|
printf "Create the config file _deploy.conf in %s.\n", $dir;
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
# parse all vm*.txt files in the VMS directory
|
||||||
|
my @files = glob "$conf{'conf'}{'VMS'}/*.txt";
|
||||||
|
%vms = get_variables('vms', @files);
|
||||||
|
|
||||||
|
# run all functions
|
||||||
|
if ($debug) { debug_parse(\%conf, \%vms); }
|
||||||
|
notify_renewal(\%conf, \%vms);
|
|
@ -0,0 +1,108 @@
|
||||||
|
#!/usr/bin/env perl
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019-2020 Mischa Peters <mischa @ openbsd.amsterdam>
|
||||||
|
#
|
||||||
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
# copyright notice and this permission notice appear in all copies.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
#
|
||||||
|
use 5.024;
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use autodie;
|
||||||
|
use Cwd qw(cwd);
|
||||||
|
use User::pwent;
|
||||||
|
|
||||||
|
# fuction to parse _deploy.conf and vm*.txt files
|
||||||
|
# all variables are stripped and added to either %vms or %conf
|
||||||
|
sub get_variables {
|
||||||
|
my ($hash_name, @files) = @_;
|
||||||
|
my %hash;
|
||||||
|
my $filename;
|
||||||
|
my $vm_name;
|
||||||
|
my $vm_number;
|
||||||
|
|
||||||
|
for my $file (@files) {
|
||||||
|
# When hash is 'vms' use the vm_name as key
|
||||||
|
# Otherwise use 'conf' as key
|
||||||
|
if ($hash_name eq "vms") {
|
||||||
|
($filename = $file) =~ s/.*\///;
|
||||||
|
($vm_name = $filename) =~ s/\.txt//;
|
||||||
|
($vm_number = $vm_name) =~ s/^vm//;
|
||||||
|
$hash{$vm_name}{'vm_number'} = $vm_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
open my $fh, "<", "$file";
|
||||||
|
while (my $row = <$fh>) {
|
||||||
|
next if ($row =~ /^\s*($|#)/);
|
||||||
|
chomp($row);
|
||||||
|
(my $key, my $val) = split(/=/, $row, 2);
|
||||||
|
if ($hash_name eq "vms") {
|
||||||
|
($hash{$vm_name}{$key} .= $val) =~ s/^"+|"+$//g;
|
||||||
|
} else {
|
||||||
|
($hash{$hash_name}{$key} .= $val) =~ s/^"+|"+$//g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close $fh;
|
||||||
|
}
|
||||||
|
return %hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to create accounts on the host for vmctl(8) access
|
||||||
|
sub change_accounts {
|
||||||
|
my %conf = %{$_[0]};
|
||||||
|
my %vms = %{$_[1]};
|
||||||
|
|
||||||
|
printf "useradd(8) creation:\n";
|
||||||
|
for my $vm_name (sort keys %vms) {
|
||||||
|
my $_instance = $vms{$vm_name}{'instance'} || $vm_name;
|
||||||
|
my $_owner = $vms{$vm_name}{'owner'} || $vms{$vm_name}{'username'};
|
||||||
|
|
||||||
|
my $jot_pass = qx(jot -rcs '' 20 43 125);
|
||||||
|
chomp($jot_pass);
|
||||||
|
my $encrypt_pass = qx(encrypt '${jot_pass}');
|
||||||
|
chomp($encrypt_pass);
|
||||||
|
my $output = qx(/usr/sbin/usermod -p '${encrypt_pass}' $_owner);
|
||||||
|
printf "%s - %s - %s\n", $_owner, $encrypt_pass, $jot_pass;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to print all keys & values for debug purposes
|
||||||
|
sub debug_parse {
|
||||||
|
my %conf = %{$_[0]};
|
||||||
|
my %vms = %{$_[1]};
|
||||||
|
|
||||||
|
for my $vm_name (sort keys %vms) {
|
||||||
|
for my $key (keys %{$vms{$vm_name}}) {
|
||||||
|
printf "VMS: %s %s = %s\n", $vm_name, $key, $vms{$vm_name}{$key};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# check if _deploy.conf exists in current working directory
|
||||||
|
my %conf;
|
||||||
|
my $dir = cwd;
|
||||||
|
if (-e "$dir/_deploy.conf") {
|
||||||
|
%conf = get_variables('conf', "$dir/_deploy.conf");
|
||||||
|
} else {
|
||||||
|
printf "Unable to find config file in current directory (%s).\n", $dir;
|
||||||
|
printf "Create the config file _deploy.conf in %s.\n", $dir;
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
# parse all vm*.txt files in the VMS directory
|
||||||
|
my %vms;
|
||||||
|
my @files = glob "$conf{'conf'}{'VMS'}/*.txt";
|
||||||
|
%vms = get_variables('vms', @files);
|
||||||
|
|
||||||
|
# run all functions
|
||||||
|
#debug_parse(\%conf, \%vms);
|
||||||
|
change_accounts(\%conf, \%vms);
|
|
@ -0,0 +1,104 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019 Mischa Peters <mischa @ openbsd.amsterdam>
|
||||||
|
#
|
||||||
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
# copyright notice and this permission notice appear in all copies.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
#
|
||||||
|
main () {
|
||||||
|
CONF_FILE="$PWD/_deploy.conf"
|
||||||
|
[ -f "$CONF_FILE" ] && . "$CONF_FILE"
|
||||||
|
|
||||||
|
file=${VMS}/$1
|
||||||
|
|
||||||
|
if [ -f "$file" ]; then
|
||||||
|
echo "reading $file"
|
||||||
|
. "$file"
|
||||||
|
backup_image "$file"
|
||||||
|
remove_user "$file"
|
||||||
|
move_file "$file"
|
||||||
|
else
|
||||||
|
echo "ERROR file doesn't exist: ${file}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_instance() {
|
||||||
|
# Check if the instance name exists, otherwise return filename as VM.
|
||||||
|
# Takes vm*.txt and instance
|
||||||
|
# prints either filename or instance variable
|
||||||
|
if test -z "$2"
|
||||||
|
then echo "$1" | sed "s@^$VMS@@;s@^/@@;s/\\.txt$//"
|
||||||
|
else echo "$2"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_owner() {
|
||||||
|
# Check if the owner name exists, otherwise returns username.
|
||||||
|
# Takes username and owner
|
||||||
|
# prints either owner or username
|
||||||
|
if test -z "$2"
|
||||||
|
then echo "$1"
|
||||||
|
else echo "$2"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_format() {
|
||||||
|
# Check if the image format exists, otherwise returns img.
|
||||||
|
# Takes format
|
||||||
|
# prints either format or img
|
||||||
|
if test -z "$1"
|
||||||
|
then echo "${FORMAT}"
|
||||||
|
else echo "$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
backup_image() {
|
||||||
|
filename=$1
|
||||||
|
_instance=$(check_instance "$filename" "$instance")
|
||||||
|
_format=$(check_format "$format")
|
||||||
|
if [ -f "${IMAGES}/${_instance}.${_format}" ]; then
|
||||||
|
mv ${IMAGES}/${_instance}.${_format} ${IMAGES}/${_instance}.${_format}-backup
|
||||||
|
echo "vmm(4)/vmd(8) files moved: ${IMAGES}/${_instance}.${_format} ${IMAGES}/${_instance}.${_format}-backup"
|
||||||
|
else
|
||||||
|
echo "ERROR vmm(4)/vmd(8) files moved: ${IMAGES}/${_instance}.${_format} doesn't exist"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_user() {
|
||||||
|
_owner=$(check_owner "$username" "$owner")
|
||||||
|
if [ -n "$_owner" ]; then
|
||||||
|
if grep -e "^${_owner}:" /etc/passwd > /dev/null; then
|
||||||
|
userdel -r "$_owner"
|
||||||
|
echo "userdel(8) removal: $_owner"
|
||||||
|
else
|
||||||
|
echo "ERROR userdel(8) removal: $_owner doesn't exist"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep -e "^${_owner}:" /etc/group > /dev/null; then
|
||||||
|
groupdel "$_owner"
|
||||||
|
echo "groupdel(8) removal: $_owner"
|
||||||
|
else
|
||||||
|
echo "ERROR groupdel(8) removal: $_owner doesn't exist"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
move_file() {
|
||||||
|
filename=$1
|
||||||
|
cp ${filename} ${filename}-backup
|
||||||
|
echo "cp(1): ${filename} ${filename}-backup"
|
||||||
|
mv ${filename} ${filename}.free
|
||||||
|
echo "mv(1): ${filename} ${filename}.free"
|
||||||
|
chown -R mischa:mischa ${filename}-backup ${filename}.free
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019 Mischa Peters <mischa @ openbsd.amsterdam>
|
||||||
|
#
|
||||||
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
# copyright notice and this permission notice appear in all copies.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
#
|
||||||
|
DEV="${HOME}/openbsd.amsterdam/deploy.pl"
|
||||||
|
PROD="${HOME}"
|
||||||
|
RELAY="mx"
|
||||||
|
|
||||||
|
if [ -d ${DEV} ]; then
|
||||||
|
. ${DEV}/_deploy.conf
|
||||||
|
elif [ -d ${PROD} ]; then
|
||||||
|
. ${PROD}/_deploy.conf
|
||||||
|
else
|
||||||
|
echo "Unable to find config file."
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
FILE="${TMPL}/email-renewal.txt"
|
||||||
|
[ ! -f ${FILE} ] && exit 1
|
||||||
|
|
||||||
|
LINES=$(wc -l ${FILE} | awk '{printf $1}')
|
||||||
|
[ ${LINES} == 2 ] && rm ${FILE} && exit 1
|
||||||
|
|
||||||
|
cat ${FILE} | while read; do sleep 0.2; echo ${REPLY}; done | nc ${RELAY} 25
|
||||||
|
mv ${FILE} ${FILE}-$(date +%Y%m%d)
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019 Mischa Peters <mischa @ openbsd.amsterdam>
|
||||||
|
#
|
||||||
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
# copyright notice and this permission notice appear in all copies.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
#
|
||||||
|
deploy.pl
|
||||||
|
rcctl restart dhcpd
|
||||||
|
vmctl reload
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
auto-deploy.exp $1
|
||||||
|
if [ $? ]; then
|
||||||
|
vmctl stop -f $1
|
||||||
|
fi
|
||||||
|
|
||||||
|
deploy.pl
|
||||||
|
rcctl restart dhcpd
|
||||||
|
vmctl reload
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
auto-start.exp $1
|
||||||
|
if [ $? ]; then
|
||||||
|
echo
|
||||||
|
echo "SUCCES! - deployed ${1}"
|
||||||
|
notify.pl deployed ${1}
|
||||||
|
fi
|
Loading…
Reference in New Issue