diff --git a/Makefile b/Makefile index 63084cb..83871d2 100644 --- a/Makefile +++ b/Makefile @@ -104,6 +104,27 @@ print-response-message-numbers: print-response-messages-without-comments: make -s print-response-messages | grep -vE '^[[:blank:]]+#' +MIGRATION_FILE_INIT ?= /tmp/dnsmanager-migration-init.txt +MIGRATION_FILE_INTERMEDIARY ?= /tmp/dnsmanager-migration-intermediary.txt +MIGRATION_FILE_TARGET ?= /tmp/dnsmanager-migration-target.txt +migrate: + # Format entries: one per line. + ./bin/format.awk < $(MIGRATION_FILE_INIT) |\ + ./bin/fix-last-element.awk |\ + # Remove 'activated' attribute. No longer relevant (never, actually). \ + sed 's/ \+activated \+=> \+0, \+//' |\ + sed 's/domain \+=> \+/"domain": /' |\ + sed 's/ \+login \+=> \+/"login": /' |\ + sed 's/", \+}/" }/' |\ + # Fix @ in logins. \ + sed 's/\\@/@/' |\ + # Remove obvious SQL hacks. \ + sed '/))))/d' |\ + sed '/: \+[0-9]\+,/d' |\ + # Remove all entries with accents. \ + grep -v '\\' > $(MIGRATION_FILE_INTERMEDIARY) + ./bin/migration-final.awk < $(MIGRATION_FILE_INTERMEDIARY) | sort -n > $(MIGRATION_FILE_TARGET) + wipe-db: rm -r $(DBDIR) diff --git a/bin/fix-last-element.awk b/bin/fix-last-element.awk new file mode 100755 index 0000000..d6d7c30 --- /dev/null +++ b/bin/fix-last-element.awk @@ -0,0 +1,22 @@ +#!/usr/bin/awk -f + +BEGIN { + data = "" +} + +/^\]/ { + gsub("},$","}",data) + print data + print + next +} + +/},$/ { + print data + data = $0 + next +} + +{ + data = $0 +} diff --git a/bin/format.awk b/bin/format.awk index 36338f6..ab5aa48 100755 --- a/bin/format.awk +++ b/bin/format.awk @@ -5,7 +5,7 @@ BEGIN { } /^\[/ || /^\]/ { - print "oups" + print next } diff --git a/bin/migration-final.awk b/bin/migration-final.awk new file mode 100755 index 0000000..27b1ac9 --- /dev/null +++ b/bin/migration-final.awk @@ -0,0 +1,27 @@ +#!/usr/bin/gawk -f + +/^\[/ || /^\]/ { + next +} + +{ + domain = $0 + login = $0 + gsub("^.+domain\": \"", "", domain) + gsub("\",\"login\": .+", "", domain) + gsub(".+\",\"login\": \"", "", login) + gsub("\" }.?$", "", login) + data[login][domain] = 1 +} + +END { + for ( login in data ) { + domains = "" + nb = 0 + for ( domain in data[login] ) { + nb += 1 + domains = (domains "\t" domain) + } + print nb, login, domains + } +}