Chinaunix首页 | 论坛 | 博客
  • 博客访问: 128217
  • 博文数量: 28
  • 博客积分: 2431
  • 博客等级: 大尉
  • 技术积分: 321
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-29 18:40
文章分类

全部博文(28)

文章存档

2011年(3)

2010年(6)

2009年(7)

2008年(12)

分类: LINUX

2008-12-08 17:21:10

这个脚本只要是刚安装完系统后使用的,我的环境是ubuntu8.04。主要功能:

1.替换软件源
2.设置IP,DNS等
3.禁止IPV6服务(暂时用不上)
4.修改localhost(将localhost化名为主机名,据说这个方法可以改善使用Ubuntu一段后,在GNOME中启动应用程序变慢的问题)
5.apt-get updata
6.安装我自己的软件包(软件列表在另一个sh脚本里,呵呵)

这个嘛,主要是方便自己的,有什么好的建议请说,呵呵!!

#!/usr/bin/perl -w

use File::Copy;
die "Permission denied:Perhaps need root\n" if `whoami`!~/root/;
$LOCK_EX=2;
$LOCK_UN=8;

##-----------following is setting-------------------------


#---------------replace the upgrade-sources----------

my $source_flat=0;
my $from="./setting/8.04/";
my $to="/etc/apt/sources.list";
my $name="sources.list";
chdir $from;
copy($name,$to)||die "can't copy file:$!\n";
print "setting upgrade-sources: done\n"&&$source_flat=1;


#-----------------------------------------------------


#---------------set the ip,DNS and so on..------------


my $dns_flat=0;
my $dns_file="/etc/resolv.conf";
my $text="#Generated by NetworkManager \n search 10.50.11.10\n nameserver 10.50.11.1\n";
open DNS,">",$dns_file||die "can't open $dns_file for write:$!\n";
flock(DNS,$LOCK_EX)||die "can't lock:$!\n"; #creat lock

print DNS $text;
flock(DNS,$LOCK_UN); #unlock

close(DNS);
print "setting DNS: done\n"&&$dns_flat=1;

my $ip_flat=0;
my $ip_file="/etc/network/interfaces";
$text="\nauto eth0
iface eth0 inet static
address 10.3.60.244
netmask 255.255.255.0
gateway 10.3.60.254
broadcast 10.3.60.255\n"
;
open IP,">>",$ip_file||die "can't open file:$!\n";
flock(IP,$LOCK_EX)||die "can't lock:$!\n"; #creat lock

print IP $text;
flock(IP,$LOCK_UN); #unlock

close(IP);
print "setting ip: done\n"&&$ip_flat=1;
print "restarting networking.....\n";


`/etc/init.d/networking restart`||die "networking restart failed\n";#make the setting effect

print "setting networking:done\n";

#-------------------------------------------------------


#---------------禁止IPV6---------------------------------


my $ipv6_flat=0;
print "stop the IPV6......\n";
my $ipv6="/etc/modprobe.d/aliases";
open FH,"<",$ipv6||die "can't open file:$!\n";
my @text=<FH>;
close(FH);
open IP,">",$ipv6||die "can't open file for write:$!\n";
flock(IP,$LOCK_EX)||die "can't lock file:$ipv6,$!\n"; #creat lock

foreach(@text)
{
    s/(alias net-pf-10) ipv6/$1 off #ipv6/;

    print IP;
}
flock(IP,$LOCK_UN); #unlock

close(IP);
print "stop the IPV6:done\n"&&$ipv6_flat=1;

#-----------------------------------------------------------


#------------------------localhost--------------------------

#将localhost化名为主机名,据说这个方法可以改善使用Ubuntu一段后,在GNOME中启动应用程序变慢的问题

my $host_flat=0;
my $host_file="/etc/hosts";
open FH,"<",$host_file||die "can't open file:$!\n";
my @tmp=<FH>;
close(FH);
my $hostname=`hostnema`;
open HOST,">",$host_file;
foreach(@tmp)
{
    s/(127.0.0.1 localhost)/$1 $hostname/;
    print HOST;
}
close(HOST);
print "setting localhost........done\n"&&$host_flat=1;

#------------------------------------------------------------






#---------------updata the system------------------------------------------


`apt-get updata`||warn "can't apt-get updata:$!\n";

#--------------------------------------------------------------------------


#----------------call install bash for install software----------------------


my $install_flat=0;
(!system "./install-all.sh"&&$install_flat=1)||die "can't call install-all.sh:$!\n";

#-------------------------------------------------------------------------------


#---------------------if all is done,creat a file for flag---------------------

#$source_flat $dns_flat $ip_flat ipv6_flat $host_flat $install_flat

&write_report;#


#------------------------write_report funtion----------------------------------

sub write_report
{
my $result_file="result";
open RES,">",$result_file||die "can't creat file:$!\n";
select(RES);
print "#this is a file for the result of 8.04-install-all.pl\n";
if($source_flat)
{
    print "upgrate-sources:replace success\n";
}
else
{
    print "upgrate-sources:replace failed\n";
}

if($dns_flat)
{
    print "DNS :success\n";
}
else
{
    print "DNS :failed\n";
}

if($ip_flat)
{
    print "ip:success\taddr:10.3.60.244\n";
}
else
{
    print "ip:failed\n";
}


if($ipv6_flat)

{
    print "stop IPV6 service:success\n";
}
else
{
    print "stop IPV6 service:failed\n";
}
if($host_flat)
{
    print "host:success\n" ;
}
else
{
    print "host:failed\n";
}

if($install_flat)
{
    print "install software:success\n" ;
}
else
{    
    print "install software:failed\n";
}
close RES;
select(STDOUT);
}
#---------------------------funtion End---------------------------


    











阅读(1195) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~