Forum: Cfengine Help
Subject: Re: Lengthy in-line bash commands
Author: sauer
Link to topic: https://cfengine.com/forum/read.php?3,22195,22275#msg-22275
So, basically you're doing
create base source directory
either update the existing source or check the source out depending on whether
or not directory exists
run a few build commands in the source directory
I'm thinking something like this would be a good start to doing it with little
to no external scripting, if you're dead set on getting rid of the shell script.
bundle agent build {
vars:
# base build dir
"base" string => "/tmp/build";
# classname prefix so builddir can communicate w/ dosrc
"pre" string => "has_dir_";
# list o' packages
"pkgs" slist => { "pkga", "pkgb" };
# default commands
"defget" string => "cvs co";
"defupd" string => "cvs update -d -P";
"defmake" string => "make all";
"definst" string => "make install";
# package-specific commands
"make" string => "crazymake arg arg arg";
"inst" string => "cp -a . /tmp/deleteme";
methods:
"dirtest" usebundle => checkdir("$(pkgs)");
"dirs" usebundle => builddir("$(pkgs)");
"build" usebundle => dobuilds("$(pkgs)");
}
# gotta be a common bundle so other bundles can see the class :/
bundle common checkdir(p){
vars:
"classname" string => canonify("$(build.pre)$(p)");
classes:
"$(classname)" expression => isdir("$(build.base)/$(p)/");
}
# create basedir, maybe set some permissions
bundle agent builddir(pkg){
files:
"$(build.base)/." create => "true";
#"$(build.base)/$(pkg)/." create => "true";
}
# just a wrapper to allow default or overridden values
bundle agent dobuilds(pkg){
vars:
"classname" string => canonify( "$(build.pre)$(pkg)" );
classes:
"hasget" expression => isvariable("build.get[$(pkg)]" );
"hasupd" expression => isvariable("build.upd[$(pkg)]" );
"hasmake" expression => isvariable("build.make[$(pkg)]");
"hasinst" expression => isvariable("build.inst[$(pkg)]");
methods:
# get or update source
hasget:: "get" usebundle => runcmd("$(pkg)", "$(build.get[$(pkg)])"),
ifvarclass => "!$(classname)";
!hasget:: "get" usebundle => runcmd("$(pkg)", "$(build.defget)" ),
ifvarclass => "!$(classname)";
hasupd:: "upd" usebundle => runcmd("$(pkg)", "$(build.upd[$(pkg)])"),
ifvarclass => "$(classname)";
!hasupd:: "upd" usebundle => runcmd("$(pkg)", "$(build.defupd)" ),
ifvarclass => "$(classname)";
# make
hasmake:: "make" usebundle => runcmd("$(pkg)", "$(build.make[$(pkg)])" );
!hasmake:: "make" usebundle => runcmd("$(pkg)", "$(build.defmake)" );
# install
hasinst:: "inst" usebundle => runcmd("$(pkg)", "$(build.inst[$(pkg)])" );
!hasinst:: "inst" usebundle => runcmd("$(pkg)", "$(build.definst)" );
}
# run actual command
bundle agent runcmd(pkg, cmd){
commands:
!done:: "$(cmd)" contain => in_dir("$(build.base)/$(pkg)"),
classes => if_ok("done");
}
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine