Switch to long format --verbose and --force flags

clean up debian packaging

update build docs, minor version bump

Pass --verbose and --force flags to upload script, remove --upload distinction
This commit is contained in:
Ben Charlton 2019-04-27 15:21:18 +01:00
parent cf6664d4d3
commit 5c24979273
8 changed files with 69 additions and 53 deletions

View file

@ -36,12 +36,12 @@ need to give Symbiosis your DNS password. To do this, put it in a file called
As root, run 'symbiosis-dns-generate --verbose --force' to regenerate the DNS As root, run 'symbiosis-dns-generate --verbose --force' to regenerate the DNS
records. These will be under records. These will be under
/srv/my-brilliant-site.com/config/dns/my-brillant-site.com.txt as usual, but /srv/my-brilliant-site.com/config/dns/my-brillant-site.com.txt as usual, but no
no longer in TinyDNS format. longer in TinyDNS format.
Again, as root, run 'symbiosis-dns-mythic -v -f' to force an upload to the DNS Again, as root, run 'symbiosis-dns-mythic --verbose --force' to force an upload
API in verbose mode. This will tell you if you have any template or auth to the DNS API in verbose mode. This will tell you if you have any template or
problems. auth problems.
These operations will be run automatically from cron in future, after any These operations will be run automatically from cron in future, after any
changes. changes.
@ -53,3 +53,9 @@ TODO
* Detect presence of NS records and skip them if the Mythic DNS template is not 'none' * Detect presence of NS records and skip them if the Mythic DNS template is not 'none'
* Make failures a bit more transparent. * Make failures a bit more transparent.
* Clean up some of the spurious template warnings. * Clean up some of the spurious template warnings.
Packaging
---------
* dch to update changlog.
* debuild -us -uc
* dh_clean to tidy up.

6
debian/changelog vendored
View file

@ -1,3 +1,9 @@
symbiosis-dns-mythic (0.11) stable; urgency=medium
* Switch to long --verbose and --force flags for consistency
-- Ben Charlton <ben@spod.cx> Sat, 27 Apr 2019 15:57:00 +0100
symbiosis-dns-mythic (0.1) stable; urgency=medium symbiosis-dns-mythic (0.1) stable; urgency=medium
* Initial release. * Initial release.

2
debian/copyright vendored
View file

@ -1,6 +1,6 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Symbiosis Upstream-Name: Symbiosis
Source: https://github.com/bcc/symbiosis-dns-mythic Source: https://gitlab.com/bcc/symbiosis-dns-mythic
Files: * Files: *

View file

@ -1 +0,0 @@
symbiosis-dns-mythic

2
debian/files vendored
View file

@ -1,2 +0,0 @@
symbiosis-dns-mythic_0.1_all.deb net extra
symbiosis-dns-mythic_0.1_amd64.buildinfo net extra

View file

@ -1,13 +0,0 @@
#!/bin/sh -e
NAME=symbiosis-dns-mythic
VERSION=$(sed 's/.*(\([^)]*\)).*/\1/;1q' debian/changelog)
n="$NAME-$VERSION"
t="$n.tar.gz"
cd ..
rm -f $t
ln -s ${NAME} $n
tar cfzh $t $n
rm $n
cd ${NAME}

View file

@ -18,7 +18,6 @@
# --template TEMPLATE Specify an alternative template file to read. # --template TEMPLATE Specify an alternative template file to read.
# #
# --force Force the re-creation of all DNS data. # --force Force the re-creation of all DNS data.
# --upload Force the upload of all DNS data.
# --help Show the help information for this script. # --help Show the help information for this script.
# --verbose Show debugging information. # --verbose Show debugging information.
# #
@ -48,11 +47,6 @@ force = false
help = false help = false
$VERBOSE = false $VERBOSE = false
#
# Do we need to re-upload the data?
#
upload=true
# #
# The root directory -- '/' by default. # The root directory -- '/' by default.
# #
@ -65,7 +59,6 @@ opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ], [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--sleep', '-s', GetoptLong::REQUIRED_ARGUMENT ], [ '--sleep', '-s', GetoptLong::REQUIRED_ARGUMENT ],
[ '--template', '-t', GetoptLong::REQUIRED_ARGUMENT ], [ '--template', '-t', GetoptLong::REQUIRED_ARGUMENT ],
[ '--upload', '-u', GetoptLong::NO_ARGUMENT ],
[ '--verbose', '-v', GetoptLong::NO_ARGUMENT ] [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ]
) )
@ -83,8 +76,6 @@ opts.each do |opt, arg|
root = arg root = arg
when '--force' when '--force'
force = true force = true
when '--upload'
upload = true
end end
end end
@ -226,12 +217,19 @@ end
begin begin
if upload
upload_script = "/usr/sbin/symbiosis-dns-mythic" upload_script = "/usr/sbin/symbiosis-dns-mythic"
fflag = ""
vflag = ""
if force
fflag = "--force"
end
if $VERBOSE
vflag = "--verbose"
end
verbose "Uploading using #{upload_script}" verbose "Uploading using #{upload_script}"
IO.popen("#{upload_script} 2>&1","r") do |io| IO.popen("#{upload_script} #{fflag} #{vflag} 2>&1","r") do |io|
while !io.eof? do while !io.eof? do
verbose io.readline verbose io.readline
end end
@ -241,9 +239,6 @@ begin
raise StandardError, "#{upload_script.inspect} failed." raise StandardError, "#{upload_script.inspect} failed."
end end
else
verbose "No need to upload as no changes in the data have been detected."
end
rescue StandardError => err rescue StandardError => err
warn "Unable to upload DNS data because #{err.to_s}" warn "Unable to upload DNS data because #{err.to_s}"
verbose "\t"+err.backtrace.join("\n\t") verbose "\t"+err.backtrace.join("\n\t")

View file

@ -2,14 +2,39 @@
use strict; use strict;
use WWW::Mechanize; use WWW::Mechanize;
use Getopt::Std; use Getopt::Long;
our ($opt_v, $opt_f);
getopts('vf');
my $domaindir = "/srv"; my $domaindir = "/srv";
my $url = 'https://dnsapi.mythic-beasts.com/'; my $url = 'https://dnsapi.mythic-beasts.com/';
sub HELP_MESSAGE {
print <<EOF;
Upload symbiosis DNS to Mythic Beasts DNS API.
Requires the domain API password to be present in /srv/example.com/config/dns/mbpassword
Flags:
--verbose Outputs a summary of actions when run.
--force Force an upload of the data.
EOF
}
our ($opt_v, $opt_f, $help);
GetOptions ("verbose" => \$opt_v,
"help" => \$help,
"force" => \$opt_f)
or die("Error in command line arguments\n");
if ($help) {
HELP_MESSAGE();
exit(0);
}
sub upload_dns($$$) { sub upload_dns($$$) {
my ($domain, $dnsfile, $password) = @_; my ($domain, $dnsfile, $password) = @_;