wmdeit-cf-wmdelib/vimbadmin.cf

166 lines
5.1 KiB
CFEngine3
Raw Normal View History

2023-10-11 09:28:28 +00:00
#
#
#
bundle agent vimbadmin(cfg)
{
classes:
"vimbadmin_restore_db_file" expression => isvariable("cfg[restore_db_file]");
2023-10-11 09:28:28 +00:00
vimbadmin_restore_db_file::
"vimbadmin_restore_db" expression => fileexists("$(cfg[restore_db_file])");
vars:
2023-10-29 00:11:35 +00:00
"pkgs" slist => {
"git"
};
2023-10-11 09:28:28 +00:00
"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";
2023-10-12 18:21:41 +00:00
"vsettings[server.email.name]" string => "$(cfg[server_email_name])";
"vsettings[server.email.address]" string => "$(cfg[server_email_address])";
2023-10-26 22:11:16 +00:00
"vsettings[resources.mail.transport.type]" string => "'smtp'";
"vsettings[resources.mail.transport.host]" string => "'127.0.0.1'";
2023-10-29 19:15:04 +00:00
"vsettings[defaults.mailbox.password_scheme]" string => "crypt:sha256";
2023-10-26 22:11:16 +00:00
#
2023-10-11 09:28:28 +00:00
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"
2023-10-17 06:49:21 +00:00
copy_from => remote_dcp("$(cfg[src_tgz])","$(sys.policy_hub)"),
2023-10-11 09:28:28 +00:00
handle => "vimbadmin_tgz_copied",
depends_on => {"vimbadmin_workdir_created"},
perms => m(644),
classes => if_repaired(vimbadmin_reconfigure);
"$(cfg[install_dir])/public/.htaccess"
copy_from => seed_cp("$(cfg[install_dir])/public/.htaccess.dist"),
2023-10-11 09:28:28 +00:00
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)&(!vimbadmin_restore_db)"::
2023-10-11 09:28:28 +00:00
"cd $(cfg[install_dir]) && ./bin/doctrine2-cli.php orm:schema-tool:create "
contain => wmde_cmd_useshell,
handle => "vimbadmin_db_initialized",
2023-10-11 09:28:28 +00:00
depends_on => {"vimbadmin_appini_edited"};
"(!mysql_$(cfg[db_name])_admin_exists)&vimbadmin_restore_db"::
"mysql -u $(cfg[db_user]) -p$(cfg[db_pass]) -h$(cfg[db_host]) $(cfg[db_name]) < $(cfg[restore_db_file])"
contain => wmde_cmd_useshell,
depends_on => {"vimbadmin_appini_edited"};
2023-10-11 09:28:28 +00:00
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'",
2023-11-03 11:57:09 +00:00
args => "-c 'export HOME=$(cfg[install_dir]) && cd $(cfg[install_dir]) && $(php_composer.exe) update -q --no-cache && $(php_composer.exe) install --no-cache -q --prefer-dist --no-dev'",
2023-10-11 09:28:28 +00:00
handle => "vimbadmin_composed",
2023-10-29 00:11:35 +00:00
depends_on => {
"vimbadmin_pkgs_installed"
},
2023-10-11 09:28:28 +00:00
contain => vimbadmin_cmd;
#"/bin/sh"
#args => '-c $(php
!vimbadmin_reconfigure::
"/bin/true"
inform => "false",
handle => "vimbadmin_untarred";
methods:
2023-10-29 00:11:35 +00:00
"any" usebundle => wmde_install_packages(@(pkgs),"vimbadmin");
2023-10-11 09:28:28 +00:00
"any" usebundle => php_composer;
"any" usebundle => mysql_table_exists(@(cfg),"admin");
vimbadmin_restore_db_file::
"any" usebundle => create_mysql_backup_cron_job(@(cfg),"$(cfg[restore_db_file])","admin","true");
2023-10-11 09:28:28 +00:00
reports:
# "VIMBADMIN $(cfg[restore_db_file])";
# "vimbadmin_restore_db_file"::
# "RESTORE_DB_FILE";
# "vimbadmin_restore_db"::
# "RESTORE_DB";
# "(!mysql_$(cfg[db_name])_admin_exists)&vimbadmin_restore_db"::
# "Should restore db";
2023-10-11 09:28:28 +00:00
}
body contain vimbadmin_cmd
{
exec_owner => "$(apache.www_user)";
exec_group => "$(apache.www_group)";
2023-11-03 11:57:09 +00:00
useshell=>"useshell";
2023-10-11 09:28:28 +00:00
}