#!/bin/bash function check_database_exists() { db-maria list | grep -q "$longname" } function check_port_used() { # shellcheck disable=SC2034 usedport=$(lxc exec "$container" -- bash -c "grep listen /etc/nginx/sites-enabled/$longname.conf | cut -d' ' -f6") [[ "$usedport" == "$port" ]] } function check_service_running() { lxc exec "$container" -- bash -c "systemctl is-active --quiet nginx.service" } function _read() { disable_trace check_database_exists check_container "$container" check_port_used check_service_running enable_trace return 0 } function _create() { echo "creating wordpress instance for <$shortname> ... " mkdir -p "$MIAOU_CONFIGDIR/apps/wordpress" APP_PORT=$port APP_NAME=$shortname tera -e --env-key env -t "$MIAOU_BASEDIR/templates/apps/wordpress/wp-host.j2" -o "$MIAOU_CONFIGDIR/apps/wordpress/$longname.conf" "$MIAOU_CONFIGDIR/miaou.expanded.yaml" echo "creating templates ... OK" echo "copying files over container <$container> ... " lxc file push --uid 0 --gid 0 "$MIAOU_CONFIGDIR/apps/wordpress/$longname.conf" "$container/etc/nginx/sites-available/$longname.conf" echo "copying files over container <$container> ... OK" if ! (db-maria list | grep -q "$longname"); then echo "create empty database <$longname> ... " db-maria create "$longname" echo "create empty database <$longname> ... OK" else echo "database already exists!" fi echo "initialize wordpress $shortname $longname ..." lxc exec "$container" -- bash < /var/www/wordpress/$shortname/wp-config.php " exit 1 ;; esac done . "$MIAOU_BASEDIR/lib/init.sh" [[ "$action" != unset && "$port" != unset && "$container" != unset && "$shortname" != unset ]] || usage $action