From d24431934e2303a575ab8343e838ab33d9b4a746 Mon Sep 17 00:00:00 2001 From: mellor Date: Thu, 1 Nov 2012 17:22:53 +0000 Subject: [PATCH] initial checkin of xCAT-buildkit rpm git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@14202 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- buildcore.sh | 2 +- xCAT-buildkit/LICENSE.html | 326 +++ xCAT-buildkit/bin/buildkit | 1996 +++++++++++++++++ xCAT-buildkit/lib/perl/xCAT/BuildKitUtils.pm | 752 +++++++ .../xcat/kits/kit_template/buildkit.conf | 189 ++ .../other_files/sample/exclude.lst | 0 .../other_files/sample/kitdeployparams.lst | 0 .../plugins/sample/imageprofile.pm | 175 ++ .../kit_template/plugins/sample/nodemgmt.pm | 251 +++ .../kits/kit_template/scripts/sample/post.sh | 3 + .../kit_template/scripts/sample/postboot.sh | 3 + .../kit_template/scripts/sample/postun.sh | 3 + .../kit_template/scripts/sample/postup.sh | 3 + .../kits/kit_template/scripts/sample/pre.sh | 3 + .../kits/kit_template/scripts/sample/preun.sh | 3 + .../kits/kit_template/scripts/sample/preup.sh | 3 + .../sample/pkg1/pkg1-1-1.noarch.rpm | Bin 0 -> 3212 bytes .../source_packages/sample/pkg2/pkg2.spec | 76 + .../sample/pkg2/pkg2/cfg/pkg2.cfg | 3 + .../sample/pkg2/pkg2/files/pkg2.file1 | 1 + .../sample/pkg2/pkg2/files/pkg2.file2 | 2 + .../source_packages/sample/pkg3/pkg3.spec | 76 + .../source_packages/sample/pkg3/pkg3.tar.gz | Bin 0 -> 271 bytes .../sample/pkg4/pkg4-1-1.src.rpm | Bin 0 -> 2516 bytes .../xcat/kits/kitcomponent.spec.template | 48 + xCAT-buildkit/xCAT-buildkit.spec | 93 + xCAT-buildkit/xCAT-buildkit.spec.broken | 86 + 27 files changed, 4096 insertions(+), 1 deletion(-) create mode 100644 xCAT-buildkit/LICENSE.html create mode 100755 xCAT-buildkit/bin/buildkit create mode 100644 xCAT-buildkit/lib/perl/xCAT/BuildKitUtils.pm create mode 100644 xCAT-buildkit/share/xcat/kits/kit_template/buildkit.conf create mode 100644 xCAT-buildkit/share/xcat/kits/kit_template/other_files/sample/exclude.lst create mode 100644 xCAT-buildkit/share/xcat/kits/kit_template/other_files/sample/kitdeployparams.lst create mode 100644 xCAT-buildkit/share/xcat/kits/kit_template/plugins/sample/imageprofile.pm create mode 100644 xCAT-buildkit/share/xcat/kits/kit_template/plugins/sample/nodemgmt.pm create mode 100755 xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/post.sh create mode 100755 xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/postboot.sh create mode 100755 xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/postun.sh create mode 100755 xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/postup.sh create mode 100755 xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/pre.sh create mode 100755 xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/preun.sh create mode 100755 xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/preup.sh create mode 100644 xCAT-buildkit/share/xcat/kits/kit_template/source_packages/sample/pkg1/pkg1-1-1.noarch.rpm create mode 100644 xCAT-buildkit/share/xcat/kits/kit_template/source_packages/sample/pkg2/pkg2.spec create mode 100644 xCAT-buildkit/share/xcat/kits/kit_template/source_packages/sample/pkg2/pkg2/cfg/pkg2.cfg create mode 100644 xCAT-buildkit/share/xcat/kits/kit_template/source_packages/sample/pkg2/pkg2/files/pkg2.file1 create mode 100644 xCAT-buildkit/share/xcat/kits/kit_template/source_packages/sample/pkg2/pkg2/files/pkg2.file2 create mode 100644 xCAT-buildkit/share/xcat/kits/kit_template/source_packages/sample/pkg3/pkg3.spec create mode 100644 xCAT-buildkit/share/xcat/kits/kit_template/source_packages/sample/pkg3/pkg3.tar.gz create mode 100644 xCAT-buildkit/share/xcat/kits/kit_template/source_packages/sample/pkg4/pkg4-1-1.src.rpm create mode 100644 xCAT-buildkit/share/xcat/kits/kitcomponent.spec.template create mode 100644 xCAT-buildkit/xCAT-buildkit.spec create mode 100644 xCAT-buildkit/xCAT-buildkit.spec.broken diff --git a/buildcore.sh b/buildcore.sh index 9858f94e2..3e9abba78 100755 --- a/buildcore.sh +++ b/buildcore.sh @@ -174,7 +174,7 @@ if [ "$OSNAME" = "AIX" ]; then fi # Build the rest of the noarch rpms -for rpmname in xCAT-client xCAT-server xCAT-IBMhpc xCAT-rmc xCAT-UI xCAT-test; do +for rpmname in xCAT-client xCAT-server xCAT-IBMhpc xCAT-rmc xCAT-UI xCAT-test xCAT-build; do if $GREP $rpmname $SVNUP || [ "$BUILDALL" == 1 ]; then UPLOAD=1 if [ "$EMBED" = "zvm" -a "$rpmname" != "xCAT-server" -a "$rpmname" != "xCAT-UI" ]; then continue; fi # for embedded envs only need to build server special diff --git a/xCAT-buildkit/LICENSE.html b/xCAT-buildkit/LICENSE.html new file mode 100644 index 000000000..83d0eebb0 --- /dev/null +++ b/xCAT-buildkit/LICENSE.html @@ -0,0 +1,326 @@ + + + + + + + +Eclipse Public License - Version 1.0 + + + + + + +
+ +

Eclipse Public License - v 1.0 +

+ +

THE ACCOMPANYING PROGRAM IS PROVIDED UNDER +THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, +REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE +OF THIS AGREEMENT.

+ +

1. DEFINITIONS

+ +

"Contribution" means:

+ +

a) +in the case of the initial Contributor, the initial code and documentation +distributed under this Agreement, and
+b) in the case of each subsequent Contributor:

+ +

i) +changes to the Program, and

+ +

ii) +additions to the Program;

+ +

where +such changes and/or additions to the Program originate from and are distributed +by that particular Contributor. A Contribution 'originates' from a Contributor +if it was added to the Program by such Contributor itself or anyone acting on +such Contributor's behalf. Contributions do not include additions to the +Program which: (i) are separate modules of software distributed in conjunction +with the Program under their own license agreement, and (ii) are not derivative +works of the Program.

+ +

"Contributor" means any person or +entity that distributes the Program.

+ +

"Licensed Patents " mean patent +claims licensable by a Contributor which are necessarily infringed by the use +or sale of its Contribution alone or when combined with the Program.

+ +

"Program" means the Contributions +distributed in accordance with this Agreement.

+ +

"Recipient" means anyone who +receives the Program under this Agreement, including all Contributors.

+ +

2. GRANT OF RIGHTS

+ +

a) +Subject to the terms of this Agreement, each Contributor hereby grants Recipient +a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly +display, publicly perform, distribute and sublicense the Contribution of such +Contributor, if any, and such derivative works, in source code and object code +form.

+ +

b) +Subject to the terms of this Agreement, each Contributor hereby grants +Recipient a non-exclusive, worldwide, royalty-free +patent license under Licensed Patents to make, use, sell, offer to sell, import +and otherwise transfer the Contribution of such Contributor, if any, in source +code and object code form. This patent license shall apply to the combination +of the Contribution and the Program if, at the time the Contribution is added +by the Contributor, such addition of the Contribution causes such combination +to be covered by the Licensed Patents. The patent license shall not apply to +any other combinations which include the Contribution. No hardware per se is +licensed hereunder.

+ +

c) +Recipient understands that although each Contributor grants the licenses to its +Contributions set forth herein, no assurances are provided by any Contributor +that the Program does not infringe the patent or other intellectual property +rights of any other entity. Each Contributor disclaims any liability to Recipient +for claims brought by any other entity based on infringement of intellectual +property rights or otherwise. As a condition to exercising the rights and +licenses granted hereunder, each Recipient hereby assumes sole responsibility +to secure any other intellectual property rights needed, if any. For example, +if a third party patent license is required to allow Recipient to distribute +the Program, it is Recipient's responsibility to acquire that license before +distributing the Program.

+ +

d) +Each Contributor represents that to its knowledge it has sufficient copyright +rights in its Contribution, if any, to grant the copyright license set forth in +this Agreement.

+ +

3. REQUIREMENTS

+ +

A Contributor may choose to distribute the +Program in object code form under its own license agreement, provided that: +

+ +

a) +it complies with the terms and conditions of this Agreement; and

+ +

b) +its license agreement:

+ +

i) +effectively disclaims on behalf of all Contributors all warranties and +conditions, express and implied, including warranties or conditions of title +and non-infringement, and implied warranties or conditions of merchantability +and fitness for a particular purpose;

+ +

ii) +effectively excludes on behalf of all Contributors all liability for damages, +including direct, indirect, special, incidental and consequential damages, such +as lost profits;

+ +

iii) +states that any provisions which differ from this Agreement are offered by that +Contributor alone and not by any other party; and

+ +

iv) +states that source code for the Program is available from such Contributor, and +informs licensees how to obtain it in a reasonable manner on or through a +medium customarily used for software exchange.

+ +

When the Program is made available in source +code form:

+ +

a) +it must be made available under this Agreement; and

+ +

b) a +copy of this Agreement must be included with each copy of the Program.

+ +

Contributors may not remove or alter any +copyright notices contained within the Program.

+ +

Each Contributor must identify itself as the +originator of its Contribution, if any, in a manner that reasonably allows +subsequent Recipients to identify the originator of the Contribution.

+ +

4. COMMERCIAL DISTRIBUTION

+ +

Commercial distributors of software may +accept certain responsibilities with respect to end users, business partners +and the like. While this license is intended to facilitate the commercial use +of the Program, the Contributor who includes the Program in a commercial +product offering should do so in a manner which does not create potential +liability for other Contributors. Therefore, if a Contributor includes the +Program in a commercial product offering, such Contributor ("Commercial +Contributor") hereby agrees to defend and indemnify every other +Contributor ("Indemnified Contributor") against any losses, damages and +costs (collectively "Losses") arising from claims, lawsuits and other +legal actions brought by a third party against the Indemnified Contributor to +the extent caused by the acts or omissions of such Commercial Contributor in +connection with its distribution of the Program in a commercial product +offering. The obligations in this section do not apply to any claims or Losses +relating to any actual or alleged intellectual property infringement. In order +to qualify, an Indemnified Contributor must: a) promptly notify the Commercial +Contributor in writing of such claim, and b) allow the Commercial Contributor +to control, and cooperate with the Commercial Contributor in, the defense and +any related settlement negotiations. The Indemnified Contributor may participate +in any such claim at its own expense.

+ +

For example, a Contributor might include the +Program in a commercial product offering, Product X. That Contributor is then a +Commercial Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance claims and +warranties are such Commercial Contributor's responsibility alone. Under this +section, the Commercial Contributor would have to defend claims against the +other Contributors related to those performance claims and warranties, and if a +court requires any other Contributor to pay any damages as a result, the +Commercial Contributor must pay those damages.

+ +

5. NO WARRANTY

+ +

EXCEPT AS EXPRESSLY SET FORTH IN THIS +AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT +WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, +WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, +MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely +responsible for determining the appropriateness of using and distributing the +Program and assumes all risks associated with its exercise of rights under this +Agreement , including but not limited to the risks and costs of program errors, +compliance with applicable laws, damage to or loss of data, programs or +equipment, and unavailability or interruption of operations.

+ +

6. DISCLAIMER OF LIABILITY

+ +

EXCEPT AS EXPRESSLY SET FORTH IN THIS +AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF +THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF +THE POSSIBILITY OF SUCH DAMAGES.

+ +

7. GENERAL

+ +

If any provision of this Agreement is invalid +or unenforceable under applicable law, it shall not affect the validity or +enforceability of the remainder of the terms of this Agreement, and without +further action by the parties hereto, such provision shall be reformed to the +minimum extent necessary to make such provision valid and enforceable.

+ +

If Recipient institutes patent litigation +against any entity (including a cross-claim or counterclaim in a lawsuit) +alleging that the Program itself (excluding combinations of the Program with +other software or hardware) infringes such Recipient's patent(s), then such +Recipient's rights granted under Section 2(b) shall terminate as of the date +such litigation is filed.

+ +

All Recipient's rights under this Agreement +shall terminate if it fails to comply with any of the material terms or +conditions of this Agreement and does not cure such failure in a reasonable +period of time after becoming aware of such noncompliance. If all Recipient's +rights under this Agreement terminate, Recipient agrees to cease use and +distribution of the Program as soon as reasonably practicable. However, +Recipient's obligations under this Agreement and any licenses granted by +Recipient relating to the Program shall continue and survive.

+ +

Everyone is permitted to copy and distribute +copies of this Agreement, but in order to avoid inconsistency the Agreement is +copyrighted and may only be modified in the following manner. The Agreement +Steward reserves the right to publish new versions (including revisions) of +this Agreement from time to time. No one other than the Agreement Steward has +the right to modify this Agreement. The Eclipse Foundation is the initial +Agreement Steward. The Eclipse Foundation may assign the responsibility to +serve as the Agreement Steward to a suitable separate entity. Each new version +of the Agreement will be given a distinguishing version number. The Program +(including Contributions) may always be distributed subject to the version of +the Agreement under which it was received. In addition, after a new version of +the Agreement is published, Contributor may elect to distribute the Program +(including its Contributions) under the new version. Except as expressly stated +in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to +the intellectual property of any Contributor under this Agreement, whether +expressly, by implication, estoppel or otherwise. All rights in the Program not +expressly granted under this Agreement are reserved.

+ +

This Agreement is governed by the laws of the +State of New York and the intellectual property laws of the United States of +America. No party to this Agreement will bring a legal action under this +Agreement more than one year after the cause of action arose. Each party waives +its rights to a jury trial in any resulting litigation.

+ +

 

