+ Reply to Thread
Results 1 to 5 of 5

Thread: Script that converts a Roll to a Kit

  1. #1
    job+2 Guest

    Default Script that converts a Roll to a Kit

    Here's a bare bones script which can convert a roll (at least one) to a kit. I know it needs to be enhanced to support every possible roll one might want to convert. Let's consider this a "pre-alpha" (or prototype) version.

    Also, I know this should be written in Python, but I'm much faster in perl.

    Anyone have ideas/suggestions/improvements please don't be shy.


    #!/usr/bin/perl
    # roll2kit.pl
    # written by Job

    use File::Copy;

    $buildkit = "/opt/kusu/bin/buildkit";

    if (@ARGV == 0) {
    print "Usage: $0 iso\n";
    exit(1)
    }

    chdir("/tmp");

    # remove the path leaving only the iso name
    $iso = $ARGV[0];
    $isopath = $iso;
    $iso =~ s/.*\/(w+)/$1/;

    # extract
    ($name, $version, $rest) = split(/-/,$iso);
    ($release, $arch, $disk, $type) = split(/\./,$rest);

    # mount the roll
    system("mount -o loop $isopath /media");
    foreach $_ (`find /media -name '*.rpm'`) {
    unless (/kickstart/) {
    chomp;
    $rpmpath = $_;
    s/.*\/(.*\.rpm)/$1/;
    push(@rpms, $_);
    }
    }

    # build the kit
    system("$buildkit new kit=$name");

    chdir("$name");

    # copy the rpm(s) into the kitname/sources directory
    copy($rpmpath,"sources");

    # unmount the iso
    system("umount /media");

    rename("build.kit", "build.kit.orig");
    open(KIT, "build.kit.orig");

    # open the build.kit file for writing
    open(BUILDKIT, ">build.kit");

    @lines = <KIT>;
    foreach (@lines) {
    if (s/^#(pkg1\s=\s)(SourcePackage)/$1RPMPackage/) {
    print BUILDKIT;
    } elsif (s/^#(pkg1.name\s=\s')(foo)/${1}${name}/) {
    print BUILDKIT;
    } elsif (s/^#(pkg1.version\s=\s')(1.0)/${1}${version}/) {
    print BUILDKIT;
    } elsif (s/^#(pkg1.release\s=\s')(0)/${1}${release}/) {
    print BUILDKIT;
    } elsif (s/^#(pkg1.filename\s=\s')(foo-1.0.tar.gz)/${1}${rpms[0]}/) {
    print BUILDKIT;
    } elsif (s/^#(comp.*)/$1/) {
    print BUILDKIT;
    } else {
    print BUILDKIT;
    }
    }
    close(BUILDKIT);
    close(KIT);

    chdir("sources");
    move("00-post-script.sh", "00-post-script.sh.orig");
    open(POST, ">00-post-script.sh");

    print POST "#!/bin/sh\n";
    print POST "# In Kusu Installer mode?\n";
    print POST "# Do not change the following line!\n";
    print POST "if [ -e /var/lock/subsys/kusu-installer ]; then exit 0; fi\n";

    print POST "PATH=\$PATH:/opt/kusu/sbin\n";
    print POST "export PATH\n";
    print POST "if [ -d /opt/kusu/lib ]; then\n";
    print POST " PYTHONPATH=/opt/kusu/lib64/python:/opt/kusu/lib/python:\n";
    print POST "else\n";
    print POST " PYTHONPATH=FIX_ME\n";
    print POST "fi\n";
    print POST "export PYTHONPATH\n";

    print POST "# Make the component entries because kitops is broken!!!\n";
    print POST "KID=`/opt/kusu/sbin/sqlrunner -q \"SELECT kid FROM kits WHERE rname='".$name."' and version='".$version."'\"`\n";
    print POST "if [ \$? -ne 0 ]; then\n";
    print POST " exit 0\n";
    print POST "fi\n";

    print POST "/opt/kusu/sbin/sqlrunner -q \"DELETE FROM components WHERE kid=\$KID\"\n";
    print POST "/opt/kusu/sbin/sqlrunner -q \"INSERT into components set cname='component-".$name."', cdesc='".$name." component for RHEL5.', kid=\$KID, os='rhel-5-x86_64'\"\n";

    print POST "CID1=`/opt/kusu/sbin/sqlrunner -q \"SELECT cid from components where kid=\$KID and cname='component-".$name."' and os=(select repos.ostype from repos, nodegroups WHERE nodegroups.ngid=2 AND nodegroups.repoid=repos.repoid)\"`\n";

    print POST "if [ \"x\$CID1\" = \"x\" ]; then\n";
    print POST " # The kit provides components that are not used with the installers OS#\n";
    print POST " exit 0\n";
    print POST "fi\n";

    print POST "# Setup the kit\n";
    print POST "/opt/kusu/sbin/sqlrunner -q \"UPDATE kits SET arch='x86_64' WHERE rname='".$name."'\"\n";

    print POST "# SQL/Shell/Python code to update the database.. The updates may optionally\n";
    print POST "# include Node group creation and component association\n";
    print POST "/opt/kusu/sbin/sqlrunner -q \"INSERT INTO ng_has_comp SET ngid = 2, cid = \$CID1\"\n";

    print POST "#if [ ! -e /var/lock/subsys/kusu-installer ]; then\n";
    print POST " # Running outside of Anaconda\n";
    print POST "# if [ -f /etc/rc.kusu.d/S15-ntop.rc.py ]; then\n";
    print POST "# echo \"Running Kusu RC Script: Ntop\"\n";
    print POST "# /opt/kusu/bin/kusurc /etc/rc.kusu.d/S15-ntop.rc.py\n";
    print POST "# fi\n";
    print POST "#else\n";
    print POST " # Running within Anaconda\n";
    print POST "#fi\n";

    close(POST);

    # change to /tmp. Then provide help for the next steps
    chdir("/tmp");
    system("buildkit make kit=$name");

  2. #2
    mblack is offline Junior Member
    Join Date
    April 15th, 2008
    Posts
    11
    Downloads
    0
    Uploads
    0

    Default

    Way cool! This should work well with the rolls that deliver rpm's, like most of the application ones (Java, maybe Fluent). Rolls needing configuration will need some way of creating the plugins for generating the files they need.

  3. #3
    job+2 Guest

    Default Can you elaborate?

    Mark,

    I want the roll2kit script to work in all, or as many as possible situations. I realized when I posted this that it wouldn't do so in its current state, but I need more information to make it more robust.

    For example, Consider this block:

    if [ ! -e /var/lock/subsys/kusu-installer ]; then
    # Running outside of Anaconda\n";
    if [ -f /etc/rc.kusu.d/S15-ntop.rc.py ]; then
    echo "Running Kusu RC Script: Ntop"
    /opt/kusu/bin/kusurc /etc/rc.kusu.d/S15-ntop.rc.py
    fi
    else
    # Running within Anaconda
    fi

    Is the file S15-ntop.rc.py a plug-in? What does this block do?
    In fact, I'm at a loss regarding the purpose of the entire 00-post-script.sh. I can see what it does, but why do the database tables need to manually operated on in this way? None of this is mentioned in the excellent "how to build a kit" post.

    Thanks,

    Job

  4. #4
    mikem's Avatar
    mikem is offline Project Moderator
    Join Date
    April 10th, 2008
    Posts
    22
    Blog Entries
    9
    Downloads
    0
    Uploads
    0

    Default

    The file 00-post-script.sh is packaged up as the %post section in the kit RPM. When the kit is added, this %post script is run. Putting SQL statements in the post script to operate on the DB tables is one way to automate some kit configuration.

    We have had ideas to provide some such configuration capabilities (such as associating kit components to certain nodegroups or creating new nodegroups) in the kitinfo file, though currently I don't think that's being worked on.

  5. #5
    mblack is offline Junior Member
    Join Date
    April 15th, 2008
    Posts
    11
    Downloads
    0
    Uploads
    0

    Default

    The kit can be added in two ways:
    1. During normal installation.
    2. Added after installation.

    The /etc/rc.kusu.d directory is a means of dealing with the post installation steps that are needed to add a component, instead of modifying the kickstart file.

    The: if [ ! -e /var/lock/subsys/kusu-installer ]; then
    tests to see if we are installing with Anaconda. Not all services are available when Anaconda is installing, like the database, so we have to defer execution till all the services are available. This is where the /etc/rc.kusu.d directory comes in. Files deposited here get run when the machine reboots. They may also get run in the post section of the kit rpm, if the kit is added after.

    For converting existing Rolls it should be possible to extract the post installation steps form the roll rpm, and put that into a kusu.rc script. This would work for the simple rolls that mostly deliver packages, but would break when there is some additional cluster information needed.

    M.
    Last edited by mblack; May 26th, 2008 at 07:38 PM.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts