Compare commits

...

5 Commits

Author SHA1 Message Date
Tobias Herre 2b52e5e413 Inital commit 2023-10-11 11:30:20 +02:00
Tobias Herre 96199c894f Inital commit 2023-10-11 11:28:59 +02:00
Tobias Herre e3c022990f Inital commit 2023-10-11 11:28:28 +02:00
Tobias Herre 8a5bd2fb10 contain with useshell added 2023-10-11 11:26:47 +02:00
Tobias Herre 453e7c2a0e contain with predefined useshell added 2023-10-11 11:25:38 +02:00
7 changed files with 387 additions and 4 deletions

View File

@ -63,10 +63,14 @@ bundle agent certbot_cert(site,webroot)
vars:
"domain" string => "$(site[domain])";
"ds" slist => {"$(site[domain])"};
"domains" slist => sort(mergedata(@(ds),getvalues(@(site[aliases]))));
"site_json" string => storejson(@(site));
"args" string => string_mustache(
"-d {{domain}} {{#aliases}} -d {{.}} {{/aliases}}",
"--cert-name {{domain}} -d {{domain}} {{#aliases}} -d {{.}} {{/aliases}}",
@(site)
);
@ -108,6 +112,7 @@ commands:
args => "certonly --agree-tos -n $(webroot_arg) --expand --email $(site[email]) $(args)";
reports:
# "DOMAINS FOR: $(site[domain]) $(domains)";
}

4
lib.cf
View File

@ -112,4 +112,8 @@ reports:
}
body contain wmde_cmd_useshell
{
useshell=>"useshell";
}

View File

@ -16,24 +16,31 @@ vars:
"cfg_file" string => "/usr/local/etc/mysql/my.cnf";
"mysql_cmd" string => "/usr/local/bin/mysql";
debian::
"pkg" string => "mariadb-server";
"pkg" slist => {"mariadb-common", "mariadb-client", "mariadb-server"};
"service_name" string => "mysql";
"cfg_file" string => "/etc/mysql/my.cnf";
"mysql_cmd" string => "/usr/bin/mysql";
commands:
# debian&mysql_repaired::
# "/usr/bin/mysql_install_db"
# depends_on => { "mysql_pkgs_installed" },
# handle => "mysql_db_installed";
files:
"$(cfg_file)"
create => "true",
perms => m("644"),
edit_template => "$(sys.workdir)/inputs/$(def.wmde_libdir)/templates/my.cnf.mustache",
template_method => "mustache",
handle => "mysql_cfg_created",
depends_on => {"mysql_pkgs_installed"},
# depends_on => {"mysql_db_installed"},
classes => if_repaired("mysql_repaired");
methods:
"any" usebundle => wmde_install_packages("$(mysql.pkg)","mysql");
"any" usebundle => wmde_install_packages(@(mysql.pkg),"mysql"),
depends_on => { "mysql_cfg_created" };
services:
"$(service_name)"
@ -49,6 +56,52 @@ services:
}
body contain mysql_cmd
{
useshell=>"useshell";
}
bundle agent mysql_table_exists(dbdef,table_name)
{
vars:
"pass_arg" string => ifelse ( isvariable("dbdef[db_pass]"),
"-p$(dbdef[db_pass])",""
);
"host_arg" string => ifelse ( isvariable("dbdef[db_host]"),
"-h$(dbdef[db_host])",""
);
"user_arg" string => ifelse ( isvariable("dbdef[db_user]"),
"-u$(dbdef[db_user])",""
);
"xargs" string => "$(pass_arg) $(host_arg) $(user_arg)";
"classname" string => "mysql_$(dbdef[db_name])_$(table_name)_exists";
"cmd" string => 'if mysql $(xargs) -e "show tables LIKE \'$(table_name)\'" $(dbdef[db_name]) | grep -q \'$(table_name)\'; then echo "+$(classname)"; else echo "-$(classname)"; fi';
#"cmd" string => '"if mysql -e \\\"show tables"';
# "cmdfile" string => hash("$cmd)","sha256");
#files:
# "/tmp/$(cmdfile)"
# create => "true",
# content => "$(cmd)",
# handle => "mysql_$(cmdfile)_created";
commands:
"$(cmd)"
contain => mysql_cmd,
inform => "false",
module => "true";
reports:
# "CMD: $(cmd)";
}
bundle agent create_mysql_db(cfg)
{
vars:
@ -65,5 +118,7 @@ commands:
args => "$(args)",
inform => "false";
#mysql -u <username> -p -e "USE <database_name>;" && mysql -u <username> -p -e "SHOW TABLES LIKE '<table_name>';" | grep -q '<table_name>' && exit 0 || exit 1
reports:
}

135
php.cf Normal file
View File

@ -0,0 +1,135 @@
#
#
#
bundle agent install_php
{
vars:
debian::
"version" string => "8.2";
ubuntu_20::
"version" string => "7.4";
ubuntu_22::
"version" string => "8.1";
freebsd::
"version" string => "7.4";
freebsd::
"cli_exe" string => "/usr/local/bin/php";
"pkgs" slist => {
"php74-session",
"php74-zip",
"php74-pgsql",
"php74-mysqli",
"php74-pdo_mysql",
"php74-pdo",
"php74-filter",
"php74-json",
};
debian::
"pkgs" slist => {
"php-cli",
"php$(version)-common",
"php$(version)-zip",
"php$(version)-pgsql",
"php$(version)-mysql",
"php-json",
"php$(version)-xml",
};
ubuntu::
"pkgs" slist => {
"php$(version)-common",
"php$(version)-zip",
"php$(version)-pgsql",
"php$(version)-mysql",
"php$(version)-xml",
"php$(version)-mbstring",
"php-geshi",
"php-json",
"php-gd",
};
packages:
freebsd::
"$(pkgs)"
policy => "present",
package_module => pkg,
classes => if_repaired(php_changed);
debian::
"$(pkgs)"
policy => "present",
package_module => apt_get,
handle => "php_installed",
classes => if_repaired(php_changed);
}
bundle agent php(settings)
{
vars:
debian::
"ini_files" slist => {
"/etc/php/$(install_php.version)/apache2/php.ini",
"/etc/php/$(install_php.version)/fpm/php.ini"
};
"cli_exe" string => "/usr/bin/php";
freebsd::
"ini_files" slist => {
"/etc/php/$(install_php.version)/apache2/php.ini",
"/etc/php/$(install_php.version)/fpm/php.ini"
};
"cli_exe" string => "/usr/local/bin/php";
files:
"$(ini_files)"
create => "true",
edit_template => "$(sys.workdir)/inputs/$(wmde_libdir)/templates/php.ini.mustache",
template_method => "mustache",
template_data => @(settings),
classes => if_repaired(php_changed);
methods:
"any" usebundle => install_php;
reports:
"PHP VERSION: $(ini_files) V:$(install_php.version)";
}
bundle agent php_composer(cfg)
{
vars:
"installer" string => "$(sys.workdir)/data/php/composer-setup.php";
"exe" string => "/usr/local/bin/composer";
classes:
"php_composer_install" expression => not(fileexists("$(exe)"));
vars:
files:
"$(sys.workdir)/data/php/."
create => "true",
handle => "php_dir_created";
commands:
php_composer_install::
"$(wget.exe) -q -O $(installer) https://getcomposer.org/installer"
handle => "php_composer_installer_downloaded",
depends_on => {"php_dir_created"};
"$(php.cli_exe) $(installer) --install-dir=/usr/local/bin --filename=composer"
handle => "php_composer_installed",
depends_on => {"php_composer_installer_downloaded"};
methods:
"any" usebundle => install_php;
"any" usebundle => install_wget;
}

22
templates/my.cnf.mustache Normal file
View File

@ -0,0 +1,22 @@
#
# Managed by CFEngine
#
[client-server]
port = {{vars.mysql.port}}
socket = /run/mysqld/mysqld.sock
#[mysql]
#prompt = \u@\h [\d]>\_
#no_auto_rehash
[mysqld]
log-error =/var/log/mysql/mysqld.log
user = {{vars.mysql.user}}
port = {{vars.mysql.port}}
bind-address = 127.0.0.1
lower_case_table_names = 1

142
vimbadmin.cf Normal file
View File