+ +
+ + + + diff --git a/xCAT-buildkit/bin/buildkit b/xCAT-buildkit/bin/buildkit new file mode 100755 index 000000000..a1df32e22 --- /dev/null +++ b/xCAT-buildkit/bin/buildkit @@ -0,0 +1,1996 @@ +#!/usr/bin/env perl +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +# + +#----------------------------------------------------------------------------- + +=head1 buildkit + + xCAT/PCM Kit Build utilities + + usage: buildkit [-h|-v] [command [-V]] + + This tool is used to create and build a new Kit. + + The options are: + -h - Provide usage info. + -v - Provide the version info. + command - Several commands are supported. See the list below. + -V - Verbose mode. Outputs additional debug messages. + + Supported commands: + create - creates a new Kit with the specified basename + chkconfig - checks the Kit build file + buildrepo - builds the specified Kit package repository + listrepo - lists the Kit package repositories in the Kit + build file, and their build status + cleanrepo - deletes the build files for the specified Kit + package repository + cleanrepo all - deletes the build files for all Kit package + repositories + buildtar - builds the Kit tarfile + cleantar - deletes the Kit deployment directory and Kit + cleanall - equivalent to buildrepo cleanrepo all and + buildrepo cleantar + +This script is designed to run on a non-xCAT system so that Kits can be +built on any product build machine. + +=cut + +BEGIN +{ + $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat'; + $::XCATDIR = $ENV{'XCATDIR'} ? $ENV{'XCATDIR'} : '/etc/xcat'; + $::XCATSHARE = $::XCATROOT.'/share/xcat'; +} + +if ($^O =~ /^aix/i) { + print "ERROR - buildkit is not supported on AIX \n"; + exit 1; +# if AIX - make sure we include perl 5.8.2 in INC path. +# Needed to find perl dependencies shipped in deps tarball. +# unshift(@INC, qw(/usr/opt/perl5/lib/5.8.2/aix-thread-multi /usr/opt/perl5/lib/5.8.2 /usr/opt/perl5/lib/site_perl/5.8.2/aix-thread-multi /usr/opt/perl5/lib/site_perl/5.8.2)); +} + +use lib "$::XCATROOT/lib/perl"; +require xCAT::Version; +require xCAT::BuildKitUtils; +use Getopt::Long; +use Expect; +use Socket; +use strict; +use Cwd; +use File::Path; +use File::Basename; + + +#----------------------------------------------------------------------------- +# Main + +$::progname = "buildkit"; +$::buildkit_conf = "buildkit.conf"; +$::kit_conf = "kit.conf"; +$::workdir = cwd(); +$::full_buildkit_conf = $::workdir."/".$::buildkit_conf; +$::build_dir = $::workdir."/build"; +$::deploy_dir = $::build_dir; #kitname appended by validate_bldkitconf routine +%::buildkit_def = ( + kit => { basename => { + description=>'The kit base name (e.g., kit-lsf)', + value_desc=>'Must be: Generic Name String', + mandatory=>1, + cp_to_kitconfig=>1}, + desc => { + description=>'The kit description', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>1}, + version => { + description=>'The kit version (e.g., 9.0)', + value_desc=>'Must be: Generic Name String', + mandatory=>1, + cp_to_kitconfig=>1}, + ostype => { + description=>'The kit OS type (e.g., Linux)', + value_desc=>'Must be: OS Type String', + mandatory=>1, + cp_to_kitconfig=>1}, + isinternal=> { + description=>'Flag to say if this Kit is used for internal use only. It is only used for information purposes.', + value_desc=>'Must be: empty string or boolean string', + mandatory=>0, + cp_to_kitconfig=>1}, + kitdeployparams=> { + description=>'The path to the Kit Deployment Parameters file.', + value_desc=>'Must be: empty string or relative path string', + mandatory=>0, + base_dir=>'other_files', + cp_to_kitconfig=>2} }, # 2 = rename with KIT_KITNAME_ on cp + kitrepo => {kitrepoid => { + description=>'The Kit Package Repository ID. (e.g., rhels-6.2-x86_64)', + value_desc=>'Must be: Generic Name String, unique in kit', + mandatory=>1, + cp_to_kitconfig=>0}, + osbasename => { + description=>'The OS distro base name (e.g., rhels)', + value_desc=>'Must be OS Name String', + mandatory=>1, + cp_to_kitconfig=>1}, + osmajorversion => { + description=>'The OS distro major version (e.g., 6)', + value_desc=>'Must be Generic Number String', + mandatory=>1, + cp_to_kitconfig=>1}, + osminorversion => { + description=>'The OS distro minor version (e.g., 3)', + value_desc=>'Must be Generic Number String', + mandatory=>0, + cp_to_kitconfig=>1}, + osarch => { + description=>'The OS distro architecture (e.g., x86_64)', + value_desc=>'Must be OS Arch String', + mandatory=>1, + cp_to_kitconfig=>1}, + compat_osbasenames => { + description=>'Comma-separated list of compatible OS base names. ', + value_desc=>'Must be Empty String or list of OS Name Strings', + mandatory=>0, + cp_to_kitconfig=>1} }, + kitcomponent => {basename => { + description=>'The component name. It is used as the meta-package name.', + value_desc=>'any string', + mandatory=>1, + cp_to_kitconfig=>1}, + desc => { + description=>'The component description. The description is added to the meta-package.', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>1}, + version => { + description=>'The component version (e.g., 9.0). It is used as the meta-package version.', + value_desc=>'any string', + mandatory=>1, + cp_to_kitconfig=>1}, + release => { + description=>'The component release number (e.g., 1). It is used as the meta-package release number.', + value_desc=>'any string', + mandatory=>1, + cp_to_kitconfig=>1}, + serverroles => { + description=>'tbd', + value_desc=>'any string', + mandatory=>1, + cp_to_kitconfig=>1}, + kitrepoid => { + description=>'tbd', + value_desc=>'any string', + mandatory=>1, + cp_to_kitconfig=>0}, + kitcompdeps => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>1}, + ospkgdeps => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>0}, + kitpkgdeps => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>1}, + non_native_pkgs => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>0}, + driverpacks => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>1}, + exlist => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + base_dir=>'other_files', + cp_to_kitconfig=>2}, + preinstall => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>0}, + postinstall => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>0}, + preuninstall => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>0}, + postuninstall => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>0}, + preupgrade => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>0}, + postupgrade => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>0}, + postbootscripts => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + base_dir=>'scripts', + cp_to_kitconfig=>2} }, + kitpackage => {filename => { + description=>'tbd', + value_desc=>'any string', + mandatory=>1, + cp_to_kitconfig=>0}, + kitrepoid => { + description=>'tbd', + value_desc=>'any string', + mandatory=>1, + cp_to_kitconfig=>0}, + rpm_spec => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>0}, + rpm_srcdir => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>0}, + rpm_srctarball => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>0}, + rpm_srpm => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>0}, + rpm_prebuiltdir => { + description=>'tbd', + value_desc=>'any string', + mandatory=>0, + cp_to_kitconfig=>0}} +); + + +my $args = join ' ', @ARGV; +$::command = "$0 $args"; +Getopt::Long::Configure("bundling"); +$Getopt::Long::ignorecase = 0; + +# parse the options +if ( + !GetOptions( + 'h|help' => \$::HELP, + 'v|version' => \$::VERSION, + 'V|verbose' => \$::VERBOSE, + ) + ) +{ + &usage; + exit(1); +} + +# display the usage if -h or --help is specified +if ($::HELP) +{ + &usage; + exit(0); +} + +# display the version statement if -v or --version is specified +if ($::VERSION) +{ + my $version = xCAT::Version->Version(); + print "$version \n"; + exit 0; +} + +my $arg=shift(@ARGV); +if ( ! $arg ) { + &usage; + exit (0); +} + +while ($arg) { + my $command = $arg; + $command =~ tr/A-Z/a-z/; # convert to lowercase + if ( $command eq 'create' ) { + $::KIT_CREATE=shift(@ARGV); + if ( ! $::KIT_CREATE ) { + print "kit basename not specified for buildkit create command \n"; + &usage; + exit 1; + } + } elsif ( $command eq 'chkconfig' ) { + $::KIT_CHKCONFIG=1; + } elsif ( $command eq 'buildrepo' ) { + $::KIT_BUILDREPO=shift(@ARGV); + if ( ! $::KIT_BUILDREPO ) { + print "kit package repository name not specified for buildkit buildrepo command \n"; + &usage; + exit 1; + } + } elsif ( $command eq 'listrepo' ) { + $::KIT_LISTREPO=1; + } elsif ( $command eq 'cleanrepo' ) { + $::KIT_CLEANREPO=shift(@ARGV); + if ( ! $::KIT_CLEANREPO ) { + print "kit package repository name not specified for buildkit cleanrepo command \n"; + &usage; + exit 1; + } + } elsif ( $command eq 'buildtar' ) { + $::KIT_BUILDTAR=1; + } elsif ( $command eq 'cleantar' ) { + $::KIT_CLEANTAR=1; + } elsif ( $command eq 'cleanall' ) { + $::KIT_CLEANALL=1; + } else { + print "buildkit command $arg not recognized \n"; + &usage; + exit (1); + } + $arg=shift(@ARGV); +} + +my $rc = 0; +if ( $::KIT_CREATE ) { + $rc = &kit_create; +} +if ( $::KIT_CHKCONFIG ) { + unless ($rc = &kit_chkconfig) { + print "No errors were found in Kit Build File $::full_buildkit_conf. \n"; + } +} +if ( $::KIT_BUILDREPO ) { + unless ($rc = &kit_chkconfig) { $rc = &kit_buildrepo; } +} +if ( $::KIT_LISTREPO ) { + unless ($rc = &kit_chkconfig) { $rc = &kit_listrepo; } +} +if ( $::KIT_CLEANREPO ) { + unless ($rc = &kit_chkconfig) { $rc = &kit_cleanrepo; } +} +if ( $::KIT_BUILDTAR ) { + unless ($rc = &kit_chkconfig) { $rc = &kit_buildtar; } +} +if ( $::KIT_CLEANTAR ) { + unless ($rc = &kit_chkconfig) { $rc = &kit_cleantar; } +} +if ( $::KIT_CLEANALL ) { + unless ($rc = &kit_chkconfig) { $rc = &kit_cleanall; } +} + + + +exit $rc; + +##################################### +# subroutines +##################################### + +#----------------------------------------------------------------------------- + +=head3 usage + + Displays message for -h option + +=cut + +#----------------------------------------------------------------------------- + +sub usage +{ + print " + usage: buildkit [-h|-v] [command [-V]] + + This tool is used to create and build a new Kit. + + The options are: + -h - Provide usage info. + -v - Provide the version info. + command - Several commands are supported. See the list below. + -V - Verbose mode. Outputs additional debug messages. + + Supported commands: + create - creates a new Kit with the specified basename + chkconfig - checks the Kit build file + listrepo - lists the Kit package repositories in the Kit + build file, and their build status + buildrepo - builds the specified Kit package repository + cleanrepo - deletes the build files for the specified Kit + package repository + cleanrepo all - deletes the build files for all Kit package + repositories + buildtar - builds the Kit tarfile + cleantar - deletes the Kit deployment directory and Kit + tarfile \n"; + +} + +#----------------------------------------------------------------------------- + +=head3 kit_create + + buildkit create + +=cut + +#----------------------------------------------------------------------------- + +sub kit_create + +{ + # create Kit directory in pwd + my $kitname=$::KIT_CREATE; + my $kitdir=$::workdir."/$kitname"; + if ( -d $kitdir ) { + print "Another directory alredy exists with the name $kitname in the current working directory. Not able to create new Kit directory $kitdir. \n"; + exit 1; + } + if ( ! mkdir($kitdir) ) { + print "Error creating Kit directory $kitdir. Verify that the current user has write privileges in the current working directory. \n"; + exit 1; + } + + # Recursive copy the shipped template directory to the Kit directory + if ( system("cp -fRp $::XCATSHARE/kits/kit_template/* $kitdir") ) { + # non-zero return from system call + print "Error copying sample Kit template files from $::XCAT_SHARE/kits/kit_template to $kitdir \n"; + exit 1; + } + + if (&edit_bldkitconf($kitdir."/".$::buildkit_conf,$kitname)) { + exit 1; + } + + print "Kit template for $kitname created in $kitdir directory \n"; +} + +#----------------------------------------------------------------------------- + +=head3 kit_chkconfig + + buildkit chkconfig + +=cut + +#----------------------------------------------------------------------------- + +sub kit_chkconfig + +{ + my $bldkitconf = $::full_buildkit_conf; + + my $chkrc = &load_bldkitconf($bldkitconf); + if ( $chkrc != 0 ) { return 1; }; + + $chkrc = &validate_bldkitconf(); + if ( $chkrc != 0 ) { return 1; }; + + return 0; +} + +#----------------------------------------------------------------------------- + +=head3 kit_buildrepo + + buildkit buildrepo + +=cut + +#----------------------------------------------------------------------------- + +sub kit_buildrepo + +{ + + my $rc = 0; + my $repoid = $::KIT_BUILDREPO; + $repoid =~ s/\s+//g; + my $repodir = $::build_dir."/kit_repodir"; + my $srcdir = $::workdir."/source_packages/"; + + # find the repo + my $found = 0; + foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) { + if ( $kr->{kitrepoid} eq $repoid ) { + $found = 1; + if ( &validate_os($kr)) { + print "The buildrepo operation will continue, but errors may occur. You may need to run this command on a host with the same OS.\n"; + } + $repodir .= "/$kr->{kitreponame}"; + last; + } + } + if (! $found) { + print "The specified Kit Package Repository \"$repoid\" does not exist in the Kit Build File. \n"; + return 1; + } + + # Create repo build directory + if ( (! -d $repodir) && (! mkpath($repodir)) ) { + print "Error creating build repository directory $repodir.\n"; + return 1; + } + + # Build kitpackages first + foreach my $kp (@{$::bldkit_config->{kitpackage}{entries}}) { + # For this kitrepo? + my $found = 0; + foreach my $kprid (split(/,/, $kp->{kitrepoid})) { + $kprid =~ s/\s+//g; + if ($repoid eq $kprid) { + $found = 1; + last; + } + } + if (!$found) { next; } + + # is this package already built? + my $rpm = "$repodir/$kp->{filename}"; + if ( -r $rpm) { next; } + + if ($::VERBOSE) { print "building kitpackage $kp->{filename} \n";} + # determine build method + if (defined($kp->{rpm_prebuiltdir})) { + # simply copy the file to the build directory + my $full_prebuiltrpm = $srcdir.$kp->{rpm_prebuiltdir}."/".$kp->{filename}; + if (system("cp -fp $full_prebuiltrpm $repodir")) { + # non-zero return from system call + print "Error copying prebuilt rpm $kp->{filename} to Kit Build directory. \n"; + return 1; + } + } elsif (defined($kp->{rpm_srpm})) { + # run rpmbuild --rebuild on the source rpm + print "SKIPPING BUILD FOR KIT PACKAGE $kp->{filename} \n"; + print "TBD - only buildrepo for prebuilt rpms is available at this time \n\n"; + } elsif (defined($kp->{rpm_srctarball}) && + defined($kp->{rpm_spec}) ) { + # run rpmbuild + print "SKIPPING BUILD FOR KIT PACKAGE $kp->{filename} \n"; + print "TBD - only buildrepo for prebuilt rpms is available at this time \n\n"; + } elsif (defined($kp->{rpm_srcdir}) && + defined($kp->{rpm_spec}) ) { + # build tarfile and run rpmbuild + print "SKIPPING BUILD FOR KIT PACKAGE $kp->{filename} \n"; + print "TBD - only buildrepo for prebuilt rpms is available at this time \n\n"; + } else { + print "Cannot determine build method for Kit Package $kp->{filename}. Verify that your Kit Build File is correct. \n"; + return 1; + } + } + + # Build kitcomponent metapackages + foreach my $kc (@{$::bldkit_config->{kitcomponent}{entries}}) { + # Check if this kitcomponent is in the requested repo + if ($repoid ne $kc->{kitrepoid}) { next; } + + # Check if already built + my $rpm = "$repodir/".&comppkgname($kc); + if (-r $rpm) { next; } + + # Build it + if ($::VERBOSE) { print "building kitcomponet metapackage for $kc->{basename} \n";} + if (&build_kitcomp($kc)) { + print "Error building kitcomponent metapackage for $kc->{basename} \n"; + return 1; + } + } + + # run createrepo + if ( system("createrepo $repodir") ) { + print "Error building the repository meta-data with the createrepo command \n"; + return 1; + } + + return 0; +} + +#----------------------------------------------------------------------------- + +=head3 kit_listrepo + + buildkit listrepo + +=cut + +#----------------------------------------------------------------------------- + +sub kit_listrepo + +{ + # print "Kit Repository: Status \n"; + foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) { + my $rc = 0; + my $status = "NOT DONE"; + unless ($rc = &validate_repo($kr)) {$status = "DONE";} + print "$kr->{kitrepoid}: $status \n"; + } + + return 0; +} + +#----------------------------------------------------------------------------- + +=head3 kit_cleanrepo + + buildkit cleanrepo + +=cut + +#----------------------------------------------------------------------------- + +sub kit_cleanrepo + +{ + my $repoid = $::KIT_CLEANREPO; + my $tmp_repoid = $repoid; + $tmp_repoid =~ tr/A-Z/a-z/; # convert to lowercase + + if (($tmp_repoid eq 'all') ) { + if ( system("rm -Rf $::build_dir/kit_repodir/* ") ) { + print "Error removing contents of $::build_dir/kit_repodir \n"; + return 1; + } else { + print "Contents of $::build_dir/kit_repodir has been successfully removed. \n"; + } + } else { + foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) { + if ($repoid eq $kr->{kitrepoid}) { + my $repodir = $::build_dir.'/kit_repodir/'.$kr->{kitreponame}; + if ( -d $repodir ){ + if ( system("rm -Rf $repodir ") ) { + print "Error removing directory $repodir \n"; + return 1; + } else { + print "Kit repository $kr->{kitrepoid} has been removed. \n"; + } + } else { + print "Kit repository $kr->{kitrepoid} directory $repodir does not exist. Nothing to remove for this repository. \n"; + } + last; + } + } + } + if ( -d "$::workdir/rpmbuild" ) { + system("rm -Rf $::workdir/rpmbuild "); + } + if ( -d "$::workdir/tmp" ) { + system("rm -Rf $::workdir/tmp "); + } + + return 0; +} + +#----------------------------------------------------------------------------- + +=head3 kit_buildtar + + buildkit buildtar + +=cut + +#----------------------------------------------------------------------------- + +sub kit_buildtar + +{ + + foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) { + if (&validate_repo($kr)) { + print "Kit Repository $kr->{kitrepoid} not built. Run: \n"; + print " buildkit buildrepo $kr->{kitrepoid} \n"; + return 1; + } + } + if (&create_kitconf) { + print "Error creating kit configuration file \n"; + return 1; + } + + if (&create_builddir) { + print "Error creating kit build directory contents \n"; + return 1; + } + + if (! -d "$::deploy_dir/repos") { + symlink "$::build_dir/kit_repodir","$::deploy_dir/repos"; + } + # build the tarfile + my $kitname = $::bldkit_config->{kit}{entries}[0]->{kitname}; + my $tarfile = $::build_dir."/".$kitname.".tar.gz"; + if ( system("cd $::build_dir; tar -czhf $tarfile $kitname/*") ) { + print "Error building tarfile $tarfile \n"; + return 1; + } + print "Kit tar file $tarfile successfully built \n"; + +} + +#----------------------------------------------------------------------------- + +=head3 kit_cleantar + + buildkit cleantar + +=cut + +#----------------------------------------------------------------------------- + +sub kit_cleantar + +{ + + print "running buildkit cleantar... \n"; + my $kitname = $::bldkit_config->{kit}{entries}[0]->{kitname}; + my $tarfile = $::build_dir."/".$kitname.".tar.gz"; + if ( -r $tarfile ) { + if ( system("rm -f $tarfile ") ) { + print "Error removing kit tar file $tarfile \n"; + } else { + print "Kit tar file $tarfile has been successfully removed \n"; + } + } + if ( -d $::deploy_dir ) { + if ( system("rm -Rf $::deploy_dir ") ) { + print "Error removing contents of $::deploy_dir \n"; + } else { + print "All $::deploy_dir contents have been successfully removed \n"; + } + } + if ( -d "$::workdir/rpmbuild" ) { + system("rm -Rf $::workdir/rpmbuild "); + } + if ( -d "$::workdir/tmp" ) { + system("rm -Rf $::workdir/tmp "); + } + + +} + + +#----------------------------------------------------------------------------- + +=head3 kit_cleanall + + buildkit cleanall + +=cut + +#----------------------------------------------------------------------------- + +sub kit_cleanall + +{ + + print "running buildkit cleanall... \n"; + if ( -d $::build_dir ) { + if ( system("rm -Rf $::build_dir/* ") ) { + print "Error removing contents of $::build_dir \n"; + } else { + print "All $::build_dir contents have been successfully removed \n"; + } + } + if ( -d "$::workdir/rpmbuild" ) { + system("rm -Rf $::workdir/rpmbuild "); + } + if ( -d "$::workdir/tmp" ) { + system("rm -Rf $::workdir/tmp "); + } + +} + +#----------------------------------------------------------------------------- + +=head3 edit_bldkitconf + + edit the shipped template buildkit.conf file to insert initial values + for the new kit +=cut + +#----------------------------------------------------------------------------- + +sub edit_bldkitconf + +{ + + my $bldkitconf = shift; + my $kitname = shift; + + # read in the buildkit.conf file + my $CF; + unless ( open( $CF, "<", $bldkitconf ) ) { + print "The Kit build file $bldkitconf does not exist. \n"; + return 1; + } + if ($::VERBOSE) { + print "Reading kit configuration file $bldkitconf \n"; + } + my @lines = <$CF>; + close $CF; + + my $osinfo = xCAT::BuildKitUtils->osver(); + my $kitrepoid = $osinfo; + $kitrepoid =~ s/\,//; + my ($osbasename,$osmore) = split(/\,/, $osinfo); + my ($osmajorversion,$osminorversion) = split(/\./, $osmore); + my $osarch=`uname -p`; + my $kitcomponent_basename = $kitname."_compute"; + + for (@lines) { + s/<<>>/$kitname/; + s/<<>>/$kitrepoid/; + s/<<>>/$osbasename/; + s/<<>>/$osmajorversion/; + s/<<>>/$osminorversion/; + s/<<>>/$osarch/; + s/<<>>/$kitcomponent_basename/; + } + + # Write the buildkit.conf back out + my $NCF; + unless ( open( $NCF, ">$bldkitconf" ) ) { + return 1; + } + if ($::VERBOSE) { + print "Inserted initial values into $bldkitconf \n"; + } + print $NCF @lines; + close($NCF); + + return 0; +} + +#----------------------------------------------------------------------------- + +=head3 load_bldkitconf + + load the kitbuild.conf file into a global data structure and + verify that the general syntax is correct. + +=cut + +#----------------------------------------------------------------------------- + + +sub load_bldkitconf + +{ + my $bldkitconf = shift; + + + # read in the buildkit.conf file + my $CF; + unless ( open( $CF, "<", $bldkitconf ) ) { + print "The Kit build file $bldkitconf does not exist. \n"; + return 1; + } + if ($::VERBOSE) { + print "Reading kit configuration file $bldkitconf \n"; + } + my @lines = <$CF>; + close $CF; + + my $current_section = 'no section'; + my %current_entry; + my $syntax_error = ''; + my $bad_line = ''; + my $line_number = 0; + foreach my $l (@lines) { + $line_number++; + # skip blank and comment lines + next if ( $l =~ /^\s*$/ || $l =~ /^\s*#/ ); + + # process a real line + # new section? + if ( $l =~ /^\s*(\w+)\s*:/ ) { + my $section = $1; + if ( defined( $::buildkit_def{$section} ) ) { + if (($section eq 'kit') && + ($::bldkit_config->{$section}{'exists'})) { + $syntax_error = "More than one \"$section:\" section exists "; + $bad_line = $l; + last; + } + $::bldkit_config->{$section}{'exists'} = 1; + push ( @{ $::bldkit_config->{$current_section}{'entries'} }, {%current_entry}); + $current_section = $section; + undef %current_entry; + next; + } + } + if ( $l =~ /^\s*(\w+)\s*=\s*(.*)\s*/ ) { + my $attr = $1; + my $val = $2; + my $orig_attr = $attr; + my $orig_val = $val; + $attr =~ s/^\s*//; # Remove any leading whitespace + $attr =~ s/\s*$//; # Remove any trailing whitespace + $attr =~ tr/A-Z/a-z/; # Convert to lowercase + $val =~ s/^\s*//; + $val =~ s/\s*$//; + + if ( defined( $::buildkit_def{$current_section}{$attr} ) ) { + $current_entry{$attr} = $val; + } else { + if ( $current_section eq 'no section' ) { + $syntax_error = "No section specified for attribute $attr."; + } else { + my $valid_attrs = join (', ', (keys (%{$::buildkit_def{$current_section}}))); + $syntax_error = "Attribute \"$attr\" is not valid for section \"$current_section\". Valid attributes are: $valid_attrs.\n"; + } + $bad_line = $l; + last; + } + + } else { + $syntax_error = "Invalid line format"; + $bad_line = $l; + last; + + } + } + + # Need at least one kit and one kitrepo section + if (! $syntax_error) { + if ( !($::bldkit_config->{'kit'}{'exists'})) { + $syntax_error = "No \"kit:\" section found. At least one section required. "; + $bad_line = ''; + } elsif ( !($::bldkit_config->{'kitrepo'}{'exists'})) { + $syntax_error = "No \"kitrepo:\" section found. At least one section required. "; + $bad_line = ''; + } else { + push ( @{ $::bldkit_config->{$current_section}{'entries'} }, {%current_entry}); + } + } + + if ($syntax_error) { + print "Error processing file $bldkitconf \n"; + print "Syntax error found on line $line_number:\n"; + print "$bad_line \n"; + print "$syntax_error \n"; + print "\n"; + print "The Kit build file does not have the correct format. \n"; + print "The format should be: \n"; + print "
: \n"; + print " = \n"; + print " = \n"; + print " ... \n"; + print "
: \n"; + print " = \n"; + print " = \n"; + print " ... \n"; + print "The valid section names are: kit, kitrepo, kitcomponent, kitpackages. \n"; + print "There must be exactly one kit, and must be at least one kitrepo section. \n"; + return 1; + } + + # Check for mandatory attributes + foreach my $s (keys %{$::bldkit_config}) { + if (! defined($::buildkit_def{$s}) ) { next;} + foreach my $se (@{$::bldkit_config->{$s}{entries}}) { + foreach my $a (keys %{$::buildkit_def{$s}}) { + if (( $::buildkit_def{$s}{$a}->{mandatory} ) && + ( ! defined ($se->{$a}) ) ) { + print "The \"$a\" mandadory attribute must be defined in the \"$s\" section of the Kit build file \n"; + return 1; + } + } + } + } + +use Data::Dumper; +#print Dumper($::bldkit_config); + + return 0; + +} + + +#----------------------------------------------------------------------------- + +=head3 validate_bldkitconf + + validate the loaded buildkit configuration data + +=cut + +#----------------------------------------------------------------------------- + +sub validate_bldkitconf + +{ + my $kitname = $::bldkit_config->{kit}{entries}[0]->{basename}; + my $full_kitname = $kitname; + $full_kitname .= '-'.$::bldkit_config->{kit}{entries}[0]->{version}; + $full_kitname .= '-'.$::bldkit_config->{kit}{entries}[0]->{ostype}; + $::bldkit_config->{kit}{entries}[0]->{kitname} = $full_kitname; + $::deploy_dir .= "/".$full_kitname; + + # Make sure each kit kitdeployparams file exists + if (defined($::bldkit_config->{kit}{entries}[0]->{kitdeployparams})){ + my $kd_file = $::workdir."/other_files/".$::bldkit_config->{kit}{entries}[0]->{kitdeployparams}; + if (! -r $kd_file ) { + print "Kit Deployment Parameters file $kd_file does not exist or is not readable\n"; + return 1; + } + if (&edit_deployparams($kd_file,1)) { return 1;} + } + + # Make sure each kitrepo has unique distro info + my $kr_count = scalar @{$::bldkit_config->{kitrepo}{entries}}; + if ($kr_count > 1) { + foreach my $kri (0..$kr_count-2) { + foreach my $kri2 ($kri+1..$kr_count-1) { + my $kr = $::bldkit_config->{kitrepo}{entries}[$kri]; + my $kr2 = $::bldkit_config->{kitrepo}{entries}[$kri2]; + if ( $kr->{kitrepoid} eq $kr2->{kitrepoid} ) { + print "There are two or more kitrepo sections with the same kitrepoid \"$kr->{kitrepoid}\". \n"; + return 1; + } + if ( ($kr->{osbasename} eq $kr2->{osbasename}) && + ($kr->{osmajorversion} eq $kr2->{osmajorversion}) && + ($kr->{osarch} eq $kr2->{osarch}) ) { + if( ( defined ($kr->{osminorversion}) && + defined ($kr2->{osminorversion}) && + ($kr->{osminorversion} eq $kr2->{osminorversion}) ) || + ( ! defined ($kr->{osminorversion}) && + ! defined ($kr2->{osminorversion}) ) ) { + print "There are two or more kitrepo sections which are defined with the same OS name, major/minor version, and architecture. \n"; + return 1; + } + } + } + } + } + + # Make sure each kitcomponent has unique basename + my $kc_count = scalar @{$::bldkit_config->{kitcomponent}{entries}}; + if ($kc_count > 1) { + foreach my $kci (0..$kc_count-2) { + foreach my $kci2 ($kci+1..$kc_count-1) { + if ( $::bldkit_config->{kitcomponent}{entries}[$kci]->{basename} + eq $::bldkit_config->{kitcomponent}{entries}[$kci2]->{basename} ) { + print "There are two or more kitcomponent sections which are defined with the same basename \"$::bldkit_config->{kitcomponent}{entries}[$kci]->{basename}\". \n"; + return 1; + } + } + } + } + + # Kitrepo checks + foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) { + my $reponame = $full_kitname; + $reponame .= '_'.$kr->{osbasename}; + $reponame .= '-'.$kr->{osmajorversion}; + if (defined($kr->{osminorversion})){ + $reponame .= '.'.$kr->{osminorversion}; + } + $reponame .= '-'.$kr->{osarch}; + $kr->{kitreponame} = $reponame; + } + + # Kitcomponent checks + foreach my $kc (@{$::bldkit_config->{kitcomponent}{entries}}) { + # Make sure all kitcomponent kitrepoids are defined + my $found = 0; + my %repo; + foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) { + if ($kc->{kitrepoid} eq $kr->{kitrepoid}) { + $found = 1; + %repo = %{$kr}; + $kc->{kitreponame} = $kr->{kitreponame}; + push (@{$kr->{packages}}, &comppkgname($kc,$kr)); + last; + } + } + if ( ! $found ) { + print "Kit Repository \"$kc->{kitrepoid}\" required by the Kit Component \"$kc->{basename}\" not defined in the Kit Build file.\n"; + return 1; + } + # Create full kitcomponent name + my $compname = $kc->{basename}; + $compname .= '-'.$kc->{version}; + $compname .= '-'.$kc->{release}; + $compname .= '-'.$repo{osbasename}; + $compname .= '-'.$repo{osmajorversion}; + if ( defined($repo{osminorversion}) ) { + $compname .= '.'.$repo{osminorversion}; + } + $compname .= '-'.$repo{osarch}; + $kc->{kitcompname} = $compname; + # Make sure all kitcomponent kitpkgdeps are defined + if (defined($kc->{kitpkgdeps})) { + foreach my $d (split(/,/, $kc->{kitpkgdeps})) { + $d =~ s/\s+//g; + $d =~ s/^([\w\.\-]+)[<>=]*.*$/$1/; + my $found = 0; + foreach my $kp (@{$::bldkit_config->{kitpackage}{entries}}) { + if ( $kp->{filename} =~ /^$d[\.\-]/ ) { + foreach my $kprid (split(/,/, $kp->{kitrepoid})) { + $kprid =~ s/\s+//g; + if ($kc->{kitrepoid} eq $kprid) { + $found = 1; + last; + } + } + } + if ($found) { last; } + } + if ( !$found ) { + print "Kit Package \"$d\" required by the Kit Component \"$kc->{basename}\" was not found in the Kit Component\'s repository \"$kc->{kitrepoid}\".\n"; + return 1; + } + } + } + # Make sure all kitcomponent driverpacks are defined + if (defined($kc->{driverpacks})) { + my @drvs = split(/,/, $kc->{driverpacks}); + foreach my $d (@drvs) { + $d =~ s/\s+//g; + my $found = 0; + foreach my $kp (@{$::bldkit_config->{kitpackage}{entries}}) { + if ( $kp->{filename} eq $d ) { + foreach my $kprid (split(/,/, $kp->{kitrepoid})) { + $kprid =~ s/\s+//g; + if ($kc->{kitrepoid} eq $kprid) { + $found = 1; + last; + } + } + } + if ($found) { last; } + } + if ( !$found ) { + print "Driver package \"$d\" required by the Kit Component \"$kc->{basename}\" was not found in the Kit Component\'s repository \"$kc->{kitrepoid}\".\n"; + return 1; + } + } + } + # Make sure files exist + if (defined($kc->{exlist})){ + my $ck_file = $::workdir."/other_files/".$kc->{exlist}; + if (! -r $ck_file ) { + print "Exclude List file $ck_file defined in Kit Componenet \"$kc->{basename}\" does not exist or is not readable\n"; + return 1; + } + } + if (defined($kc->{preinstall})){ + my $ck_file = $::workdir."/scripts/".$kc->{preinstall}; + if (! -r $ck_file ) { + print "Pre-Install script $ck_file defined in Kit Componenet \"$kc->{basename}\" does not exist or is not readable\n"; + return 1; + } + } + if (defined($kc->{postinstall})){ + my $ck_file = $::workdir."/scripts/".$kc->{postinstall}; + if (! -r $ck_file ) { + print "Post-Install script $ck_file defined in Kit Componenet \"$kc->{basename}\" does not exist or is not readable\n"; + return 1; + } + } + if (defined($kc->{preuninstall})){ + my $ck_file = $::workdir."/scripts/".$kc->{preuninstall}; + if (! -r $ck_file ) { + print "Pre-Uninstall script $ck_file defined in Kit Componenet \"$kc->{basename}\" does not exist or is not readable\n"; + return 1; + } + } + if (defined($kc->{postuninstall})){ + my $ck_file = $::workdir."/scripts/".$kc->{postuninstall}; + if (! -r $ck_file ) { + print "Post-Uninstall script $ck_file defined in Kit Componenet \"$kc->{basename}\" does not exist or is not readable\n"; + return 1; + } + } + if (defined($kc->{preupgrade})){ + my $ck_file = $::workdir."/scripts/".$kc->{preupgrade}; + if (! -r $ck_file ) { + print "Pre-Upgrade script $ck_file defined in Kit Componenet \"$kc->{basename}\" does not exist or is not readable\n"; + return 1; + } + } + if (defined($kc->{posupgrade})){ + my $ck_file = $::workdir."/scripts/".$kc->{postupgrade}; + if (! -r $ck_file ) { + print "Post-Upgrade script $ck_file defined in Kit Componenet \"$kc->{basename}\" does not exist or is not readable\n"; + return 1; + } + } + if (defined($kc->{postbootscripts})){ + foreach my $script (split(/\,/, $kc->{postbootscripts})){ + $script =~ s/\s+//g; + my $ck_file = $::workdir."/scripts/".$script; + if (! -r $ck_file ) { + print "Postboot script $ck_file defined in Kit Componenet \"$kc->{basename}\" does not exist or is not readable\n"; + return 1; + } + } + } + } + + # Kitpackage checks + foreach my $kp (@{$::bldkit_config->{kitpackage}{entries}}) { + # Make sure all kitpackage kitrepoids are defined + foreach my $kprid (split(/,/, $kp->{kitrepoid})) { + my $found = 0; + $kprid =~ s/\s+//g; + foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) { + if ($kprid eq $kr->{kitrepoid}) { + $found = 1; + push (@{$kr->{packages}}, $kp->{filename}); + last; + } + } + if ( ! $found ) { + print "Kit Repository \"$kprid\" required by the Kit Package \"$kp->{filename}\" is not defined in the Kit Build file.\n"; + return 1; + } + } + # determine if valid build method + if (defined($kp->{rpm_prebuiltdir})) { + if ((defined($kp->{rpm_srpm})) || + (defined($kp->{rpm_srctarball})) || + (defined($kp->{rpm_spec})) || + (defined($kp->{rpm_srcdir})) ) { + print "Cannot determine build method for Kit Package $kp->{filename}. Conflicting attributes were specified.\n"; + return 1; + } + } elsif (defined($kp->{rpm_srpm})) { + if ((defined($kp->{rpm_prebuiltdir})) || + (defined($kp->{rpm_srctarball})) || + (defined($kp->{rpm_spec})) || + (defined($kp->{rpm_srcdir})) ) { + print "Cannot determine build method for Kit Package $kp->{filename}. Conflicting attributes were specified.\n"; + return 1; + } + } elsif (defined($kp->{rpm_srctarball}) && + defined($kp->{rpm_spec}) ) { + if ((defined($kp->{rpm_prebuiltdir})) || + (defined($kp->{rpm_srpm})) || + (defined($kp->{rpm_srcdir})) ) { + print "Cannot determine build method for Kit Package $kp->{filename}. Conflicting attributes were specified.\n"; + return 1; + } + } elsif (defined($kp->{rpm_srcdir}) && + defined($kp->{rpm_spec}) ) { + if ((defined($kp->{rpm_prebuiltdir})) || + (defined($kp->{rpm_srpm})) || + (defined($kp->{rpm_srctarball})) ) { + print "Cannot determine build method for Kit Package $kp->{filename}. Conflicting attributes were specified.\n"; + return 1; + } + } else { + print "Cannot determine build method for Kit Package $kp->{filename}. Verify that your Kit Build File is correct. \n"; + return 1; + } + # Make sure files exist + if (defined($kp->{rpm_spec})){ + my $ck_file = $::workdir."/source_packages/".$kp->{rpm_spec}; + if (! -r $ck_file ) { + print "RPM spec file $ck_file defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; + return 1; + } + } + if (defined($kp->{rpm_srcdir})){ + my $ck_dir = $::workdir."/source_packages/".$kp->{rpm_srcdir}; + if (! -d $ck_dir ) { + print "RPM source directory $ck_dir defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; + return 1; + } + } + if (defined($kp->{rpm_srctarball})){ + my $ck_file = $::workdir."/source_packages/".$kp->{rpm_srctarball}; + if (! -r $ck_file ) { + print "RPM source tarfile $ck_file defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; + return 1; + } + } + if (defined($kp->{rpm_srpm})){ + my $ck_file = $::workdir."/source_packages/".$kp->{rpm_srpm}; + if (! -r $ck_file ) { + print "Source RPM $ck_file defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; + return 1; + } + } + if (defined($kp->{rpm_prebuiltdir})){ + my $ck_dir = $::workdir."/source_packages/".$kp->{rpm_prebuiltdir}; + if (! -d $ck_dir ) { + print "Pre-built RPM directory $ck_dir defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; + return 1; + } + my $ck_file = $ck_dir."/".$kp->{filename}; + if (! -r $ck_file ) { + print "Pre-built rpm $ck_file defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; + return 1; + } + } + } +#use Data::Dumper; +#print Dumper($::bldkit_config->{kitrepo}); + return 0; +} + +#----------------------------------------------------------------------------- + +=head3 comppkgname + + build a metapkg rpm filename for this kitcomponent + input: kitcomponent hash + kitrepo hash that this kitcomponent belongs to + +=cut + +#----------------------------------------------------------------------------- + +sub comppkgname + +{ + my $comp = shift; + # my $repo = shift; + + my $pkgname = $comp->{basename}; + $pkgname .= '-'.$comp->{version}; + $pkgname .= '-'.$comp->{release}; + $pkgname .= '.noarch.rpm'; + # $pkgname .= '-'.$repo->{osmajorversion}; + # if (defined($repo->{osminorversion})) { + # $pkgname .= '.'.$repo->{osminorversion}; + # } + # $pkgname .= '-'.$repo->{osarch}; + # $pkgname .= '.rpm'; + + return $pkgname; +} + + +#----------------------------------------------------------------------------- + +=head3 validate_repo + + validate whether a kit repo has been built + input: repo hash + returns rc: + 0 - repo status is DONE + 1 - repo status is NOT DONE + verbose mode displays message for first rpm not built + +=cut + +#----------------------------------------------------------------------------- + +sub validate_repo + +{ + my $repo = shift; + + my $repodir = $::build_dir."/kit_repodir/".$repo->{kitreponame}; + if ( ! -d $repodir ) { + if ($::VERBOSE) { + print "\n$repodir does not exist. No rpms have been built for this kitrepo. \n"; + } + return 1; + } + + foreach my $pkg (@{$repo->{packages}}){ + my $pkg_filename = $repodir.'/'.$pkg; + if (! -r $pkg_filename) { + if ($::VERBOSE) { + print "\nFile $pkg in directory $repodir does not exist or is not readable. \n"; + } + return 1; + } + } + + return 0; +} + + +#----------------------------------------------------------------------------- + +=head3 validate_os + + validate whether a kit repo matches the current OS + input: repo hash + returns rc: + 0 - match + 1 - no match + verbose mode displays message for mismatch details + +=cut + +#----------------------------------------------------------------------------- + +sub validate_os + +{ + my $repo = shift; + + my $osinfo = xCAT::BuildKitUtils->osver(); + my ($osbasename,$osmore) = split(/\,/, $osinfo); + my ($osmajorversion,$osminorversion) = split(/\./, $osmore); + my $osarch=`uname -p`; + chomp($osarch); + $osinfo =~ s/\,//; + my $repo_osinfo = "$repo->{osbasename}$repo->{osmajorversion}"; + if (defined($repo->{osminorversion})){ + $repo_osinfo .= ".$repo->{osminorversion}"; + } + $repo_osinfo .= "-$repo->{osarch} "; + my $mismatch_msg = "The local host is running $osinfo-$osarch. This does not match the Kit Repository \"$repo->{kitrepoid}\" data: $repo_osinfo"; + if (defined($repo->{compat_osbasenames})){ + $mismatch_msg .= " or the compatible OS distros: $repo->{compat_osbasenames} "; + } + + + my $compat_match = 0; + if ($repo->{osbasename} ne $osbasename) { + if (defined($repo->{compat_osbasenames})){ + foreach my $cos (split(/,/, $repo->{compat_osbasenames})) { + if ($cos eq $osbasename) { + $compat_match = 1; + last; + } + } + } + if (!$compat_match) { + print "$mismatch_msg \n"; + if ($::VERBOSE) { + print "\n Local OS basename $osbasename does not match repository.\n"; + } + return 1; + } + } + if ( ($repo->{osmajorversion} ne $osmajorversion) && + (!$compat_match) ) { + print "$mismatch_msg \n"; + if ($::VERBOSE) { + print "\n Local OS major version $osmajorversion does not match repository.\n"; + } + return 1; + } + if (defined($repo->{osminorversion})) { + if ( ($repo->{osminorversion} ne $osminorversion) && + (!$compat_match) ) { + print "$mismatch_msg \n"; + if ($::VERBOSE) { + print "\n Local OS minor version $osminorversion does not match repository.\n"; + } + return 1; + } + } + if ($repo->{osarch} ne $osarch) { + print "$mismatch_msg \n"; + if ($::VERBOSE) { + print "\n Local OS arch $osarch does not match repository.\n"; + } + return 1; + } + + return 0; +} + + +#----------------------------------------------------------------------------- + +=head3 build_kitcomp + + build a metapkg rpm for this kitcomponent + input: kitcomponent hash + +=cut + +#----------------------------------------------------------------------------- + +sub build_kitcomp + +{ + my $comp = shift; + my %repo; + my $rpmbuild_dir = $::workdir."/rpmbuild"; + + # find the kitrepo hash for this component + foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) { + if ($comp->{kitrepoid} eq $kr->{kitrepoid}) { + %repo = %{$kr}; + last; + } + } + + # Create spec file for this kit component + if ( &gen_kitcomp_spec($comp,\%repo) ) { return 1; } + + # run the rpmbuild command + my $curdir = $::workdir; + my $cmd = "rm -Rf $curdir/rpmbuild"; + system($cmd); + my $avoiderr = $rpmbuild_dir."/BUILDROOT/".$comp->{basename}; + $avoiderr .= "-$comp->{version}-$comp->{release}.$repo{osarch}"; + mkpath($avoiderr); + + my $specfile = $::workdir."/tmp/$comp->{basename}.spec"; + $cmd = "rpmbuild --define \"_topdir $rpmbuild_dir\" -ba $specfile"; + if (!$::VERBOSE) { + $cmd .= ' --quiet '; + } + if ( system($cmd) ) { + print "Error running rpmbuild command for kit component $comp->{basename} meta package\n"; + return 1; + } + my $repodir = $::build_dir."/kit_repodir/".$repo{kitreponame}; + my @built_rpms = `find $rpmbuild_dir/RPMS -name *.rpm`; + foreach my $rpm (@built_rpms) { + chomp($rpm); + if ( system ("cp -fp $rpm $repodir") ) { + print "Error copying rpm $rpm to build repo directory $repodir \n"; + return 1; + } + } + + return 0; +} + +#----------------------------------------------------------------------------- + +=head3 gen_kitcomp_spec + + generate the rpm spec file for the kitcomponent metapkg rpm + input: kitcomponent hash + kitrepo hash + +=cut + +#----------------------------------------------------------------------------- + +sub gen_kitcomp_spec + +{ + my $comp = shift; + my $repo = shift; + my $scriptdir = $::workdir."/scripts/"; + my $tmpdir = $::workdir."/tmp/"; + + # read in the template spec file + my $spec_template = $::XCATSHARE."/kits/kitcomponent.spec.template"; + my $SF; + unless ( open( $SF, "<", $spec_template ) ) { + print "Error attempting to open the xCAT Kit Component template file $spec_template. \n"; + return 1; + } + if ($::VERBOSE) { + print "Reading the xCAT Kit Component template file $spec_template. \n"; + } + my @lines = <$SF>; + close $SF; + + + my $kitname = $::bldkit_config->{kit}{entries}[0]->{basename}; + my ($prescript,$postscript,$preupscript,$postupscript,$preunscript,$postunscript) = ' '; + if (defined($comp->{preinstall})) { + $prescript = &load_script("$scriptdir$comp->{preinstall}"); } + if (defined($comp->{postinstall})) { + $postscript = &load_script("$scriptdir$comp->{postinstall}"); } + if (defined($comp->{preupgrade})) { + $preupscript = &load_script("$scriptdir$comp->{preupgrade}"); } + if (defined($comp->{postupgrade})) { + $postupscript = &load_script("$scriptdir$comp->{postupgrade}"); } + if (defined($comp->{preuninstall})) { + $preunscript = &load_script("$scriptdir$comp->{preuninstall}"); } + if (defined($comp->{postuninstall})) { + $postunscript = &load_script("$scriptdir$comp->{postuninstall}"); } + + for (@lines) { + s/<<>>/$kitname/; + s/<<>>/$comp->{basename}/; + s/<<>>/$comp->{version}/; + s/<<>>/$comp->{release}/; + s/<<>>/$comp->{ospkgdeps}/; + s/<<>>/$comp->{kitpkgdeps}/; + s/<<>>/$comp->{kitcompdeps}/; + s/<<>>/$comp->{desc}/; + s/<<>>/$prescript/; + s/<<>>/$postscript/; + s/<<>>/$preupscript/; + s/<<>>/$postupscript/; + s/<<>>/$preunscript/; + s/<<>>/$postunscript/; + } + + # Write the generated spec file + my $joined_lines = join("\n",@lines); + @lines = split(/\\n/,$joined_lines); + mkpath($tmpdir); + my $NSF; + unless ( open( $NSF, ">$tmpdir/$comp->{basename}.spec" ) ) { + return 1; + } + if ($::VERBOSE) { + print "Created kitcomponent spec file $tmpdir/$comp->{basename}.spec \n"; + } + print $NSF @lines; + close($NSF); + + return 0; +} + + +#----------------------------------------------------------------------------- + +=head3 load_script + + load a kitcomponent script into a single return string + with imbedded newline chars + input: fullpath of scriptname + +=cut + +#----------------------------------------------------------------------------- + +sub load_script + +{ + my $scriptname = shift; + my $SF; + unless ( open( $SF, "<", $scriptname ) ) { + print "Error attempting to open the file $scriptname. \n"; + return; + } + if ($::VERBOSE) { + print "Reading the file $scriptname. \n"; + } + my @lines = <$SF>; + close $SF; + + my $script_contents = join('\n', @lines); + return $script_contents; +} + + + +#----------------------------------------------------------------------------- + +=head3 create_kitconf + + Create the kit configuration file to put into the kit tar file. + +=cut + +#----------------------------------------------------------------------------- + +sub create_kitconf + +{ + + # Build kit config file entries from buildkit config input + my $kitname = $::bldkit_config->{kit}{entries}[0]->{kitname}; + foreach my $s (keys %{$::bldkit_config}) { + if (! defined($::buildkit_def{$s}) ) { next;} + if ( $s eq 'kitpackage' ) { next; } + my $li = 0; + foreach my $se (@{$::bldkit_config->{$s}{entries}}) { + $::kit_config->{$s}{entries}[$li]->{kitname} = $kitname; + # copy all defined attrs over + foreach my $a (keys %{$::buildkit_def{$s}}) { + if (( $::buildkit_def{$s}{$a}->{cp_to_kitconfig} eq '1' ) && + ( defined ($se->{$a}) ) ) { + $::kit_config->{$s}{entries}[$li]->{$a} = $se->{$a} + } + if (( $::buildkit_def{$s}{$a}->{cp_to_kitconfig} eq '2' ) && + ( defined ($se->{$a}) ) ) { + my $prefix = "$kitname"; + if ( $s eq 'kitcomponent' ) { + $prefix = "$::bldkit_config->{$s}{entries}[$li]->{kitcompname}"; + if ($a eq 'postbootscripts') { + $prefix = "KIT_".$prefix; + } + } + if ( !($::kit_config->{$s}{entries}[$li]->{$a} = + &cp_to_builddir($se->{$a},$::workdir.'/'.$::buildkit_def{$s}{$a}->{base_dir},$prefix)) ) { + return 1; + } + } + } + # Handle special attrs + if ( $s eq 'kitrepo' ) { + $::kit_config->{$s}{entries}[$li]->{kitreponame} = + $se->{kitreponame}; + } elsif ( $s eq 'kitcomponent' ) { + $::kit_config->{$s}{entries}[$li]->{kitcompname} = + $se->{kitcompname}; + $::kit_config->{$s}{entries}[$li]->{kitreponame} = + $se->{kitreponame}; + } + $li++; + } + } + + # Write Kit Config File + my @lines; + my $li=0; + $lines[$li++] = "# Kit Configuration File for $kitname generated by buildkit\n"; + $lines[$li++] = "# ".localtime()."\n"; + foreach my $s ('kit','kitrepo','kitcomponent') { + foreach my $se (@{$::kit_config->{$s}{entries}}) { + $lines[$li++] = "$s: \n"; + foreach my $a (keys %{$se}) { + $lines[$li++] = " $a = $se->{$a} \n"; + } + } + } + + my $full_kit_conf = $::deploy_dir."/".$::kit_conf; + my $NCF; + unless ( open( $NCF, ">$full_kit_conf" ) ) { + return 1; + } + if ($::VERBOSE) { + print "Wrote new kit configuration file $full_kit_conf \n"; + } + print $NCF @lines; + close($NCF); + + + return 0; + +} + +#----------------------------------------------------------------------------- + +=head3 cp_to_builddir + + Copy specified files into the build directory renaming as indicated + +=cut + +#----------------------------------------------------------------------------- + +sub cp_to_builddir + +{ + + my $files = shift; + my $from_dir = shift; + my $prefix = shift; + + my $copied_files; + my $other_files = $::deploy_dir."/other_files"; + if ( (! -d $other_files) && (! mkpath($other_files)) ) { + print "Error creating build directory $other_files.\n"; + return; + } + foreach my $file (split(/\,/, $files)) { + $file =~ s/\s+//g; + my $from_file = $from_dir."/".$file; + my $from_file_base = basename($file); + my $to_file_base = $prefix."_".$from_file_base; + my $to_file = $other_files."/".$to_file_base; + if ( system("cp -fp $from_file $to_file") ) { + # non-zero return from system call + print "Error copying file $from_file to build directory $other_files \n"; + return; + } + $copied_files .= ",$to_file_base"; + } + $copied_files =~ s/^\,//; + return $copied_files; + +} + +#----------------------------------------------------------------------------- + +=head3 create_builddir + + Create the build directory and copy in all required files for building + the kit tar file. + +=cut + +#----------------------------------------------------------------------------- + +sub create_builddir + +{ + my $kitname = $::bldkit_config->{kit}{entries}[0]->{kitname}; + + # Note: + # - repos already created and validated + # - kit.conf file already created + # - exlists, postbootscripts, and deployparams already copied + + # copy plugins to build dir and edit to insert correct plugin and kit names + my $plugin_dir = $::deploy_dir."/plugins"; + if ( -d "$::workdir/plugins" ) { + if ( (! -d $plugin_dir) && (! mkpath($plugin_dir)) ) { + print "Error creating build directory $plugin_dir.\n"; + return 1; + } + + foreach my $plugin (<$::workdir/plugins/*.pm>){ + my $plugin_base = basename($plugin); + my $to_plugin = $plugin_dir."/".$kitname."_".$plugin_base; + if ( system("cp -fp $plugin $to_plugin") ) { + # non-zero return from system call + print "Error copying plugin file $plugin to build directory $plugin_dir \n"; + return 1; + } + if (&edit_plugin($to_plugin)) { return 1;} + } + } + + + + # copy docs to build dir + if ( -d "$::workdir/docs" ) { + if ( system("cp -fRp $::workdir/docs $::deploy_dir") ) { + # non-zero return from system call + print "Error copying doc files $::workdir/docs to build directory $::deploy_dir \n"; + return 1; + } + } + + # Edit deploy params file to make sure correct format for xCAT + if (defined($::kit_config->{kit}{entries}[0]->{kitdeployparams})){ + my $kd_file = $::deploy_dir."/other_files/".$::kit_config->{kit}{entries}[0]->{kitdeployparams}; + if (&edit_deployparams($kd_file)) { return 1;} + } + + + return 0; + +} + + +#----------------------------------------------------------------------------- + +=head3 edit_deployparams + + Edit the kit deployment parameters to make sure it has correct + syntax for xCAT otherpkglist support + + +=cut + +#----------------------------------------------------------------------------- + +sub edit_deployparams + +{ + my $file = shift; + my $validate_only = shift; + + # read in the file + my $DF; + unless ( open( $DF, "<", $file ) ) { + print "The Kit deployment parameters file $file could not be read. \n"; + return 1; + } + my @lines = <$DF>; + close $DF; + + # Edit the files + my $changed = 0; + my @new_lines; + my $ln = 0; + foreach my $l (@lines) { + $ln++; + # skip blank lines + if ( $l =~ /^\s*$/ ) { + push (@new_lines, $l); + next; + } + # #ENV lines + $l =~ s/^\s+//; # compress leading blanks + if ( $l =~ /^\#ENV\:/ ) { + if ( !($l =~ /\#\s*$/) ) { + chomp $l; + $l .= "#\n"; + $changed = 1; + } + push (@new_lines, $l); + next; + } + # skip all other comments + if ( $l =~ /^\s*#/ ) { + push (@new_lines, $l); + next; + } + # Add #ENV if not specified + if ( $l =~ /^\w*\s*\=/ ) { + chomp $l; + $l = "#ENV: $l #"; + $changed = 1; + push (@new_lines, $l); + next; + } + # Syntax error + print "Syntax error in kit deployment parameters file $file \n"; + print "line $ln: \n"; + print "$l \n"; + return 1; + } + + # Write the file back out + if ($changed && !$validate_only) { + my $NDF; + unless ( open( $NDF, ">$file" ) ) { + return 1; + } + if ($::VERBOSE) { + print "Editted kit deployment parameters file $file \n"; + } + print $NDF @lines; + close($NDF); + } + + return 0; +} + + + +#----------------------------------------------------------------------------- + +=head3 edit_plugin + + Edit the kit plugin file to insert the full kit name + + +=cut + +#----------------------------------------------------------------------------- + +sub edit_plugin + +{ + my $file = shift; + my $kitname = $::bldkit_config->{kit}{entries}[0]->{kitname}; + + # read in the file + my $PF; + unless ( open( $PF, "<", $file ) ) { + print "The Kit plugin file $file could not be read. \n"; + return 1; + } + my @lines = <$PF>; + close $PF; + + for (@lines) { + s/<<>>/$kitname/g; + } + + # Write the plugin back out + my $NPF; + unless ( open( $NPF, ">$file" ) ) { + return 1; + } + if ($::VERBOSE) { + print "Inserted kitname values into $file \n"; + } + print $NPF @lines; + close($NPF); + + return 0; +} + + + diff --git a/xCAT-buildkit/lib/perl/xCAT/BuildKitUtils.pm b/xCAT-buildkit/lib/perl/xCAT/BuildKitUtils.pm new file mode 100644 index 000000000..380d3586e --- /dev/null +++ b/xCAT-buildkit/lib/perl/xCAT/BuildKitUtils.pm @@ -0,0 +1,752 @@ +#!/usr/bin/env perl +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +package xCAT::BuildKitUtils; + +BEGIN +{ + $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat'; +} + +# if AIX - make sure we include perl 5.8.2 in INC path. +# Needed to find perl dependencies shipped in deps tarball. +if ($^O =~ /^aix/i) { + unshift(@INC, qw(/usr/opt/perl5/lib/5.8.2/aix-thread-multi /usr/opt/perl5/lib/5.8.2 /usr/opt/perl5/lib/site_perl/5.8.2/aix-thread-multi /usr/opt/perl5/lib/site_perl/5.8.2)); +} + +use lib "$::XCATROOT/lib/perl"; +use POSIX qw(ceil); +use File::Path; +use Socket; +use strict; +use Symbol; +my $sha1support = eval { + require Digest::SHA1; + 1; +}; +use IPC::Open3; +use IO::Select; +use xCAT::GlobalDef; +eval { + require xCAT::RemoteShellExp; +}; +use warnings "all"; +require xCAT::InstUtils; +#require xCAT::NetworkUtils; +require xCAT::Schema; +#require Data::Dumper; +require xCAT::NodeRange; +require xCAT::Version; +require DBI; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw(genpassword runcmd3); + +#-------------------------------------------------------------------------------- + +=head1 xCAT::BuildKitUtils + +=head2 Package Description + +This program module file, is a set of utilities used by xCAT buildkit command + +=cut + +#------------------------------------------------------------- + + +#------------------------------------------------------------------------------- + +=head3 isAIX + returns 1 if localHost is AIX + Arguments: + none + Returns: + 1 - localHost is AIX + 0 - localHost is some other platform + Globals: + none + Error: + none + Example: + if (xCAT::BuildKitUtils->isAIX()) { blah; } + Comments: + none +=cut + +#------------------------------------------------------------------------------- +sub isAIX +{ + if ($^O =~ /^aix/i) { return 1; } + else { return 0; } +} + +#------------------------------------------------------------------------------- + +=head3 get_OS_VRMF + + Arguments: + none + Returns: + v.r.m.f - if success + undef - if error + Example: + my $osversion = xCAT::BuildKitUtils->get_OS_VRMF(); + Comments: + Only implemented for AIX for now +=cut + +#------------------------------------------------------------------------------- +sub get_OS_VRMF +{ + my $version; + if (xCAT::BuildKitUtils->isAIX()) { + my $cmd = "/usr/bin/lslpp -cLq bos.rte"; + my $output = `$cmd`; + chomp($output); + + # The third field in the lslpp output is the VRMF + $version = (split(/:/, $output))[2]; + + # not sure if the field would ever contain more than 4 parts? + my ($v1, $v2, $v3, $v4, $rest) = split(/\./, $version); + $version = join(".", $v1, $v2, $v3, $v4); + } + return (length($version) ? $version : undef); +} + +#---------------------------------------------------------------------------- + +=head3 testversion + + Compare version1 and version2 according to the operator and + return True or False. + + Arguments: + $version1 + $operator + $version2 + $release1 + $release2 + Returns: + True or False + + Example: + if (BuildKitUtils->testversion ( $ins_ver, + "<", + $req_ver, + $ins_rel, + $req_rel)){ blah; } + + Comments: + +=cut + +#------------------------------------------------------------------------------- +sub testversion +{ + my ($class, $version1, $operator, $version2, $release1, $release2) = @_; + + my @a1 = split(/\./, $version1); + my @a2 = split(/\./, $version2); + my $len = (scalar(@a1) > scalar(@a2) ? scalar(@a1) : scalar(@a2)); + $#a1 = $len - 1; # make the arrays the same length before appending release + $#a2 = $len - 1; + push @a1, split(/\./, $release1); + push @a2, split(/\./, $release2); + $len = (scalar(@a1) > scalar(@a2) ? scalar(@a1) : scalar(@a2)); + my $num1 = ''; + my $num2 = ''; + + for (my $i = 0 ; $i < $len ; $i++) + { + my ($d1) = $a1[$i] =~ /^(\d*)/; # remove any non-numbers on the end + my ($d2) = $a2[$i] =~ /^(\d*)/; + + my $diff = length($d1) - length($d2); + if ($diff > 0) # pad d2 + { + $num1 .= $d1; + $num2 .= ('0' x $diff) . $d2; + } + elsif ($diff < 0) # pad d1 + { + $num1 .= ('0' x abs($diff)) . $d1; + $num2 .= $d2; + } + else # they are the same length + { + $num1 .= $d1; + $num2 .= $d2; + } + } + + # Remove the leading 0s or perl will interpret the numbers as octal + $num1 =~ s/^0+//; + $num2 =~ s/^0+//; + + #SLES Changes ?? + # if $num1="", the "eval '$num1 $operator $num2'" will fail. + # So MUST BE be sure that $num1 is not a "". + if (length($num1) == 0) { $num1 = 0; } + if (length($num2) == 0) { $num2 = 0; } + #End of SLES Changes + + if ($operator eq '=') { $operator = '=='; } + my $bool = eval "$num1 $operator $num2"; + + if (length($@)) + { + # error msg ? + } + + return $bool; +} + + +#------------------------------------------------------------------------------- + +=head3 isLinux + returns 1 if localHost is Linux + Arguments: + none + Returns: + 1 - localHost is Linux + 0 - localHost is some other platform + Globals: + none + Error: + none + Example: + if (xCAT::BuildKitUtils->isLinux()) { blah; } + Comments: + none +=cut + +#------------------------------------------------------------------------------- +sub isLinux +{ + if ($^O =~ /^linux/i) { return 1; } + else { return 0; } +} + +#-------------------------------------------------------------------------------- + +=head3 CreateRandomName + + Create a random file name. + Arguments: + Prefix of name + Returns: + Prefix with 8 random letters appended + Error: + none + Example: + $file = xCAT::BuildKitUtils->CreateRandomName($namePrefix); + Comments: + None + =cut + +#------------------------------------------------------------------------------- +sub CreateRandomName +{ +my ($class, $name) = @_; + +my $nI; +for ($nI = 0 ; $nI < 8 ; $nI++) +{ + my $char = ('a' .. 'z', 'A' .. 'Z')[int(rand(52)) + 1]; + $name .= $char; +} + $name; +} + +#----------------------------------------------------------------------- + +=head3 +close_delete_file. + + Arguments: + file handle,filename + Returns: + none + Globals: + none + Error: + undef + Example: + xCAT::BuildKitUtils->close_delete_file($file_handle, $file_name); + Comments: + none + +=cut + +#------------------------------------------------------------------------ +sub close_delete_file +{ + my ($class, $file_handle, $file_name) = @_; + close $file_handle; + + unlink($file_name); +} + + +#------------------------------------------------------------------------------- +=head3 runcmd3 + Run the specified command with optional input and return stderr, stdout, and exit code + + Arguments: + command=>[] - Array reference of command to run + input=>[] or string - Data to send to stdin of process like piping input + Returns: + { exitcode => number, output=> $string, errors => string } +=cut +sub runcmd3 { #a proper runcmd that indpendently returns stdout, stderr, pid and accepts a stdin + my %args = @_; + my @indata; + my $output; + my $errors; + if ($args{input}) { + if (ref $args{input}) { #array ref + @indata = @{$args{input}}; + } else { #just a string + @indata=($args{input}); + } + } + my @cmd; + if (ref $args{command}) { + @cmd = @{$args{command}}; + } else { + @cmd = ($args{command}); + } + my $cmdin; + my $cmdout; + my $cmderr = gensym; + my $cmdpid = open3($cmdin,$cmdout,$cmderr,@cmd); + my $cmdsel = IO::Select->new($cmdout,$cmderr); + foreach (@indata) { + print $cmdin $_; + } + close($cmdin); + my @handles; + while ($cmdsel->count()) { + @handles = $cmdsel->can_read(); + foreach (@handles) { + my $line; + my $done = sysread $_,$line,180; + if ($done) { + if ($_ eq $cmdout) { + $output .= $line; + } else { + $errors .= $line; + } + } else { + $cmdsel->remove($_); + close($_); + } + } + } + waitpid($cmdpid,0); + my $exitcode = $? >> 8; + return { 'exitcode' => $exitcode, 'output' => $output, 'errors' => $errors } +} + +#------------------------------------------------------------------------------- + +=head3 runcmd + Run the given cmd and return the output in an array (already chopped). + Alternately, if this function is used in a scalar context, the output + is joined into a single string with the newlines separating the lines. + + Arguments: + command, exitcode, reference to output, streaming mode + Returns: + see below + Globals: + $::RUNCMD_RC , $::CALLBACK + Error: + Normally, if there is an error running the cmd,it will display the + error and exit with the cmds exit code, unless exitcode + is given one of the following values: + 0: display error msg, DO NOT exit on error, but set + $::RUNCMD_RC to the exit code. + -1: DO NOT display error msg and DO NOT exit on error, but set + $::RUNCMD_RC to the exit code. + -2: DO the default behavior (display error msg and exit with cmds + exit code. + number > 0: Display error msg and exit with the given code + + Example: + my $outref = xCAT::BuildKitUtils->runcmd($cmd, -2, 1); + $::CALLBACK= your callback (required for streaming from plugins) + my $outref = xCAT::BuildKitUtils->runcmd($cmd,-2, 1, 1); streaming + + Comments: + If refoutput is true, then the output will be returned as a + reference to an array for efficiency. + + +=cut + +#------------------------------------------------------------------------------- +sub runcmd + +{ + + my ($class, $cmd, $exitcode, $refoutput, $stream) = @_; + $::RUNCMD_RC = 0; + # redirect stderr to stdout + if (!($cmd =~ /2>&1$/)) { $cmd .= ' 2>&1'; } + + my $outref = []; + if (!defined($stream) || (length($stream) == 0)) { # do not stream + @$outref = `$cmd`; + } else { # streaming mode + my @cmd; + push @cmd,$cmd; + my $rsp = {}; + my $output; + my $errout; + open (PIPE, "$cmd |"); + while () { + if ($::CALLBACK){ + $rsp->{data}->[0] = $_; + $::CALLBACK->($rsp); + } else { + xCAT::MsgUtils->message("D", "$_"); + } + $output .= $_; + } + # store the return string + push @$outref,$output; + } + + # now if not streaming process errors + if (($?) && (!defined($stream))) + { + $::RUNCMD_RC = $? >> 8; + my $displayerror = 1; + my $rc; + if (defined($exitcode) && length($exitcode) && $exitcode != -2) + { + if ($exitcode > 0) + { + $rc = $exitcode; + } # if not zero, exit with specified code + elsif ($exitcode <= 0) + { + $rc = ''; # if zero or negative, do not exit + if ($exitcode < 0) { $displayerror = 0; } + } + } + else + { + $rc = $::RUNCMD_RC; + } # if exitcode not specified, use cmd exit code + if ($displayerror) + { + my $rsp = {}; + my $errmsg = ''; + if (xCAT::BuildKitUtils->isLinux() && $::RUNCMD_RC == 139) + { + $errmsg = "Segmentation fault $errmsg"; + } + else + { + $errmsg = join('', @$outref); + chomp $errmsg; + + } + if ($::CALLBACK) + { + $rsp->{data}->[0] = + "Command failed: $cmd. Error message: $errmsg.\n"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + + } + else + { + xCAT::MsgUtils->message("E", + "Command failed: $cmd. Error message: $errmsg.\n"); + } + $xCAT::BuildKitUtils::errno = 29; + } + } + if ($refoutput) + { + chomp(@$outref); + return $outref; + } + elsif (wantarray) + { + chomp(@$outref); + return @$outref; + } + else + { + my $line = join('', @$outref); + chomp $line; + return $line; + } + +} + +#------------------------------------------------------------------------------- + +=head3 CheckVersion + Checks the two versions numbers to see which one is greater. + Arguments: + ver_a the version number in format of d.d.d.d... + ver_b the version number in format of d.d.d.d... + Returns: + 1 if ver_a is greater than ver_b + 0 if ver_a is eaqual to ver_b + -1 if ver_a is smaller than ver_b + +=cut + +#------------------------------------------------------------------------------- +sub CheckVersion +{ + my $ver_a = shift; + if ($ver_a =~ /xCAT::BuildKitUtils/) + { + $ver_a = shift; + } + my $ver_b = shift; + + my @a = split(/\./, $ver_a); + my @b = split(/\./, $ver_b); + my $len_a = @a; + my $len_b = @b; + + my $index = 0; + my $max_index = ($len_a > $len_b) ? $len_a : $len_b; + + for ($index = 0 ; $index <= $max_index ; $index++) + { + my $val_a = ($len_a < $index) ? 0 : $a[$index]; + my $val_b = ($len_b < $index) ? 0 : $b[$index]; + if ($val_a > $val_b) { return 1; } + if ($val_a < $val_b) { return -1; } + } + + return 0; +} + +#------------------------------------------------------------------------------- + +=head3 osver + Returns the os and version of the System you are running on + Arguments: + none + Returns: + 0 - ok + Globals: + none + Error: + 1 error + Example: + my $os=(xCAT::BuildKitUtils->osver{ ...} + Comments: + none + +=cut + +#------------------------------------------------------------------------------- +sub osver +{ + my $osver = "unknown"; + my $os = ''; + my $ver = ''; + my $line = ''; + my @lines; + my $relfile; + if (-f "/etc/redhat-release") + { + open($relfile,"<","/etc/redhat-release"); + $line = <$relfile>; + close($relfile); + chomp($line); + $os = "rh"; + $ver=$line; + # $ver=~ s/\.//; + $ver =~ s/[^0-9]*([0-9.]+).*/$1/; + if ($line =~ /AS/) { $os = 'rhas' } + elsif ($line =~ /ES/) { $os = 'rhes' } + elsif ($line =~ /WS/) { $os = 'rhws' } + elsif ($line =~ /Server/) { $os = 'rhels' } + elsif ($line =~ /Client/) { $os = 'rhel' } + elsif (-f "/etc/fedora-release") { $os = 'rhfc' } + } + elsif (-f "/etc/SuSE-release") + { + open($relfile,"<","/etc/SuSE-release"); + @lines = <$relfile>; + close($relfile); + chomp(@lines); + if (grep /SLES|Enterprise Server/, @lines) { $os = "sles" } + if (grep /SLEC/, @lines) { $os = "slec" } + $ver = $lines[0]; + $ver =~ s/\.//; + $ver =~ s/[^0-9]*([0-9]+).*/$1/; + + #print "ver: $ver\n"; + } + elsif (-f "/etc/UnitedLinux-release") + { + + $os = "ul"; + open($relfile,"<","/etc/UnitedLinux-release"); + $ver = <$relfile>; + close($relfile); + $ver =~ tr/\.//; + $ver =~ s/[^0-9]*([0-9]+).*/$1/; + } + elsif (-f "/etc/lsb-release") # Possibly Ubuntu + { + + if (open($relfile,"<","/etc/lsb-release")) { + my @text = <$relfile>; + close($relfile); + chomp(@text); + my $distrib_id = ''; + my $distrib_rel = ''; + + foreach (@text) { + if ( $_ =~ /^\s*DISTRIB_ID=(.*)$/ ) { + $distrib_id = $1; # last DISTRIB_ID value in file used + } elsif ( $_ =~ /^\s*DISTRIB_RELEASE=(.*)$/ ) { + $distrib_rel = $1; # last DISTRIB_RELEASE value in file used + } + } + + if ( $distrib_id =~ /^(Ubuntu|"Ubuntu")\s*$/ ) { + $os = "ubuntu"; + + if ( $distrib_rel =~ /^(.*?)\s*$/ ) { # eliminate trailing blanks, if any + $distrib_rel = $1; + } + if ( $distrib_rel =~ /^"(.*?)"$/ ) { # eliminate enclosing quotes, if any + $distrib_rel = $1; + } + $ver = $distrib_rel; + } + } + } + $os = "$os" . "," . "$ver"; + return ($os); +} + +#----------------------------------------------------------------------------- +=head3 acquire_lock + Get a lock on an arbirtrary named resource. For now, this is only across the scope of one service node/master node, an argument may be added later if/when 'global' locks are supported. This call will block until the lock is free. + Arguments: + A string name for the lock to acquire + Returns: + false on failure + A reference for the lock being held. +=cut + +sub acquire_lock { + my $lock_name = shift; + use File::Path; + mkpath("/var/lock/xcat/"); + use Fcntl ":flock"; + my $tlock; + $tlock->{path}="/var/lock/xcat/".$lock_name; + open($tlock->{fd},">",$tlock->{path}) or return undef; + unless ($tlock->{fd}) { return undef; } + flock($tlock->{fd},LOCK_EX) or return undef; + return $tlock; +} + +#--------------------- +=head3 release_lock + Release an acquired lock + Arguments: + reference to lock + Returns: + false on failure, true on success +=cut + +sub release_lock { + my $tlock = shift; + unlink($tlock->{path}); + flock($tlock->{fd},LOCK_UN); + close($tlock->{fd}); +} + + +#------------------------------------------------------------------------------- + +=head3 get_unique_members + Description: + Return an array which have unique members + + Arguments: + origarray: the original array to be treated + Returns: + Return an array, which contains unique members. + Globals: + none + Error: + none + Example: + my @new_array = xCAT::BuildKitUtils::get_unique_members(@orig_array); + Comments: + +=cut + +#------------------------------------------------------------------------------- +sub get_unique_members +{ + my @orig_array = @_; + my %tmp_hash = (); + for my $ent (@orig_array) + { + $tmp_hash{$ent} = 1; + } + return keys %tmp_hash; +} + +#------------------------------------------------------------------------------- + +=head3 full_path + Description: + Convert the relative path to full path. + + Arguments: + relpath: relative path + cwdir: current working directory, use the cwd() if not specified + Returns: + Return the full path + NULL - Failed to get the full path. + Globals: + none + Error: + none + Example: + my $fp = xCAT::BuildKitUtils::full_path('./test', '/home/guest'); + Comments: + +=cut + +#------------------------------------------------------------------------------- +sub full_path +{ + my ($class, $relpath, $cwdir) = @_; + + my $fullpath; + + if (!$cwdir) { #cwdir is not specified + $fullpath = Cwd::abs_path($relpath); + } else { + $fullpath = $cwdir . "/$relpath"; + } + + return $fullpath; +} + + + +1; diff --git a/xCAT-buildkit/share/xcat/kits/kit_template/buildkit.conf b/xCAT-buildkit/share/xcat/kits/kit_template/buildkit.conf new file mode 100644 index 000000000..033b6c2e3 --- /dev/null +++ b/xCAT-buildkit/share/xcat/kits/kit_template/buildkit.conf @@ -0,0 +1,189 @@ +# Kit Build File +# +# This file was initially auto-generated by the buildkit CLI command. +# To create a new kit, the user should modify this file accordingly. +# Refer to the buildkit manpage for further details. +# + +# kit: This section defines general info for the Kit. +# There must be exactly one kit section in a kit build file. +# +# kit attributes: +# basename (mandatory) Kit base name. e.g., kit-lsf +# desc (optional) Kit description. +# version (mandatory) Kit version. e.g., 1.0 +# ostype (mandatory) Kit OS type. Must be Linux. +# AIX is currently not supported. +# isinternal (optional) PCM use only. +# Indicate if Kit is for internal use. +# Use 1 for yes, 0 for no. Default: 0 +# kitdeployparams (optional) Filename containing a list of kit deployment +# parameters, relative to +# /other_files +kit: + basename=<<>> + desc=description for <<>> + version=1.0 + ostype=Linux + kitdeployparams=sample/kitdeployparams.lst + + +# kitrepo: This section defines a Kit Package Repository. +# There must be at least one kitrepo section in a kit build file. +# If you want to support multiple OSes, you should create a separate +# repo for each OS. Also, no two repos can be defined with the same +# OS name, major/minor version and arch. For example, you cannot have +# two repos for RHEL 6.2 x86_64 in the same kit. +# +# kitrepo attributes: +# kitrepoid (mandatory) Kit package repository ID. +# Must be unique within this file. +# osbasename (mandatory) OS distro base name. e.g., rhels. +# osmajorversion (mandatory) OS major version. e.g., 6 +# osminorversion (optional) OS minor version. +# osarch (mandatory) OS architecture. e.g., x86_64 +# compat_osbasenames (optional) Comma-separated list of compatible +# OS distro base names. e.g., centos + +kitrepo: + kitrepoid=<<>> + osbasename=<<>> + osmajorversion=<<>> + osminorversion=<<>> + osarch=<<>> + #compat_osbasenames= + + +# kitcomponent: This section defines one Kit Component. +# There can be zero or more kitcomponent sections. +# If you want to build a component which supports multiple OSes, +# you should create one kitcomponent section for each OS. +# Also, no two components in a kit can be defined with the same +# base name. +# +# kitcomponent attributes: +# basename (mandatory) Kit component base name +# desc (optional) Kit component description +# version (mandatory) Kit component version +# release (mandatory) Kit component release +# serverroles (mandatory) Comma-separated list of servers that this +# component can install on. Valid values: +# mgtnode,servicenode,compute,loginnode,storagenode +# kitrepoid (mandatory) The ID of the kit package repository this +# component belongs to +# kitcompdeps (optional) Comma-separated list of kit component +# dependencies. These kit components can be included in +# this kit or in other kits. +# ospkgdeps (optional) Comma-separated list of OS package dependencies +# These packages must be shipped with the OS distro. +# kitpkgdeps (optional) Comma-separated list of kit package names that +# will be listed as "REQUIRES" when building this kit +# component. Each package must be defined in a separate +# kitpackage section. Each package must be in the same +# kitrepo as this kit component. +# non_native_pkgs (optional) TBD -- NOT SUPPORTED YET! +# Comma-separated list of non-native package +# paths that will be included as files in this kit +# component. All filenames are relative to +# /source_packages +# Kit component deployment scripts must be specified +# to manage these files. +# driverpacks (optional) Comma-separated list of driver package filenames +# Each driverpack must be defined in a separate kitpackage +# section. +# exlist (optional) Exclude list file for stateless image, relative +# to /other_files +# Kit component deployment scripts (optional) Each attribute specifies +# script path relative to /scripts +# Script attributes: +# preinstall, postinstall, preuninstall, postuninstall, +# preupgrade, postupgrade, postbootscripts +kitcomponent: + basename=<<>> + desc=description for component <<>> + version=1.0 + release=1 + serverroles=compute + kitrepoid=<<>> + #kitcompdeps= + #ospkgdeps= + kitpkgdeps=pkg1 + #kitpkgdeps=pkg1,pkg2,pkg2,pkg4 + #non_native_pkgs= + #driverpacks= + exlist=sample/exclude.lst + preinstall=sample/pre.sh + postinstall=sample/post.sh + preuninstall=sample/preun.sh + postuninstall=sample/postun.sh + preupgrade=sample/preup.sh + postupgrade=sample/postup.sh + postbootscripts=sample/postboot.sh + + +# kitpackage: This section defines one Kit Package, and how to build it. +# There can be zero or more kitpackage sections. +# All filenames should be relative paths to +# /source_packages +# If you want to build a package which can run on multiple OSes, +# you have two options: +# 1. Build a separate package for each OS you want to support. +# For this option, you need to define one kitpackage section +# per supported OS. +# 2. Build one package that can run on multiple OSes. +# If you are building an RPM package, you are responsible for +# creating an RPM spec file that can run on multiple OSes. +# For this option, you need to define one kitpackage section +# which contains multiple kitrepoid lines. +# +# kitpackage attributes: +# filename (mandatory) Package filename +# kitrepoid (mandatory) The repo(s) this package belongs to. +# If multiple repos are defined, the package will be built for +# the first repo only. For the other repos, a symlink is created +# to the package built for the first repo. +# Package build methods (optional) +# Define how to build the packages. +# If you don't specify a build method, the default behavior is +# to assume the package is pre-built under +# /source_packages +# All files in this section are relative to +# /source_packages +# There are four methods to build packages. +# 1. Use pre-built RPM package +# rpm_prebuiltdir: Path to directory containing pre-built +# RPM package +# 2. Build RPM from spec + src dir +# rpm_spec: Path to spec file. +# rpm_srcdir: Path to source directory. +# 3. Build RPM from spec + src tarball +# rpm_spec: Path to spec file. +# rpm_srctarball: Path to source tarball. +# 4. Build RPM from source RPM +# rpm_srpm: Path to source RPM package. +kitpackage: + filename=pkg1-1-1.noarch.rpm + kitrepoid=<<>> + # Method 1: Use pre-built RPM package + rpm_prebuiltdir=sample/pkg1 + +#kitpackage: +# filename=pkg2-1-1.noarch.rpm +# kitrepoid=<<>> +# # Method 2: Build RPM from spec + src dir +# rpm_spec=sample/pkg2/pkg2.spec +# rpm_srcdir=sample/pkg2/pkg2 +# +#kitpackage: +# filename=pkg3-1-1.noarch.rpm +# kitrepoid=<<>> +# # Method 3: Build RPM from spec + src tarball +# rpm_spec=sample/pkg3/pkg3.spec +# rpm_srctarball=sample/pkg3/pkg3.tar.gz +# +#kitpackage: +# filename=pkg4-1-1.noarch.rpm +# kitrepoid=<<>> +# # Method 4: Build RPM from source RPM +# rpm_srpm=sample/pkg4/pkg4-1-1.src.rpm +# diff --git a/xCAT-buildkit/share/xcat/kits/kit_template/other_files/sample/exclude.lst b/xCAT-buildkit/share/xcat/kits/kit_template/other_files/sample/exclude.lst new file mode 100644 index 000000000..e69de29bb diff --git a/xCAT-buildkit/share/xcat/kits/kit_template/other_files/sample/kitdeployparams.lst b/xCAT-buildkit/share/xcat/kits/kit_template/other_files/sample/kitdeployparams.lst new file mode 100644 index 000000000..e69de29bb diff --git a/xCAT-buildkit/share/xcat/kits/kit_template/plugins/sample/imageprofile.pm b/xCAT-buildkit/share/xcat/kits/kit_template/plugins/sample/imageprofile.pm new file mode 100644 index 000000000..f42b70e7f --- /dev/null +++ b/xCAT-buildkit/share/xcat/kits/kit_template/plugins/sample/imageprofile.pm @@ -0,0 +1,175 @@ +package xCAT_plugin::<<>>_imageprofile; + +use strict; +use warnings; + +require xCAT::Utils; +require xCAT::Table; +require xCAT::KitPluginUtils; + + +# buildkit Processing +# In order to avoid collisions with other plugins, the package +# name for this plugin must contain the full kit name. +# The buildkit buildtar command will copy this file from your plugins +# directory to the the kit build directory, renaming the file with the +# correct kit name. All strings in this file of the form +# <<>> +# will be replaced with the full kit name. In order for buildkit to +# correctly edit this file, do not remove these strings. + + +# Global Variables + +# This is the full name of the kit which this plugin belongs +# to. The kit name is used by some code in process_request() +# to determine if the plugin should run. When you are testing +# your plugin the kit name should be set to "TESTMODE" to +# bypass the plugin check in process_request(). + +our ($PLUGIN_KITNAME); +#$PLUGIN_KITNAME = "TESTMODE"; +$PLUGIN_KITNAME = "<<>>"; + + +#------------------------------------------------------- + +=head1 + + Image Profile Kit Plugin + This plugin contains commands to run custom actions + during image profile operations. + +=cut + +#------------------------------------------------------- + + +#------------------------------------------------------- + +=head3 handled_commands + + Return list of kit plugin commands handled by this plugin + +=cut + +#------------------------------------------------------- + +sub handled_commands { + return { + kitimagevalidatecomps => '<<>>_imageprofile', + kitimageimport => '<<>>_imageprofile', + }; +} + + +#------------------------------------------------------- + +=head3 process_request + + Process the kit plugin command. + +=cut + +#------------------------------------------------------- + +sub process_request { + my $request = shift; + my $callback = shift; + + # This kit plugin is passed the name of an image profile. + # We need to determine which kits is used by this + # image profile to decide if this plugin should run or not. + + my $imgprofilename = $request->{arg}->[0]; + + my $kitdata = $request->{kitdata}; + if (! defined($kitdata)) { + $kitdata = xCAT::KitPluginUtils->get_kits_used_by_image_profiles([$imgprofilename]); + $request->{kitdata} = $kitdata; + } + + if ($PLUGIN_KITNAME ne "TESTMODE" && ! exists($kitdata->{$PLUGIN_KITNAME})) { + return; + } + + # Name of command and node list + my $command = $request->{command}->[0]; + my $args = $request->{arg}; + + if($command eq 'kitimagevalidatecomps') { + kitimagevalidatecomps($callback, $args); + } + elsif ($command eq 'kitimageimport') { + kitimageimport($callback, $args); + + } else { + my $rsp; + $rsp->{data}->[0] = "Command is not supported"; + xCAT::MsgUtils->message("E", $rsp, $callback); + } +} + + +#------------------------------------------------------- + +=head3 kitimagevalidatecomps + + This command is called to validate new changes to an + image profile's kit component list before the changes + are committed. + +=cut + +#------------------------------------------------------- + +sub kitimagevalidatecomps { + my $callback = shift; + my $args = shift; + my $rsp; + + # Parameters + my $imgprofilename = $args->[0]; + my $newcomplist = $args->[1]; + my @newcomplist = (); + if (defined($newcomplist)) { + @newcomplist = split(/,/, $newcomplist); + } + my $newosdistro = $args->[2]; + my $newosdistroupdate = $args->[3]; + + $rsp->{data}->[0] = "Running kitimagevalidatecomps"; + xCAT::MsgUtils->message("I", $rsp, $callback); + + # TODO + # ... ADD YOUR CODE HERE +} + + +#------------------------------------------------------- + +=head3 kitimageimport + + This command is called after changes to an image profile + have been committed. + +=cut + +#------------------------------------------------------- + +sub kitimageimport { + my $callback = shift; + my $args = shift; + my $rsp; + + # Parameters + my $imgprofilename = $args->[0]; + + $rsp->{data}->[0] = "Running kitimageimport"; + xCAT::MsgUtils->message("I", $rsp, $callback); + + # TODO + # ... ADD YOUR CODE HERE +} + + diff --git a/xCAT-buildkit/share/xcat/kits/kit_template/plugins/sample/nodemgmt.pm b/xCAT-buildkit/share/xcat/kits/kit_template/plugins/sample/nodemgmt.pm new file mode 100644 index 000000000..1eb766eb7 --- /dev/null +++ b/xCAT-buildkit/share/xcat/kits/kit_template/plugins/sample/nodemgmt.pm @@ -0,0 +1,251 @@ +package xCAT_plugin::<<>>_nodemgmt; + +use strict; +use warnings; + +require xCAT::Utils; +require xCAT::Table; +require xCAT::KitPluginUtils; + +# buildkit Processing +# In order to avoid collisions with other plugins, the package +# name for this plugin must contain the full kit name. +# The buildkit buildtar command will copy this file from your plugins +# directory to the the kit build directory, renaming the file with the +# correct kit name. All strings in this file of the form +# <<>> +# will be replaced with the full kit name. In order for buildkit to +# correctly edit this file, do not remove these strings. + +# Global Variables + +# This is the full name of the kit which this plugin belongs +# to. The kit name is used by some code in process_request() +# to determine if the plugin should run. When you are testing +# your plugin the kit name should be set to "TESTMODE" to +# bypass the plugin check in process_request(). + +our ($PLUGIN_KITNAME); +#$PLUGIN_KITNAME = "TESTMODE"; +$PLUGIN_KITNAME = "<<>>"; + + +#------------------------------------------------------- + +=head1 + + Node Management Kit Plugin + This plugin contains commands to run custom actions + during node management operations. + +=cut + +#------------------------------------------------------- + + +#------------------------------------------------------- + +=head3 handled_commands + + Return list of kit plugin commands handled by this plugin + +=cut + +#------------------------------------------------------- + +sub handled_commands { + return { + kitnodeadd => '<<>>_nodemgmt', + kitnoderemove => '<<>>_nodemgmt', + kitnodeupdate => '<<>>_nodemgmt', + kitnoderefresh => '<<>>_nodemgmt', + kitnodefinished => '<<>>_nodemgmt', + }; +} + + +#------------------------------------------------------- + +=head3 process_request + + Process the kit plugin command. + +=cut + +#------------------------------------------------------- + +sub process_request { + my $request = shift; + my $callback = shift; + + # Name of command and node list + my $command = $request->{command}->[0]; + my $nodes = $request->{node}; + + # This kit plugin is passed a list of node names. + # We need to determine which kits are used by these + # nodes to decide if this plugin should run or not. + + my $kitdata = $request->{kitdata}; + if (! defined($kitdata)) { + $kitdata = xCAT::KitPluginUtils->get_kits_used_by_nodes($nodes); + $request->{kitdata} = $kitdata; + } + + if ($PLUGIN_KITNAME ne "TESTMODE" && ! exists($kitdata->{$PLUGIN_KITNAME})) { + return; + } + + # Get the nodes using this plugin's kit + $nodes = $kitdata->{$PLUGIN_KITNAME}; + + + if($command eq 'kitnodeadd') { + kitnodeadd($callback, $nodes); + } + elsif ($command eq 'kitnoderemove') { + kitnoderemove($callback, $nodes); + } + elsif ($command eq 'kitnodeupdate') { + kitnodeupdate($callback, $nodes); + } + elsif ($command eq 'kitnoderefresh') { + kitnoderefresh($callback, $nodes); + } + elsif ($command eq 'kitnodefinished') { + kitnodefinished($callback); + + } else { + my $rsp; + $rsp->{data}->[0] = "Command is not supported"; + xCAT::MsgUtils->message("E", $rsp, $callback); + } +} + + +#------------------------------------------------------- + +=head3 kitnodeadd + + This command is called when one or more nodes are added + to the cluster. + +=cut + +#------------------------------------------------------- + +sub kitnodeadd { + my $callback = shift; + my $rsp; + + # Parameters + my $nodes = shift; + + $rsp->{data}->[0] = "Running kitnodeadd"; + xCAT::MsgUtils->message("I", $rsp, $callback); + + # TODO + # ... ADD YOUR CODE HERE +} + + +#------------------------------------------------------- + +=head3 kitnoderemove + + This command is called when one or more nodes are + removed from the cluster. + +=cut + +#------------------------------------------------------- + +sub kitnoderemove { + my $callback = shift; + my $rsp; + + # Parameters + my $nodes = shift; + + $rsp->{data}->[0] = "Running kitnoderemove"; + xCAT::MsgUtils->message("I", $rsp, $callback); + + # TODO + # ... ADD YOUR CODE HERE +} + + +#------------------------------------------------------- + +=head3 kitnodeupdate + + This command is called when the configuration of one + or more nodes are updated. + +=cut + +#------------------------------------------------------- + +sub kitnodeupdate { + my $callback = shift; + my $rsp; + + # Parameters + my $nodes = shift; + + $rsp->{data}->[0] = "Running kitnodeupdate"; + xCAT::MsgUtils->message("I", $rsp, $callback); + + # TODO + # ... ADD YOUR CODE HERE +} + + +#------------------------------------------------------- + +=head3 kitnoderefresh + + This command is called when node-related configuration + files are updated. + +=cut + +#------------------------------------------------------- + +sub kitnoderefresh { + my $callback = shift; + my $rsp; + + # Parameters + my $nodes = shift; + + $rsp->{data}->[0] = "Running kitnoderefresh"; + xCAT::MsgUtils->message("I", $rsp, $callback); + + # TODO + # ... ADD YOUR CODE HERE +} + + +#------------------------------------------------------- + +=head3 kitnodefinished + + This command is called at the end of a node management + operation. + +=cut + +#------------------------------------------------------- + +sub kitnodefinished { + my $callback = shift; + my $rsp; + + $rsp->{data}->[0] = "Running kitnodefinished"; + xCAT::MsgUtils->message("I", $rsp, $callback); + + # TODO + # ... ADD YOUR CODE HERE +} + diff --git a/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/post.sh b/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/post.sh new file mode 100755 index 000000000..2fa3d84e1 --- /dev/null +++ b/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/post.sh @@ -0,0 +1,3 @@ + +echo "running sample-comp1 post script" + diff --git a/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/postboot.sh b/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/postboot.sh new file mode 100755 index 000000000..abbcb3e56 --- /dev/null +++ b/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/postboot.sh @@ -0,0 +1,3 @@ +#!/bin/sh +echo "running sample-comp1 postboot script" + diff --git a/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/postun.sh b/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/postun.sh new file mode 100755 index 000000000..a5596e931 --- /dev/null +++ b/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/postun.sh @@ -0,0 +1,3 @@ + +echo "running sample-comp1 postun script" + diff --git a/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/postup.sh b/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/postup.sh new file mode 100755 index 000000000..a4ad3c500 --- /dev/null +++ b/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/postup.sh @@ -0,0 +1,3 @@ + +echo "running sample-comp1 postup script" + diff --git a/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/pre.sh b/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/pre.sh new file mode 100755 index 000000000..36a88c970 --- /dev/null +++ b/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/pre.sh @@ -0,0 +1,3 @@ + +echo "running sample-comp1 pre script" + diff --git a/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/preun.sh b/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/preun.sh new file mode 100755 index 000000000..e94c3aa8e --- /dev/null +++ b/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/preun.sh @@ -0,0 +1,3 @@ + +echo "running sample-comp1 preun script" + diff --git a/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/preup.sh b/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/preup.sh new file mode 100755 index 000000000..bf2248496 --- /dev/null +++ b/xCAT-buildkit/share/xcat/kits/kit_template/scripts/sample/preup.sh @@ -0,0 +1,3 @@ + +echo "running sample-comp1 preup script" + diff --git a/xCAT-buildkit/share/xcat/kits/kit_template/source_packages/sample/pkg1/pkg1-1-1.noarch.rpm b/xCAT-buildkit/share/xcat/kits/kit_template/source_packages/sample/pkg1/pkg1-1-1.noarch.rpm new file mode 100644 index 0000000000000000000000000000000000000000..8bffe202d515026e040e8941ae8fa8ce222e4d62 GIT binary patch literal 3212 zcmbuB32YQq7{}jsx22R~OTbtPDPzR|%HG$kZKVgj0A;lVQ2{$U^QN7!mpi+)tzfJu zl+;jyg%|>w)PqxlgeEGQG%7;CgD9ZI6N?p)qJn7&k=E~j}P=lO5+1WI~%S(Vjjy$34dO%)wU9RA$eH%{x=J+v)=dN0&bP-jC;Cqy?EGzlse z@YSCNH9(!o_#7zuTcCo!{x?vx=R?&=)aszrM(uVhFWY&KOdXWBIy_W%xkb_DvRj=z z?-nKSg)%0(YGre*Z^iFdzUWk3n_ro^8bYlDgO*c&fB$Z1Lmz|;$$J*0R}Hs7F^{B0 zpy-1!lc8c6$Q#Fz!1xR(GUkrv_cG%?#;-B%XS^%UmDJ1O43wjQ*9NFcw1wDBAs?`20jr zv^O%&jI#mf0qxU4A--V}D8|oYd^=;@lW3p8822ACzMtry&)CDbgmD4mQc%dpPzj3t zl`&qH!V$`;RK%FsDb#;W1lxa&5DO2+kd>QCBcw(LV_ZLv5r+aXhGjDH zpku+S-I0;JFy0V1TqE2vBrC4i))>!;^n&h&R|~rF*8o3s8!Wiy-sc*3#ueKdpMZOv zL=3lDpCCOejz~B z8HCxqLY+S(Xa==RsG;5nm6h77=7lt(!fQaK*)&Xp5)Fz9K8(d~vX~t3J>)Q1;EH6| zh&NeAOlTm{f4=OT)$X)-Y`oinCpJljL61- zw5)l#;~uO0sibjA`pF+Vb1F@(txcns>@js5?>pXSU(}wEPWYAl(X5O^`sJ=nUGpW| zQ{Vma@oIf! zF+Z))P~OyZ$liM4g{eEkoKFD8!FC~9=G9dp1Ci(m6+E01mHGIH@wXgH%@}58Y`Zq>N{%YZU zJoV@K`@D&%?a0TUe|tNS*t7cA3$HO-|9aa0i(CCW)PD-0{`FY@XaIjE)PGesG5-NR zI{#T;|ICHM`7ebr|Iqzq5@C(m{%?wh{Iz37|4(6+%SE)Ms_*Kyq3}JZ`vJ#600000 V00000004mBbp@$}BI*Dr008!Zj{X1u literal 0 HcmV?d00001 diff --git a/xCAT-buildkit/share/xcat/kits/kit_template/source_packages/sample/pkg4/pkg4-1-1.src.rpm b/xCAT-buildkit/share/xcat/kits/kit_template/source_packages/sample/pkg4/pkg4-1-1.src.rpm new file mode 100644 index 0000000000000000000000000000000000000000..8833a5c555a31f164a1a6bdd3ca3bd77cbf322fd GIT binary patch literal 2516 zcmbW3d010d8pdw`F%?imP^eNu1%xq#tdIZ#ia?O1SP&_jWVwMrLP8QSP+FiAtbmGZ z>k6$%E!05~RB&MtAIk)9H>P z8ja3p0WTQDYpx~X#@5|xTB%)b*_)iu)nMv+kXWc`et!NuxCU!r*gJKDItbn1mOBVg z2jQPUp+^XU2m+2j>W2H!LOcuDtOpdX*NzzW2{6G3F??=-pJ0r58OpCg z4EqTEHi%7tLO&I;DPlHI&_5kBpwRD%_*N)gE5&M{qo1ul%^sW9J70VGeELQcWFg8bj1jdHm}Ea0icvP7jr zaH>*;OBafxsCWuWY#JsJCnl@0L>W&Zhy(L2as=hB%qqz$fwKqY2<7%kgv zATGVQGi9Ai#;38Oi@5oAepzXpKQn&QS2i{t^(DILmWI|Vi`3_v40lhFc60X_oHfm^ z_Iu#M7_HQ+dZ@M#wQiW4Ngs4sw<}+htGtVlmUfLuvI{T7tZeC(~pG+p- z8lk54?C)KC;9B9}MPf@##w4ldH1B$LNiZY)V5tw?pSY-oM_&A}G=bZFPT!-}wn*x8L7y35Dv3n}F$JiYwiC*k4CnR{z zaBZu~@Zw*Czjw|JSsa(8zpK`$CUb(l_O40ly{3qxEhjA%?)$QwRqc1o?fccNe4+ib z_?5PmlUL`j z@jCRNantYmGk?;5o$;;Z=jR$fv2X6pByvrD{5UJEyCJ(SuV%U{W|?hXLeGPAziDTq z@d+ih^XZM1$0n*TQ|$7(RF5s=2cNC*jlWy%w<91>nP71xU302u-YYu&^8D!=cQkKr zPi9P4Ucv|M=Ewgvl`WeKerR6%vSaq}NW-47&tkLhPmZ>@+x|vh|KsuL{^1pE*K-Dj zd~R&0GgK?$Cc-}&;P&kf-+a|=K6)g6Tz|)>Pu|>3{v`$>^a6fSFLf`AU zhklpc91{&n974O6I?Np?dty7Gxz*JX`FT=6@};znolhzP-c}5{A2$tiy(X_p_>fFF zAShGcSi5RXqD`?q9czPH&kXSlbag82Z9@{rB6h ey0mpx76vAduS*MdD{8wvYhm8sJXH_=ZTt?aGT|Qp literal 0 HcmV?d00001 diff --git a/xCAT-buildkit/share/xcat/kits/kitcomponent.spec.template b/xCAT-buildkit/share/xcat/kits/kitcomponent.spec.template new file mode 100644 index 000000000..70c948cbb --- /dev/null +++ b/xCAT-buildkit/share/xcat/kits/kitcomponent.spec.template @@ -0,0 +1,48 @@ +Summary: Kit <<>> Component <<>> metapackage +Name: <<>> +Version: <<>> +Release: <<>> +License: EPL +BuildArch: noarch +Requires: <<>>,<<>>,<<>> + +%description +<<>> + +%prep +%build +%install + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +%defattr(-,root,root) + +%changelog + +%pre +if [ "$1" = "1" ] ; then +<<>> + + +elif [ "$1" = "2" ] ; then +<<>> + +fi + +%post +if [ "$1" = "1" ] ; then +<<>> + +elif [ "$1" = "2" ] ; then +<<>> + +fi + +%preun +<<>> + +%postun +<<>> + diff --git a/xCAT-buildkit/xCAT-buildkit.spec b/xCAT-buildkit/xCAT-buildkit.spec new file mode 100644 index 000000000..6010c2088 --- /dev/null +++ b/xCAT-buildkit/xCAT-buildkit.spec @@ -0,0 +1,93 @@ +Summary: xCAT buildkit tools and sample kit +Name: xCAT-buildkit +Version: %(cat Version) +Release: snap%(date +"%Y%m%d%H%M") +Epoch: 4 +License: EPL +Group: Applications/System +Source: xCAT-buildkit-%(cat Version).tar.gz +Packager: IBM Corp. +Vendor: IBM Corp. +Distribution: %{?_distribution:%{_distribution}}%{!?_distribution:%{_vendor}} +Prefix: /opt/xcat +BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root + +#%ifnos linux +AutoReqProv: no +#%endif + +# AIX will build with an arch of "ppc" +# also need to fix Requires for AIX +%ifos linux +BuildArch: noarch +#Requires: +%endif + +# No dependencies on any other xCAT rpms +# so that this rpm can be installed in a separate build server +Requires: rpm-build + +Provides: xCAT-buildkit = %{epoch}:%{version} + +%description +xCAT-buildkit provides the buildkit tool and sample kit files to build an xCAT kit. + +%prep +%setup -q -n xCAT-buildkit +%build +%install +rm -rf $RPM_BUILD_ROOT +mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/xcat/kits +mkdir -p $RPM_BUILD_ROOT/%{prefix}/bin +mkdir -p $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT + +%ifos linux +cp -aR share/xcat/kits/* $RPM_BUILD_ROOT/%{prefix}/share/xcat/kits/ +chmod -R 644 $RPM_BUILD_ROOT/%{prefix}/share/xcat/kits/* +cp -a lib/perl/xCAT/* $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT +chmod -R 644 $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT/* +cp -a bin/* $RPM_BUILD_ROOT/%{prefix}/bin/ +chmod -R 755 $RPM_BUILD_ROOT/%{prefix}/bin/* +%else +cp -hpR share/xcat/kits/* $RPM_BUILD_ROOT/%{prefix}/share/xcat/kits/ +chmod -R 644 $RPM_BUILD_ROOT/%{prefix}/share/xcat/kits/* +cp -hpR lib/perl/xCAT/* $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT/ +chmod -R 755 $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT/* +cp -hpR bin/* $RPM_BUILD_ROOT/%{prefix}/bin/ +chmod -R 755 $RPM_BUILD_ROOT/%{prefix}/bin/* +%endif + +mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/doc/packages/xCAT-buildkit +cp LICENSE.html $RPM_BUILD_ROOT/%{prefix}/share/doc/packages/xCAT-buildkit +chmod 644 $RPM_BUILD_ROOT/%{prefix}/share/doc/packages/xCAT-buildkit/* +echo $RPM_BUILD_ROOT %{prefix} + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +%defattr(-,root,root) +#%doc LICENSE.html +%{prefix} + +%changelog + +%pre +# only need to check on AIX +%ifnos linux +if [ -x /usr/sbin/emgr ]; then # Check for emgr cmd + /usr/sbin/emgr -l 2>&1 | grep -i xCAT # Test for any xcat ifixes - msg and exit if found + if [ $? = 0 ]; then + echo "Error: One or more xCAT emgr ifixes are installed. You must use the /usr/sbin/emgr command to uninstall each xCAT emgr ifix prior to RPM installation." + exit 2 + fi +fi +%endif + +%post + +%preun + + + + diff --git a/xCAT-buildkit/xCAT-buildkit.spec.broken b/xCAT-buildkit/xCAT-buildkit.spec.broken new file mode 100644 index 000000000..53e190eea --- /dev/null +++ b/xCAT-buildkit/xCAT-buildkit.spec.broken @@ -0,0 +1,86 @@ +Summary: xCAT buildkit tools and sample kit +Name: xCAT-buildkit +Version: %(cat Version) +Release: snap%(date +"%Y%m%d%H%M") +Epoch: 4 +License: EPL +Group: Applications/System +Source: xCAT-buildkit-%(cat Version).tar.gz +Packager: IBM Corp. +Vendor: IBM Corp. +Distribution: %{?_distribution:%{_distribution}}%{!?_distribution:%{_vendor}} +Prefix: /opt/xcat +BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root + +%ifnos linux +AutoReqProv: no +%endif + +# AIX will build with an arch of "ppc" +# also need to fix Requires for AIX +%ifos linux +BuildArch: noarch +#Requires: +%endif + +# No dependencies on any other xCAT rpms +# so that this rpm can be installed in a separate build server +Requires: rpm-build + +Provides: xCAT-buildkit = %{epoch}:%{version} + +%description +xCAT-buildkit provides the buildkit tool and sample kit files to build an xCAT kit. + +%prep +%setup -q -n xCAT-buildkit +%build +%install +rm -rf $RPM_BUILD_ROOT +mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/xcat/kits +mkdir -p $RPM_BUILD_ROOT/%{prefix}/bin + +%ifos linux +cp -aR share/xcat/kits/* $RPM_BUILD_ROOT/%{prefix}/share/xcat/kits/ +chmod -R 644 $RPM_BUILD_ROOT/%{prefix}/share/xcat/kits/* +cp -a bin/* $RPM_BUILD_ROOT/%{prefix}/bin/ +chmod -R 755 $RPM_BUILD_ROOT/%{prefix}/bin/* +%else +cp -hpR share/xcat/kits/* $RPM_BUILD_ROOT/%{prefix}/share/xcat/kits/ +chmod -R 755 $RPM_BUILD_ROOT/%{prefix}/share/xcat/kits/* +%endif + +mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/doc/packages/xCAT-buildkit +cp LICENSE.html $RPM_BUILD_ROOT/%{prefix}/share/doc/packages/xCAT-buildkit +chmod 644 $RPM_BUILD_ROOT/%{prefix}/share/doc/packages/xCAT-buildkit/* +echo $RPM_BUILD_ROOT %{prefix} + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +%defattr(-,root,root) +#%doc LICENSE.html +%{prefix} + +%changelog + +%pre +# only need to check on AIX +%ifnos linux +if [ -x /usr/sbin/emgr ]; then # Check for emgr cmd + /usr/sbin/emgr -l 2>&1 | grep -i xCAT # Test for any xcat ifixes - msg and exit if found + if [ $? = 0 ]; then + echo "Error: One or more xCAT emgr ifixes are installed. You must use the /usr/sbin/emgr command to uninstall each xCAT emgr ifix prior to RPM installation." + exit 2 + fi +fi +%endif + +%post + +%preun + + + +