rel-eng/packages/spacewalk-setup | 2
spacewalk/setup/Makefile.PL | 6
spacewalk/setup/bin/cobbler-setup | 108 -----------
spacewalk/setup/bin/cobbler20-setup | 108 +++++++++++
spacewalk/setup/bin/spacewalk-setup | 88 ---------
spacewalk/setup/bin/spacewalk-setup-cobbler | 261 ++++++++++++++++++++++++++++
spacewalk/setup/share/cobbler/modules.conf | 1
spacewalk/setup/share/cobbler/settings | 5
spacewalk/setup/spacewalk-setup.spec | 12 +
9 files changed, 395 insertions(+), 196 deletions(-)
New commits:
commit 46ecb5b914911b9e775dbbd6f1363d7a5fe2b10a
Author: Milan Zazrivec <mzazrivec(a)redhat.com>
Date: Tue Apr 24 14:42:28 2012 +0200
Automatic commit of package [spacewalk-setup] release [1.8.7-1].
diff --git a/rel-eng/packages/spacewalk-setup b/rel-eng/packages/spacewalk-setup
index 26c1762..fe88fd8 100644
--- a/rel-eng/packages/spacewalk-setup
+++ b/rel-eng/packages/spacewalk-setup
@@ -1 +1 @@
-1.8.6-1 spacewalk/setup/
+1.8.7-1 spacewalk/setup/
diff --git a/spacewalk/setup/spacewalk-setup.spec b/spacewalk/setup/spacewalk-setup.spec
index 24ef3dd..e26192c 100644
--- a/spacewalk/setup/spacewalk-setup.spec
+++ b/spacewalk/setup/spacewalk-setup.spec
@@ -1,5 +1,5 @@
Name: spacewalk-setup
-Version: 1.8.6
+Version: 1.8.7
Release: 1%{?dist}
Summary: Initial setup tools for Red Hat Spacewalk
@@ -110,6 +110,10 @@ rm -rf %{buildroot}
%{_mandir}/man8/spacewalk-make-mount-points*
%changelog
+* Tue Apr 24 2012 Milan Zazrivec <mzazrivec(a)redhat.com> 1.8.7-1
+- spacewalk-setup-cobbler: script to configure cobbler for Spacewalk
+- Rename cobbler-setup to cobbler20-setup
+
* Tue Apr 17 2012 Jan Pazdziora 1.8.6-1
- Create deploy.sql on PostgreSQL as well (mzazrivec(a)redhat.com)
commit 87d4fed998c5b354bb74a6f024d15c4942e9b325
Author: Milan Zazrivec <mzazrivec(a)redhat.com>
Date: Tue Apr 24 14:21:07 2012 +0200
modify Makefile.PL for new cobbler setup layout
diff --git a/spacewalk/setup/Makefile.PL b/spacewalk/setup/Makefile.PL
index 9cae919..7bb7f09 100644
--- a/spacewalk/setup/Makefile.PL
+++ b/spacewalk/setup/Makefile.PL
@@ -8,12 +8,14 @@ WriteMakefile(
VERSION_FROM => 'lib/Spacewalk/Setup.pm',
ABSTRACT_FROM => 'lib/Spacewalk/Setup.pm',
PL_FILES => {},
- EXE_FILES => ['bin/spacewalk-setup',
'bin/cobbler20-setup', 'bin/spacewalk-make-mount-points'],
+ EXE_FILES => ['bin/spacewalk-setup',
'bin/cobbler20-setup', 'bin/spacewalk-make-mount-points',
+ 'bin/spacewalk-setup-cobbler'],
PREREQ_PM => {
'Test::More' => 0,
},
MAN1PODS => { 'lib/Spacewalk/Setup.pm' =>
'$(INST_MAN1DIR)/spacewalk-setup.$(MAN1EXT)',
- 'bin/cobbler-setup' =>
'$(INST_MAN1DIR)/cobbler20-setup.$(MAN1EXT)',
+ 'bin/cobbler20-setup' =>
'$(INST_MAN1DIR)/cobbler20-setup.$(MAN1EXT)',
+ 'bin/spacewalk-setup-cobbler' =>
'$(INST_MAN1DIR)/spacewalk-setup-cobbler.$(MAN1EXT)',
},
dist => { COMPRESS => 'gzip -9f', SUFFIX =>
'gz', },
clean => { FILES => 'Spacewalk-Setup-*' },
commit f467a5b2473f8da01544b115217d98653da828f5
Author: Milan Zazrivec <mzazrivec(a)redhat.com>
Date: Tue Apr 24 14:17:46 2012 +0200
spacewalk-setup-cobbler: script to configure cobbler for Spacewalk
diff --git a/spacewalk/setup/bin/spacewalk-setup b/spacewalk/setup/bin/spacewalk-setup
index a5edec7..c08f777 100755
--- a/spacewalk/setup/bin/spacewalk-setup
+++ b/spacewalk/setup/bin/spacewalk-setup
@@ -38,7 +38,8 @@ $DEBUG = 0;
use constant DEFAULT_CA_CERT_NAME =>
'RHN-ORG-TRUSTED-SSL-CERT';
-use constant COBBLER_COMMAND => 'cobbler-setup';
+use constant COBBLER_20_COMMAND => 'cobbler20-setup';
+use constant COBBLER_COMMAND => 'spacewalk-setup-cobbler';
my %opts = Spacewalk::Setup::parse_options();
@@ -236,89 +237,9 @@ sub setup_cobbler {
# newer versions of Cobbler don't ship the config templates
if ($cobbler_version =~ /2\.0/) {
# Cobbler 2.0 can use the old helper script
- system(COBBLER_COMMAND);
+ system(COBBLER_20_COMMAND);
} else {
- my $cobbler_dir = '/etc/cobbler';
- my $cobbler_settings_file = 'settings';
- my $cobbler_modules_file = 'modules.conf';
-
- my %cobbler_settings = (
- 'server' => $answers->{'hostname'},
- 'next_server' => $answers->{'hostname'},
- 'redhat_management_server' => $answers->{'hostname'},
- 'redhat_management_type' => 'site',
- 'pxe_just_once' => 1
- );
-
- Spacewalk::Setup::backup_file($cobbler_dir, $cobbler_settings_file);
-
- open(FILE, "<$cobbler_dir/$cobbler_settings_file");
-
- my @output_lines;
- while(<FILE>) {
- my $line = $_;
-
- foreach my $key (keys(%cobbler_settings)) {
- if ($line =~ /^$key ?:/) {
- $line = "$key: $cobbler_settings{$key}\n";
- last;
- }
- }
-
- push(@output_lines, $line);
- }
-
- close(FILE);
-
- # write the new file
- open(FILE, ">$cobbler_dir/$cobbler_settings_file");
- for my $line (@output_lines) {
- print FILE $line;
- }
- close(FILE);
-
- my %cobbler_modules = ( 'authentication' => 'authn_spacewalk' );
- Spacewalk::Setup::backup_file($cobbler_dir, $cobbler_modules_file);
- open(FILE, "<$cobbler_dir/$cobbler_modules_file");
-
- @output_lines = ();
- my $replace = 0;
- my $value = '';
- while(<FILE>) {
- my $line = $_;
-
- # look for the next 'module' line
- if ($replace) {
- if ($line =~ /^module ?=/) {
- $line = "module = $value\n";
- push(@output_lines, $line);
- $replace = 0;
- next;
- } else {
- next;
- }
- }
-
- # look for a section in the config
- foreach my $key (keys(%cobbler_modules)) {
- if ($line =~ /^\[$key\]/) {
- $replace = 1;
- $value = $cobbler_modules{$key};
- last;
- }
- }
-
- push(@output_lines, $line);
- }
-
- close(FILE);
-
- # write the new file
- open(FILE, ">$cobbler_dir/$cobbler_modules_file");
- for my $line (@output_lines) {
- print FILE $line;
- }
- close(FILE);
+ system(COBBLER_COMMAND . " --verbose --macros
hostname:$answers->{'hostname'}");
my $skip_rhnconf = 0;
open(FILE, "<" . Spacewalk::Setup::DEFAULT_RHN_CONF_LOCATION);
@@ -336,6 +257,7 @@ sub setup_cobbler {
print FILE "cobbler.host = " . $answers->{'hostname'} .
"\n";
close(FILE);
}
+ system("/usr/bin/cobbler sync");
}
Spacewalk::Setup::ask(
diff --git a/spacewalk/setup/bin/spacewalk-setup-cobbler
b/spacewalk/setup/bin/spacewalk-setup-cobbler
new file mode 100755
index 0000000..6fc9c00
--- /dev/null
+++ b/spacewalk/setup/bin/spacewalk-setup-cobbler
@@ -0,0 +1,261 @@
+#!/usr/bin/perl
+
+eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
+ if 0; # not running under some shell
+#
+# Copyright (c) 2012 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+
+use Sys::Hostname;
+use Getopt::Long;
+use Spacewalk::Setup;
+
+use strict 'refs';
+use warnings FATAL => 'all';;
+
+my $macros = '';
+my $verbose;
+my $help = 0;
+my %macros = ('hostname' => Sys::Hostname::hostname());
+
+my @ini_files = ('modules.conf');
+my @flat_files = ('settings');
+
+my $usage = <<EOHELP;
+Usage: $0 --help | --macros macros
+Options:
+ --help Print this help message
+ --verbose Verbose output
+ --macros Comma delimited list of macroname:macrovalue options
+EOHELP
+
+GetOptions("macros:s" => \$macros, "verbose" => \$verbose,
"help" => \$help) or die $usage;
+if ($help) {
+ print $usage;
+ exit 0;
+}
+
+if ($macros) {
+ foreach my $i (split(/,/, $macros, 0)) {
+ my ($key, $value) = split(/:/, $i, 3);
+ $macros{$key} = $value;
+ }
+}
+
+foreach my $configfile ('modules.conf', 'settings') {
+ my $cfpath= "/etc/cobbler/" . $configfile;
+ my @original_content = my @modified_content = @{ read_filelines($cfpath) };
+ my %cf_def = %{ read_config_definition($configfile, \%macros) };
+ my $i = 0;
+ my $section;
+
+ print "Processing $cfpath\n" if $verbose;
+ foreach my $line (@original_content) {
+ next if ($line =~ /^\s*#/);
+
+ $section = $1 if ($line =~ /^\[(.+)\]\s*$/);
+
+ if ($line =~ /^([^#=:]+?)\s*[:=]\s*(.+?)\s*$/) {
+ if (defined $section) {
+ if (defined $cf_def{$section}{$1} && not $cf_def{$section}{$1} eq $2) {
+ $modified_content[$i] = "## disabled by spacewalk-setup-cobbler ## " .
+ "$line$1 = $cf_def{$section}{$1}\n";
+ }
+ } else {
+ if (defined $cf_def{$1} && not $cf_def{$1} eq $2) {
+ $modified_content[$i] = "## disabled by spacewalk-setup-cobbler ## " .
+ "$line$1: $cf_def{$1}\n";
+ }
+ }
+ }
+ } continue {
+ ++$i;
+ }
+
+ if (!arrays_match(\@original_content, \@modified_content)) {
+ my @backup_cmd = ('/bin/cp', '-p', '--backup=numbered',
$cfpath, "$cfpath-swsave");
+ push @backup_cmd, '-v' if $verbose;
+ system(@backup_cmd);
+
+ local *FILE;
+ open FILE, ">$cfpath" or die "Error opening [$cfpath] for writing:
$!\n";
+ print FILE @modified_content;
+ close FILE;
+ }
+}
+
+sub read_filelines {
+ my $path = shift;
+ my @content;
+
+ local *CF_FILE;
+ open (CF_FILE, $path) or die "Error opening [$path] for reading: $!\n";
+ @content = <CF_FILE>;
+ close CF_FILE;
+
+ return \@content;
+}
+
+sub read_config_definition {
+ my $file = shift;
+ my %macros = %{(shift)};
+ my %definition;
+
+ foreach my $line (@{read_filelines(Spacewalk::Setup::SHARED_DIR .
"/cobbler/$file")}) {
+ chomp $line;
+ next if $line =~ /^\s*(#|$)/;
+ my @content = split / /, $line, 3;
+ my $value = $content[-1];
+
+ if ($value and $value =~ /^\@(.+)\(a)$/) {
+ $value = $macros{$1} if defined $macros{$1};
+ }
+
+ if (scalar(@content) == 2) {
+ $definition{$content[0]} = $value;
+ } elsif (scalar(@content) == 3) {
+ $definition{$content[0]}{$content[1]} = $value;
+ }
+ }
+
+ return \%definition;
+}
+
+sub arrays_match {
+ my @array1 = @{(shift)};
+ my @array2 = @{(shift)};
+
+ foreach my $i (@array1) {
+ return 0 if ! grep {$i eq $_} (@array2);
+ }
+
+ return 1;
+}
+
+1;
+
+=head1 NAME
+
+spacewalk-setup-cobbler - utility for configuring cobbler services to work with
+Spacewalk / Satellite
+
+=head1 SYNOPSIS
+
+B<spacewalk-setup-cobbler>
+[B<--help>]
+[B<--verbose>]
+[B<--macros macro1:macro1value,macro2:macro2value...>]
+
+=head1 OPTIONS
+
+=over 5
+
+=item B<--macros>
+
+Specify macro names and corresponding macro values that will be used for
+substitution for correct document modification. You can specify multiple
+macro:value pairs which you need to delimit by commas.
+
+Example: --macros
hostname:host.domain.org
+
+=item B<--verbose>
+
+Verbose script operation.
+
+=item B<--help>
+
+Print help message.
+
+=back
+
+=head1 DESCRIPTION
+
+B<spacewalk-setup-cobbler> is a utility for configuring cobbler to work
+with Spacewalk / Satellite. The script uses template documents to modify
+default / existing cobbler configuration.
+
+Ordinarily, spacewalk-setup-cobbler is called by spacewalk-setup(1) during
+initial Spacewalk / Satellite configuration or upgrade.
+
+The workflow of the script is:
+
+=over 5
+
+=item
+
+For each of the cobbler configuration files, the script reads appropriate
+template file.
+
+=item
+
+Substitutes macros as found in template files with expanded values.
+
+=item
+
+Reads particular cobbler configuration files and substitutes default / existing
+values with values from template files.
+
+=item
+
+Resulting configuration files are written out while the original files are backed up.
+
+=back
+
+=head1 TEMPLATE FILES
+
+Basename of a template files must be the same as the basename of
+the corresponding configuration file.
+
+A template file for an INI-style configuration file (such as
+/etc/cobbler/modules.conf) has the following format:
+
+C<section parameter value>
+
+A template file for a key: value type of configuration file (such as
+/etc/cobbler/settings) has the following format:
+
+C<parameter value>
+
+In both cases, string enclosed in '@' signs (e.g. @hostname@) denotes a macro
+name rather than an actual value.
+
+=head1 MACROS
+
+Currently, the only recognized macro is B<hostname>. If not specified on
+command line, the hostname will be determined automatically.
+
+=head1 FILES
+
+Template files used for modification of existing cobbler configuration files:
+
+F</usr/share/spacewalk/setup/cobbler/modules.conf>
+
+F</usr/share/spacewalk/setup/cobbler/settings>
+
+Cobbler configuration files modified by spacewalk-setup-cobbler:
+
+F</etc/cobbler/modules.conf>
+
+F</etc/cobbler/settings>
+
+=head1 SEE ALSO
+
+B<spacewalk-setup>(1) - Spacewalk setup program
+
+B<cobbler>(1) - Cobbler manual page
+
+=head1 AUTHORS
+
+Milan Zazrivec
+
+=cut
diff --git a/spacewalk/setup/share/cobbler/modules.conf
b/spacewalk/setup/share/cobbler/modules.conf
new file mode 100644
index 0000000..0f13ead
--- /dev/null
+++ b/spacewalk/setup/share/cobbler/modules.conf
@@ -0,0 +1 @@
+authentication module authn_spacewalk
diff --git a/spacewalk/setup/share/cobbler/settings
b/spacewalk/setup/share/cobbler/settings
new file mode 100644
index 0000000..42f311a
--- /dev/null
+++ b/spacewalk/setup/share/cobbler/settings
@@ -0,0 +1,5 @@
+next_server @hostname@
+pxe_just_once 1
+redhat_management_type "site"
+redhat_management_server @hostname@
+server @hostname@
diff --git a/spacewalk/setup/spacewalk-setup.spec b/spacewalk/setup/spacewalk-setup.spec
index 50bdffe..24ef3dd 100644
--- a/spacewalk/setup/spacewalk-setup.spec
+++ b/spacewalk/setup/spacewalk-setup.spec
@@ -72,6 +72,8 @@ install -d -m 755 %{buildroot}/%{_datadir}/spacewalk/setup/defaults.d/
install -d -m 755 %{buildroot}/%{_datadir}/spacewalk/setup/upgrade
install -m 0755 share/upgrade/* %{buildroot}/%{_datadir}/spacewalk/setup/upgrade
install -m 0644 share/defaults.d/defaults.conf
%{buildroot}/%{_datadir}/spacewalk/setup/defaults.d/
+install -d -m 755 %{buildroot}/%{_datadir}/spacewalk/setup/cobbler
+install -m 0644 share/cobbler/* %{buildroot}/%{_datadir}/spacewalk/setup/cobbler/
# Oracle specific stuff, possible candidate for sub-package down the road:
install -d -m 755 %{buildroot}/%{_datadir}/spacewalk/setup/oracle/
@@ -84,6 +86,7 @@ install -d -m 755 %{buildroot}/%{_var}/spacewalk
mkdir -p $RPM_BUILD_ROOT%{_mandir}/man8
/usr/bin/pod2man --section=8 $RPM_BUILD_ROOT/%{_bindir}/spacewalk-make-mount-points |
gzip > $RPM_BUILD_ROOT%{_mandir}/man8/spacewalk-make-mount-points.8.gz
+/usr/bin/pod2man --section=1 $RPM_BUILD_ROOT/%{_bindir}/spacewalk-setup-cobbler | gzip
> $RPM_BUILD_ROOT%{_mandir}/man1/spacewalk-setup-cobbler.1.gz
%check
make test
@@ -99,6 +102,7 @@ rm -rf %{buildroot}
%{perl_vendorlib}/*
%{_bindir}/spacewalk-setup
%{_bindir}/spacewalk-make-mount-points
+%{_bindir}/spacewalk-setup-cobbler
%{_bindir}/cobbler20-setup
%{_mandir}/man[13]/*.[13]*
%{_datadir}/spacewalk/*
commit b876b9d0e1fdb186a2e758a880e38e086735fca3
Author: Milan Zazrivec <mzazrivec(a)redhat.com>
Date: Tue Apr 24 13:51:43 2012 +0200
Rename cobbler-setup to cobbler20-setup
This is left in case one would need to configure cobbler v2.0.
diff --git a/spacewalk/setup/Makefile.PL b/spacewalk/setup/Makefile.PL
index b0b8061..9cae919 100644
--- a/spacewalk/setup/Makefile.PL
+++ b/spacewalk/setup/Makefile.PL
@@ -8,12 +8,12 @@ WriteMakefile(
VERSION_FROM => 'lib/Spacewalk/Setup.pm',
ABSTRACT_FROM => 'lib/Spacewalk/Setup.pm',
PL_FILES => {},
- EXE_FILES => ['bin/spacewalk-setup',
'bin/cobbler-setup', 'bin/spacewalk-make-mount-points'],
+ EXE_FILES => ['bin/spacewalk-setup',
'bin/cobbler20-setup', 'bin/spacewalk-make-mount-points'],
PREREQ_PM => {
'Test::More' => 0,
},
MAN1PODS => { 'lib/Spacewalk/Setup.pm' =>
'$(INST_MAN1DIR)/spacewalk-setup.$(MAN1EXT)',
- 'bin/cobbler-setup' =>
'$(INST_MAN1DIR)/cobbler-setup.$(MAN1EXT)',
+ 'bin/cobbler-setup' =>
'$(INST_MAN1DIR)/cobbler20-setup.$(MAN1EXT)',
},
dist => { COMPRESS => 'gzip -9f', SUFFIX =>
'gz', },
clean => { FILES => 'Spacewalk-Setup-*' },
diff --git a/spacewalk/setup/bin/cobbler-setup b/spacewalk/setup/bin/cobbler-setup
deleted file mode 100755
index e8ba1ce..0000000
--- a/spacewalk/setup/bin/cobbler-setup
+++ /dev/null
@@ -1,108 +0,0 @@
-#!/usr/bin/python
-from yaml import load
-from Cheetah.Template import Template
-from socket import gethostbyname, gethostname
-import shutil
-from os.path import exists, join, dirname, basename, isdir, isfile
-from os import system, chmod
-import sys
-import re
-
-from spacewalk.common import rhnConfig
-
-TEMPLATES_DIR = '/usr/share/cobbler/installer_templates'
-MODULES_TEMPLATE = join(TEMPLATES_DIR, 'modules.conf.template')
-SETTINGS_TEMPLATE = join(TEMPLATES_DIR, 'settings.template')
-DEFAULTS = join(TEMPLATES_DIR, 'defaults')
-
-CONFIG_DIR = '/etc/cobbler/'
-MODULES = join(CONFIG_DIR, 'modules.conf')
-SETTINGS = join(CONFIG_DIR, 'settings')
-
-TEMP_MODULES = '/tmp/modules.conf'
-TEMP_SETTINGS = '/tmp/settings'
-
-def loadFile(fl):
- return load(open(fl).read())
-
-def copy(src, dest):
- if exists(dest):
- if isfile(dest):
- shutil.copy(dest, dest + ".old")
- elif isdir(dest) and isfile(src) and exists(join(dest, basename(src))):
- shutil.copy(join(dest,basename(src)), join(dest,basename(src)) +
".old")
- shutil.copy(src, dest)
-
-def ask_yes_no(question, default_val = None):
- if default_val and default_val.lower() == 'y':
- default_val = 'y'
- default_q = '[Y/n]'
- else:
- default_val = 'n'
- default_q = '[y/N]'
-
- ans = raw_input(question + " " + default_q + "?")
- if not ans:
- return default_val == 'y'
-
- return ans.lower() == 'y'
-
-def gen_template(template, answers, output):
- t = Template(file=template, searchList=answers)
- open(output,"w").write(t.respond())
-
-def main():
- answers = dict(loadFile(DEFAULTS))
- answers['server'] = gethostname()
- answers['next_server'] = answers['server']
- answers['redhat_management_server'] = answers['server']
- answers['redhat_management_type'] = 'site'
- answers['authn_module'] = 'authn_spacewalk'
- answers['pxe_once'] = '1'
- gen_template(SETTINGS_TEMPLATE, answers, TEMP_SETTINGS)
- gen_template(MODULES_TEMPLATE, answers, TEMP_MODULES)
- copy(TEMP_SETTINGS, SETTINGS)
- chmod(SETTINGS, 0644)
- copy(TEMP_MODULES, MODULES)
- chmod(MODULES, 0644)
- m = re.compile(r"^cobbler\.host\s*=\s*", re.MULTILINE)
-
- conf_lines = open(rhnConfig._CONFIG_FILE).read()
- if not m.search(conf_lines):
- system ("echo 'cobbler.host = %s' >> %s " %
(answers['server'],
- rhnConfig._CONFIG_FILE))
- system("cobbler sync")
-
-
-if __name__=="__main__":
- main()
-
-
-"""
-
-=head1 NAME
-
-cobbler-setup
-
-=head1 SYNOPSIS
-
- cobbler-setup
-
-=head1 DESCRIPTION
-
-The B<cobbler-setup> program generates configuration files for cobbler
-in F</etc/cobbler>, based on templates in
-F</usr/share/cobbler/installer_templates>.
-
-The tool is generally called automatically by Spacewalk's
-B<spacewalk-setup>.
-
-=back
-
-=head1 SEE ALSO
-
-spacewalk-setup(1)
-
-=cut
-
-"""
diff --git a/spacewalk/setup/bin/cobbler20-setup b/spacewalk/setup/bin/cobbler20-setup
new file mode 100755
index 0000000..e8ba1ce
--- /dev/null
+++ b/spacewalk/setup/bin/cobbler20-setup
@@ -0,0 +1,108 @@
+#!/usr/bin/python
+from yaml import load
+from Cheetah.Template import Template
+from socket import gethostbyname, gethostname
+import shutil
+from os.path import exists, join, dirname, basename, isdir, isfile
+from os import system, chmod
+import sys
+import re
+
+from spacewalk.common import rhnConfig
+
+TEMPLATES_DIR = '/usr/share/cobbler/installer_templates'
+MODULES_TEMPLATE = join(TEMPLATES_DIR, 'modules.conf.template')
+SETTINGS_TEMPLATE = join(TEMPLATES_DIR, 'settings.template')
+DEFAULTS = join(TEMPLATES_DIR, 'defaults')
+
+CONFIG_DIR = '/etc/cobbler/'
+MODULES = join(CONFIG_DIR, 'modules.conf')
+SETTINGS = join(CONFIG_DIR, 'settings')
+
+TEMP_MODULES = '/tmp/modules.conf'
+TEMP_SETTINGS = '/tmp/settings'
+
+def loadFile(fl):
+ return load(open(fl).read())
+
+def copy(src, dest):
+ if exists(dest):
+ if isfile(dest):
+ shutil.copy(dest, dest + ".old")
+ elif isdir(dest) and isfile(src) and exists(join(dest, basename(src))):
+ shutil.copy(join(dest,basename(src)), join(dest,basename(src)) +
".old")
+ shutil.copy(src, dest)
+
+def ask_yes_no(question, default_val = None):
+ if default_val and default_val.lower() == 'y':
+ default_val = 'y'
+ default_q = '[Y/n]'
+ else:
+ default_val = 'n'
+ default_q = '[y/N]'
+
+ ans = raw_input(question + " " + default_q + "?")
+ if not ans:
+ return default_val == 'y'
+
+ return ans.lower() == 'y'
+
+def gen_template(template, answers, output):
+ t = Template(file=template, searchList=answers)
+ open(output,"w").write(t.respond())
+
+def main():
+ answers = dict(loadFile(DEFAULTS))
+ answers['server'] = gethostname()
+ answers['next_server'] = answers['server']
+ answers['redhat_management_server'] = answers['server']
+ answers['redhat_management_type'] = 'site'
+ answers['authn_module'] = 'authn_spacewalk'
+ answers['pxe_once'] = '1'
+ gen_template(SETTINGS_TEMPLATE, answers, TEMP_SETTINGS)
+ gen_template(MODULES_TEMPLATE, answers, TEMP_MODULES)
+ copy(TEMP_SETTINGS, SETTINGS)
+ chmod(SETTINGS, 0644)
+ copy(TEMP_MODULES, MODULES)
+ chmod(MODULES, 0644)
+ m = re.compile(r"^cobbler\.host\s*=\s*", re.MULTILINE)
+
+ conf_lines = open(rhnConfig._CONFIG_FILE).read()
+ if not m.search(conf_lines):
+ system ("echo 'cobbler.host = %s' >> %s " %
(answers['server'],
+ rhnConfig._CONFIG_FILE))
+ system("cobbler sync")
+
+
+if __name__=="__main__":
+ main()
+
+
+"""
+
+=head1 NAME
+
+cobbler-setup
+
+=head1 SYNOPSIS
+
+ cobbler-setup
+
+=head1 DESCRIPTION
+
+The B<cobbler-setup> program generates configuration files for cobbler
+in F</etc/cobbler>, based on templates in
+F</usr/share/cobbler/installer_templates>.
+
+The tool is generally called automatically by Spacewalk's
+B<spacewalk-setup>.
+
+=back
+
+=head1 SEE ALSO
+
+spacewalk-setup(1)
+
+=cut
+
+"""
diff --git a/spacewalk/setup/spacewalk-setup.spec b/spacewalk/setup/spacewalk-setup.spec
index 112064d..50bdffe 100644
--- a/spacewalk/setup/spacewalk-setup.spec
+++ b/spacewalk/setup/spacewalk-setup.spec
@@ -99,7 +99,7 @@ rm -rf %{buildroot}
%{perl_vendorlib}/*
%{_bindir}/spacewalk-setup
%{_bindir}/spacewalk-make-mount-points
-%{_bindir}/cobbler-setup
+%{_bindir}/cobbler20-setup
%{_mandir}/man[13]/*.[13]*
%{_datadir}/spacewalk/*
%attr(755, apache, root) %{_var}/spacewalk