#!/usr/bin/perl
# gather list of afp and nfs mounts
chomp (@mounts = `mount -t afpfs,nfs`);
# don't restart NFS (automount) unless we need to
$restart_NFS = 0;
# iterate across all lines of the 'mount' output
foreach $line ( @mounts ) {
    # use a backref to grab any white-space delimited string
    # that starts with /private
    $line =~ /(\/private\S*)/;
    $path = $1;
    if ($path) {
        # print the path to unmount, then forcibly unmount it
        print "$path\n";
        system("sudo umount -f $path");
        $restart_NFS = 1;
    }
}
# tear down and rebuild the automount processes
if ($restart_NFS) {
    system("sudo killall automount");
    system("sudo rm /var/run/NFS.StartupItem");
    system("sudo SystemStarter start NFS");
    # refresh disk arbitration for good measure?
    system("sudo disktool -r");
};

