## nm-repair.awk ## ## Replace old UUID strings with propper UUIDs, making sure to refer to same IDs throughout file. ## This is for correcting the problem with knetworkmanager and ~/.kde/share/config/knetworkmanagerrc ## ## By: Mateo Obregon, obregonmateo at gmaildotcom, 11-Feb-2010 ## Copyright: GNU General Public License, Version 2 or later ################################### (/_/ && ! /_.*=/) { # for all lines with an UUID reference res=split($0, aa, /_/); # every 2nd string is an UUID for (ii=2; ii<=res; ii+=2) { if (split(aa[ii], ss, /]/)) { aa[ii]=ss[1]; # remove end "]" if uuid string contains it } id=aa[ii]; # old ID if (length(uuids[id]) == 0) { # check whether ID has been seen before ## if not, generate a new UUID "cat /proc/sys/kernel/random/uuid" | getline uuid; close("cat /proc/sys/kernel/random/uuid"); ####### alternatively: ## "uuidcdef -u" | getline uuid; ## close("uuidcdef -u"); uuids[id] = uuid; # and store it, referenced by old ID } else { uuid=uuids[id]; # if ID has new UUID, then use this } gsub(id, uuid, $0); # replace all occurrences of ID for UUID in current line } } ################################### { # for all lines ## check whether this line has a reference to an old ID for (id in uuids) { if (index($0, id)) { gsub(id, uuids[id], $0); # if so, replace all occurrences with its new UUID } } ## print all lines to STDOUT print $0; }