#!/opt/bin/perl
#
# presort_alias_entries
#
# This script is designed to go through the GASH aliases_info
# file and sort the entries in group email aliases.
#
# GASH (v1.03f and after) sorts group email alias entries
# when the group aliases are modified, but this script
# is needed to pre-sort group aliases so that they will
# all appear sorted, rather than only ones that a recent
# version of GASH has modified.
#
# If you create your aliases_info file with GASH v1.03f or
# later, all group aliases will be sorted as they are
# created and modified, so you don't need to run this
# script.

open(INPUT, "<aliases_info") || die "crud";
open(OUTPUT, ">aliases_info.sorted") || die "dang";

while (<INPUT>) {
	if (!/^:/) {
	   print OUTPUT $_;
	   next;
	}
	s/\n//;  # remove new line
	@fields = split(/:/, $_);
	@entries = split(/, /, $fields[3]);
	@entries = sort @entries;
	printf OUTPUT ":%s:%s:%s\n", $fields[1], $fields[2],join(', ', @entries);
}
close(INPUT);
close(OUTPUT);