@ -0,0 +1,142 @@
#
#
#
bundle agent vimbadmin(cfg)
{
vars:
"r" int => randomint(1,5),
handle => "rand_assigned";
"vsettings[resources.doctrine2.connection.options.driver]" string => "'$(cfg[db_driver])'";
"vsettings[resources.doctrine2.connection.options.dbname]" string => "'$(cfg[db_name])'";
"vsettings[resources.doctrine2.connection.options.user]" string => "'$(cfg[db_user])'";
"vsettings[resources.doctrine2.connection.options.password]" string => "'$(cfg[db_pass])'";
"vsettings[resources.doctrine2.connection.options.host]" string => "'$(cfg[db_host])'";
"vsettings[securitysalt]" string => "'$(cfg[security_salt])'";
"vsettings[resources.auth.oss.rememberme.salt]" string => "'$(cfg[rememberme_salt])'";
"vsettings[defaults.mailbox.password_salt]" string => "'$(cfg[password_salt])'";
"vsettings[skipInstallPingback]" string => "1";
classes:
"vimbadmin_checked_out" expression => fileexists("$(cfg[dst_dir])/.git");
"pull_it" expression => eval("1 == $(r)","class","infix"),
depends_on => {"rand_assigned"};
"vimbadmin_reconfigure" expression =>
or(
not(fileexists("$(sys.workdir)/data/agent/vimbadmin/configured.txt")),
not(fileexists("$(cfg[install_dir])/public"))
);
vars:
"clone_cmd" string => "$(git.exe) clone $(cfg[clone_args]) $(cfg[src]) $(cfg[dst_dir])";
files:
"$(sys.workdir)/data/public/."
create => "true",
perms => m(755),
handle => "vimbadmin_workdir_created";
"$(sys.workdir)/data/public/vimbadmin.tgz"
copy_from => sync_cp("$(cfg[src_tgz])","$(sys.policy_hub)"),
handle => "vimbadmin_tgz_copied",
depends_on => {"vimbadmin_workdir_created"},
perms => m(644),
classes => if_repaired(vimbadmin_reconfigure);
"$(cfg[install_dir])/public/.htaccess"
copy_from => local_cp("$(cfg[install_dir])/public/.htaccess.dist"),
perms => mog("644","root","root"),
depends_on => {"vimbadmin_untarred"},
handle => "vimbadmin_htaccess_copied";
"$(cfg[install_dir])/application/configs/application.ini"
copy_from => seed_cp("$(cfg[install_dir])/application/configs/application.ini.dist"),
perms => mog("644","root","root"),
depends_on => {"vimbadmin_untarred"},
handle => "vimbadmin_appini_copied";
"$(cfg[install_dir])/application/configs/application.ini"
edit_line => set_variable_values("vimbadmin.vsettings"),
handle => "vimbadmin_appini_edited",
depends_on => { "vimbadmin_appini_copied" };
vimbadmin_reconfigure::
"$(sys.workdir)/data/agent/vimbadmin/configured.txt"
depends_on => { "vimbadmin_tgz_copied" },
delete => tidy;
"$(sys.workdir)/data/agent/vimbadmin/configured.txt"
depends_on => { "vimbadmin_composed" },
create => "true",
content => "ok";
commands:
"!mysql_$(cfg[db_name])_admin_exists"::
"cd $(cfg[install_dir]) && ./bin/doctrine2-cli.php orm:schema-tool:create "
contain => wmde_cmd_useshell,
depends_on => {"vimbadmin_appini_edited"};
vimbadmin_reconfigure::
"/bin/sh"
args => "-c '/usr/bin/tar xf $(sys.workdir)/data/public/vimbadmin.tgz --strip-components=1 -C $(cfg[install_dir])'",
handle => "vimbadmin_untarred",
contain => vimbadmin_cmd;
"/bin/sh"
# args => "-c 'cd $(cfg[install_dir]) && $(php_composer.exe) -q -n create-project --prefer-dist --no-dev opensolutions/vimbadmin'",
args => "-c 'cd $(cfg[install_dir]) && $(php_composer.exe) install -q --prefer-dist --no-dev",
handle => "vimbadmin_composed",
contain => vimbadmin_cmd;
#"/bin/sh"
#args => '-c $(php
!vimbadmin_reconfigure::
"/bin/true"
inform => "false",
handle => "vimbadmin_untarred";
methods:
"any" usebundle => php_composer;
"any" usebundle => mysql_table_exists(@(cfg),"admin");
reports:
"mysql_$(cfg[db_name])_admin_exists"::
"VIMBADMIN TABLE ADMIN ALREADY EXISTS";
vimbadmin_reconfigure::
"DO RECONFIGURE";
!vimbadmin_reconfigure::
"VIMADMIN UNTARRED" depends_on => {"vimbadmin_untarred"};
"Hello not econf";
}
body contain vimbadmin_cmd
{
exec_owner => "www-data";
exec_group => "www-data";
}

20
wget.cf Normal file
View File

@ -0,0 +1,20 @@
bundle agent wget
{
vars:
"pkgs" slist => {"wget"};
freebsd::
"exe" string => "/usr/local/bin/wget";
debian::
"exe" string => "/usr/bin/wget";
}
bundle agent install_wget
{
methods:
"any" usebundle => wmde_install_packages(@(wget.pkgs),"wget");
}