#!/bin/sh
# -*- perl -*-
# This code allows us to start perl from our path or an environment variable
# rather than hardcoding a path into the #! line.  It works from sh or csh.
(exit $?0) && eval 'exec ${QPERLQ-perl} -x $0 ${1+"$@"}'
if (! $?QPERLQ) setenv QPERLQ perl
exec $QPERLQ -x $0 $argv:q

#!/usr/local/bin/perl -w
#
# $Id: lanswitch,v 1.5 1998/11/29 17:45:54 ejb Exp $
# $Source: /home/ejb/scripts/aloo/RCS/lanswitch,v $
# $Author: ejb $
#

require 5.002;
use strict;

my $whoami = ($0 =~ m,([^/\\]*)$,) ? $1 : $0;
#my $dirname = ($0 =~ m,(.*)[/\\][^/\\]+$,) ? $1 : ".";

my @files = ("/etc/resolv.conf",
	     "/etc/krb5.conf",
	     "/etc/sysconfig/network",
	     "/etc/sysconfig/network-scripts/ifcfg-eth0",
	     "/etc/sendmail.cf"
	     );

&usage() if @ARGV > 1;
if (@ARGV == 0)
{
    system("ls -l " . join(' ', @files));
    exit 0;
}
die "$whoami: must be root to run this script\n" unless $< == 0;
my $suffix = shift(@ARGV);
my @newfiles = ();
my $okay = 1;
for (@files)
{
    my $new = "$_.$suffix";
    push(@newfiles, $new);
    if (! (((! (-e $_)) ||
	    (-l $_)) &&
	   (-f $new)))
    {
	$okay = 0;
    }
}
die "$whoami: invalid configuration\n" unless $okay;

my $i;
for ($i = 0; $i < scalar(@newfiles); ++$i)
{
    unlink $files[$i];
    symlink $newfiles[$i], $files[$i];
}

# Don't restart network here.  It's better to just cycle the network
# card or reboot.

# system("/etc/rc.d/init.d/network restart");

sub usage
{
    die "Usage: $whoami [configuration]\n";
}
