10 if ( /^\[(.+)\]$/ ) { $currentGroup = $1; next; };
11 # store all keys regarding Identities in the hash:
12 if ( $currentGroup =~ /^Identity/ ) {
13 ($key,$value) = split /=/;
15 $data{$currentGroup}{$key} = $value;
19 # We need to prevent this script from being run twice, since it would
20 # kill all identities then.
21 # Non-presence of the [Identity]IdentityList key is the best indiator:
22 unless ( defined( $data{'Identity'}{'IdentityList'} ) ) { exit; }
24 # first, delete all old groups:
25 foreach $group ( keys %data ) {
26 print "# DELETEGROUP [$group]\n";
29 # now, extract the list of valid identities (and their sequence):
30 $rawIdentityList = $data{'Identity'}{'IdentityList'};
31 # don't include the IdentityList anymore:
32 delete $data{'Identity'}{'IdentityList'};
33 # remove backslash-quoting:
34 $rawIdentityList =~ s/\\(.)/$1/g;
35 # split into a list at unquoted commas:
36 @identities = split /(?<!\\),/, $rawIdentityList;
37 # unquote individual items yet again:
38 for ( @identities ) { s/\\(.)/$1/g; }
39 # build the list of groups (this time incl. the default identity):
40 @groups = ( 'Identity', map { $_ = "Identity-$_"; } @identities );
41 # write out the groups, now named "Identity #n",
42 # with the same data and the same keys that the old groups had:
44 foreach $group (@groups) {
45 %groupData = %{$data{$group}};
46 print "[Identity #$n]\n";
47 foreach $key ( keys %groupData ) {
49 . $groupData{$key} . "\n";
53 # remember which one is default:
54 print "[General]\nDefault Identity=" . $data{'Identity'}{'Identity'} . "\n";