diff --git a/Makefile b/Makefile index 2e97fde..0a30d66 100644 --- a/Makefile +++ b/Makefile @@ -78,26 +78,6 @@ print-response-messages:; cat src/responses/*.cr | ./bin/get-message print-response-message-numbers:; make -s print-response-messages | grep -E "^[0-9]" | sort -n print-response-messages-no-comments:; make -s print-response-messages | grep -vE '^[[:blank:]]+#' -# format: nb-domains login domain1 domain2 domain3 -MIGRATION_FILE_TARGET = /tmp/dnsmanagerd-migration -SQLDB = /tmp/usrdb -POWERDNS_ZONEDIR = /var/powerdns -BINDDIR = /tmp/DATA-dnsmanagerd/bind9-zones -$(MIGRATION_FILE_TARGET):; ./bin/sql-to-migration-format.awk < $(SQLDB) > $(MIGRATION_FILE_TARGET) -run-migration-client:; ./bin/dnsmanager-client admin migration-script $(MIGRATION_FILE_TARGET) $(LOGIN) -migration-file: $(MIGRATION_FILE_TARGET) -copy-old-zones: ; cd $(BINDDIR) && for i in * ; do cp -v /tmp/rndczones/$$i . ; done -/tmp/rndczones: - @echo "you forgot to get a copy of old bind zones here: /tmp/rndczones" - exit 1 -powerdns-create-zonedir: - -mkdir -p $(POWERDNS_ZONEDIR) - cp -v $(BINDDIR)/* $(POWERDNS_ZONEDIR) -powerdns-add-zones: powerdns-create-zonedir - cd $(POWERDNS_ZONEDIR) && for i in *; do pdns_control bind-add-zone $$i $(POWERDNS_ZONEDIR)/$$i; done -migration: build-client migration-file run-migration-client run-client-genzones copy-old-zones - @echo "next as root: make powerdns-add-zones" - doc: crystal docs src/main.cr src/client.cr lib/authd/src/client.cr @@ -113,3 +93,5 @@ wipe-db: release: make build-server OPTS="--release --progress --no-debug" + +-include migration.mk diff --git a/bin/sql-to-migration-format.awk b/bin/sql-to-migration-format.awk index caacb6e..7c2d5e9 100755 --- a/bin/sql-to-migration-format.awk +++ b/bin/sql-to-migration-format.awk @@ -1,5 +1,10 @@ #!/usr/bin/awk -f +# The input file format should be: +# login password domain +# +# (the "password" field won't actually be used) + BEGIN { OFS = "\t" } diff --git a/migration.mk b/migration.mk new file mode 100644 index 0000000..167a8d7 --- /dev/null +++ b/migration.mk @@ -0,0 +1,62 @@ +# This is the migration makefile. +# +# WHAT IS NEEDED FOR THE MIGRATION: +# +# - $(SQLDB): a dump of the SQL database (format: login password domain) +# - $(OLDBINDDIR): directory with old Bind9 zone files +# +# HOW MIGRATION WORKS, STEP BY STEP (`migration` rule): +# +# 1. build-client -> build bin/dnsmanager-client +# 2. migration-file -> generate $(MIGRATION_FILE_TARGET) +# 3. run-migration-client -> create users and attribute domains +# 4. run-client-genzones -> generate Bind9 zone files with dnsmanagerd +# those files will (mostly) be replaced by the old migrated Bind9 zone files +# 5. copy-old-zones -> copies the old Bind9 zone files where dnsmanagerd just produced its Bind9 zone files +# +# AFTER THE `migration` RULE: `powerdns-add-zones` as root +# This will run `pdns_control bind-add-zone domain zonefile` for every zone file in $(POWERDNS_ZONEDIR). +# Then the different zones should be served by powerdns. + + +# Migration input file, format: login password domain +SQLDB ?= /tmp/usrdb + +# Migration final file format: nb-domains login domain1 domain2 domain3 +MIGRATION_FILE_TARGET ?= /tmp/dnsmanagerd-migration + +# Old Bind9 migrated files. +OLDBINDDIR ?= /tmp/rndczones + +# Directory where Bind9 zone files are generated by dnsmanagerd. +BINDDIR ?= /tmp/DATA-dnsmanagerd/bind9-zones + +# Where powerdns reads Bind9 zone files. +POWERDNS_ZONEDIR ?= /var/powerdns + +$(MIGRATION_FILE_TARGET): + ./bin/sql-to-migration-format.awk < $(SQLDB) > $(MIGRATION_FILE_TARGET) + +run-migration-client: + ./bin/dnsmanager-client admin migration-script $(MIGRATION_FILE_TARGET) $(LOGIN) + +copy-old-zones: + cd $(BINDDIR) && for i in * ; do cp -v $(OLDBINDDIR)/$$i . ; done + +$(OLDBINDDIR): + @echo "you forgot to get a copy of old bind zones here: $(OLDBINDDIR)" + exit 1 + +# A nice rule for the command-line. +migration-file: $(MIGRATION_FILE_TARGET) + +migration: build-client migration-file run-migration-client run-client-genzones copy-old-zones + @echo "next as root: make powerdns-add-zones" + +# POWERDNS RULES +powerdns-create-zonedir: + -mkdir -p $(POWERDNS_ZONEDIR) + cp -v $(BINDDIR)/* $(POWERDNS_ZONEDIR) + +powerdns-add-zones: powerdns-create-zonedir + cd $(POWERDNS_ZONEDIR) && for i in *; do pdns_control bind-add-zone $$i $(POWERDNS_ZONEDIR)/$$i; done