1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | !/usr/bin/perl use strict; # Some global variables declaration $::RETVAL; $::VERBOSE; $::distro_name = RedHatEL-Server $::repo_base_url = "http://172.20.3.27/data/RedHatEL-Server5.4-GA-x86_64/", $::repo_base_name = RedHatEL-Server5.4-GA-x86_64; $::NODE_RPM_LIST_FILE = "/var/opt/yum/rpmlist"; $::NODE_YUM_TMPL_DIR = "/var/opt/yum/tmpl"; $::NODE_YUM_CONF_DIR = "/var/opt/yum/config/"; $::NODE_YUM_CONF_FILE = "/var/opt/yum/config/yum.conf"; $::CREATEREPOCMD = "/usr/bin/createrepo"; $:IRNAME = "/usr/bin/dirname"; $::NODE_UPDATESWCMD_DIR = "/var/opt/bin/"; $::NODEUPDATESWCMD = "/var/opt/bin/updateSWorSys.pl"; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | sub createyumConf { my ($distro_name, $repo_base_url, $repo_base_name) = @_; my $yumconf_ref = { # keyword vaule '#DistroVerPkg#' => $distro_name =~ /SLES/ ? 'sles-release' : 'redhat-release', '#BaseName#'=> "$repo_base_name", '#BaseUrl#' => "file://$repo_base_url" }; if ( ! -d $::NODE_YUM_CONF_DIR ) { mkpath($::NODE_YUM_CONF_DIR, $::VERBOSE, 0755); } # 根据具体的参数,创建 yum 配置文件 substFile($::NODE_YUM_TMPL_DIR . "/yum.conf", "/var/opt/csm/yum/yum.conf", $yumconf_ref); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | Sub createRepo { my $yumConfile = @_; my $retVal = 0; if ($yumConfile eq "") { print "pls specify the yum configuration file.\n"; $retVal = 1; return $retVal; } my $yumconf = getConfig($yumConfile); delete $$yumconf{'main'}; my %repoHash; # Filter yum config hash and extract dirlist foreach my $section (keys %$yumconf) { foreach my $entry (keys %{ $$yumconf{$section} } ) { if ($entry eq "baseurl") { my $value = $$yumconf{$section}{$entry}; $value =~ s/file:\/\///g; if ($value =~ /yumrepo/) { chomp($value = runCmd("$:IRNAME $value",-1) ); $repoHash{$value}{output} = "$value/yumrepo"; } else { $repoHash{$value} = undef; } } } } my $repo_out; foreach my $repo (keys %repoHash) { $repo_out = undef; $repo_out = $repoHash{$repo}{output} || $repo_out; $retVal || = createRepoDB($repo, $repo_out); } return $retVal; } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |