### ### Copyright 2000-2007 University of Illinois Board of Trustees ### All rights reserved. ### ### RedHat.pm - RedHat module for psgconf ### ### Campus Information Technologies and Educational Services ### University of Illinois at Urbana-Champaign ### package PSGConf::Control::RedHat; use strict; use PSGConf::Action::GenerateFile::AppConfig; use PSGConf::Action::GenerateFile::EnvFile; use PSGConf::Action::RPMImportGPGKey; use PSGConf::Action::ModifyFile; use PSGConf::Data::Boolean; use PSGConf::Data::Hash; use PSGConf::Data::List; use PSGConf::Data::String; use PSGConf::Control::Packages qw(_add_pkgs); ############################################################################### ### decide() method ############################################################################### sub decide { my ($self, $psgconf) = @_; my ($key); return if (!$psgconf->data_obj('platform')->match('(-rhel-)|(-rhl-)|(-fc-)')); $psgconf->register_actions( PSGConf::Action::GenerateFile::EnvFile->new( 'name' => '/etc/sysconfig/autofsck', 'description' => 'Auto fsck config file', 'requires_reboot' => 1, 'vars' => { AUTOFSCK_DEF_CHECK => 'yes' } ) ); if ($psgconf->data_obj('rhn_enable')->equals('true')) { $psgconf->register_actions( PSGConf::Action::GenerateFile::EnvFile->new( name => '/etc/sysconfig/rhn/up2date', description => 'RHN configuration file', mode => 0600, vars => $psgconf->data_obj('rhn_config')->get() ), PSGConf::Action::ModifyFile->new( 'name' => '/etc/sysconfig/rhn/systemid', 'modify_func' => \&_modify_systemid, 'uid' => 0, 'gid' => 0, 'mode' => 0600 ) ); } if ($psgconf->data_obj('yum_enable')->equals('true')) { $psgconf->register_actions( PSGConf::Action::GenerateFile::AppConfig->new( name => '/etc/yum.conf', description => 'Yum configuration file', mode => 0644, stanza => 1, vars => $psgconf->data_obj('yum_config')->get() ) ); } if ($psgconf->data_obj('rhn_enable')->equals('true') || $psgconf->data_obj('yum_enable')->equals('true')) { foreach $key ( @{$psgconf->data_obj('gpg_keys')->get()} ) { $psgconf->register_actions( PSGConf::Action::RPMImportGPGKey->new( name => "GPG KeyID $key", key => $key, rpm_cmd => $psgconf->data_obj('pkg_rpm_cmd')->get(), gpg_cmd => $psgconf->data_obj('gpg_cmd')->get(), keyserver => $psgconf->data_obj('gpg_keyserver')->get() ) ); } } } ############################################################################### ### ModfileFile plugin to edit /etc/sysconfig/rhn/systemid ############################################################################### sub _modify_systemid { my ($action, $infh, $fh, $psgconf) = @_; my ($line, $in_profile_name); while ($line = <$infh>) { if ($line =~ m|^profile_name| ) { $in_profile_name = 1; } elsif ( $in_profile_name && $line =~ m|^.*| ) { $line = '' . $psgconf->data_obj('hostname')->get() . "\n"; $in_profile_name = 0; } print $fh $line; } return 1; } ############################################################################### ### policy methods ############################################################################### ### create RC script sub _policy_add_rc_scripts { my ($self, $psgconf) = @_; if ( $psgconf->data_obj('yum_enable')->equals('true') ) { $psgconf->data_obj('rc_scripts')->insert( { 'yum' => { 'state' => 'enable' }} ); } elsif ( $psgconf->data_obj('rhn_enable')->equals('true') ) { $psgconf->data_obj('rc_scripts')->insert( { 'rhnsd' => { 'state' => 'enable' }} ); } } sub _policy_add_packages { my ($self, $psgconf) = @_; if ( $psgconf->data_obj('yum_enable')->equals('true')) { $self->{enable} = 'yum_enable'; $self->{packages} = 'yum_packages'; } else { $self->{enable} = 'rhn_enable'; $self->{packages} = 'rhn_packages'; } $self->_add_pkgs($psgconf); } ############################################################################### ### Constructor ############################################################################### sub new { my ($class, $psgconf) = @_; my ($self); $self = {}; bless($self, $class); $self->{name} = 'RedHat'; $psgconf->register_data( rhn_enable => PSGConf::Data::Boolean->new( value => 'false' ), yum_enable => PSGConf::Data::Boolean->new( value => 'false' ), rhn_config => PSGConf::Data::Hash->new(), yum_config => PSGConf::Data::Hash->new(), pkg_up2date_cmd => PSGConf::Data::String->new( 'value_abspath' => 1, value => "/usr/sbin/up2date" ), pkg_yum_cmd => PSGConf::Data::String->new( 'value_abspath' => 1, value => "/usr/bin/yum" ), gpg_cmd => PSGConf::Data::String->new( 'value_abspath' => 1, value => "/usr/bin/gpg" ), gpg_keys => PSGConf::Data::List->new(), gpg_keyserver => PSGConf::Data::String->new( value => "hkp://subkeys.pgp.net" ), rhn_packages => PSGConf::Data::List->new(), yum_packages => PSGConf::Data::List->new() ); $psgconf->register_policy($self, redhat_add_packages => '_policy_add_packages', redhat_add_rc_scripts => '_policy_add_rc_scripts' ); return $self; } ############################################################################### ### documentation ############################################################################### 1; __END__ =head1 NAME PSGConf::Control::RedHat - psgconf control class for RedHat-specific configuration =head1 SYNOPSIS In F: Control PSGConf::Control::RedHat =head1 DESCRIPTION The B module provides a B control object for RedHat-specific configuration. It supports the following methods: =over 4 =item new() The constructor. Its parameter is a reference to the B object. It registers the following data objects: =over 4 =item I A B object indicating whether RHN should be configured. Defaults to no. =item I A B object indicating whether Yum should be configured. Defaults to no. =item I A B object containing the contents of the F file. =item I A B object containing the contents of the F file. =item I A B object that determines the location of the I command. Defaults to F. =item I A B object that determines what GPG Key server to fetch the keys from. Defaults to F. =item I A B object containing the GPG keys to trust when installing packages. =item I A B object containing the packages to install in support of RHN. =item I A B object containing the packages to install in support of Yum. =item I A B object that determines the location of the I command. The default is F. =item I A B object that determines the location of the I command. The default is F. =back The constructor also registers the following policy methods: =over 4 =item I If I is set, adds the I to the I. If I is set, adds the I to the I. =item I If I is set, enables the I startup script. If I is set, enables the I startup script. =back =item decide() =over 4 =item * Under systems other than RedHat, returns without doing anything. Otherwise, registers B action objects to create the F file. =item * Registers a B object to create F if I is set. =item * Registers a B object to create F if I is set. =item * Registers a B object to download and install all the keys listsed in F if either I or I is set. =item * Registers a B object to change the C in F if I is set. =back =back =head1 SEE ALSO Cup2date(8)E> Cyum(8)E> L L L L L L L L L L L L =cut