#!/bin/bash function check_database_exists() { db-psql list | grep -q "$longname" } function check_port_used() { # shellcheck disable=SC2034 usedport=$(lxc exec "$container" -- bash -c "grep xmlrpc_port /etc/odoo15/$shortname.conf | cut -d' ' -f3") [[ "$usedport" == "$port" ]] } function check_service_running() { lxc exec "$container" -- bash -c "systemctl is-active --quiet ${longname}.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 templates ... " mkdir -p "$MIAOU_CONFIGDIR/apps/odoo15" longport=$((port + 1000)) APP_PORT=$port LONG_PORT=$longport APP_NAME=$shortname tera -e -t "$MIAOU_BASEDIR/templates/apps/odoo15/odoo.conf.j2" -o "$MIAOU_CONFIGDIR/apps/odoo15/$shortname.conf" "$MIAOU_CONFIGDIR/miaou.expanded.yaml" >/dev/null APP_NAME=$shortname tera -t "$MIAOU_BASEDIR/templates/apps/odoo15/odoo.service.j2" --env-only -o "$MIAOU_CONFIGDIR/apps/odoo15/$longname.service" >/dev/null echo "creating templates ... OK" echo "copying files to container <$container> ... " lxc file push --uid 0 --gid 0 "$MIAOU_CONFIGDIR/apps/odoo15/$shortname.conf" "$container/etc/odoo15/$shortname.conf" lxc file push --uid 0 --gid 0 "$MIAOU_CONFIGDIR/apps/odoo15/$longname.service" "$container/etc/systemd/system/$longname.service" echo "copying files to container <$container> ... OK" echo "create data folder for $shortname" cat < ... " db-psql create "$longname" echo "create empty database <$longname> ... OK" admin_username=$(echo -e "$data" | yq '.admin.username') [[ $admin_username == 'null ' ]] && echoerr "odoo12 recipe requires \`data:admin:username\` into miaou.yaml service definition of <$fqdn>" && exit 1 admin_password=$(echo -e "$data" | yq '.admin.password') [[ $admin_password == 'null ' ]] && echoerr "odoo12 recipe requires \`data:admin:password\` into miaou.yaml service definition of <$fqdn>" && exit 1 cat <" exit 1 ;; esac done [[ "$action" != unset && "$port" != unset && "$fqdn" != unset && "$container" != unset && "$shortname" != unset && "$data" != unset ]] || usage . "$MIAOU_BASEDIR/lib/init.sh" $action