#!/usr/bin/perl
# clearcfkey, Boone, 09/22/08
# Forget old cfengine key for this machine
#
# Modifications:
# 09/22/08 Boone      Initial coding
# 02/01/13 Deming     Updated for preseed, changed exec to system, changed method for getting IPs
# End Modifications

# Misc variables

	$sshcmd = "/usr/bin/ssh";
        @sshargs =
        (
                "-o",
                "BatchMode=yes",
                "-o",
                "PreferredAuthentications=publickey",
                "-o",
                "StrictHostKeyChecking=no",
                "-i",
                "/etc/ssh/id_Rmrsh_rsa",
                "-l",
                "Rmrsh",
		"faihost.matrix.msu.edu"
        );
	$sshargs = join(" ", @sshargs);

# Get list of IPs

        $ifconfig="/sbin/ifconfig";
        @lines=qx|$ifconfig | or die("Can't get info from ifconfig: ".$!);

# DO THE CHANGE
	foreach(@lines)
	{
		if(/inet addr:([\d.]+)/)
		{
			$keypath = "/var/lib/cfengine2/ppkeys/root-" . $1 . ".pub";
			system($sshcmd, @sshargs, "test", "-f", $keypath, "&&", "rm", $keypath);
		}
	}

# Done

	exit(0);
