recipe odoo data

This commit is contained in:
pvincent
2024-02-29 16:12:53 +04:00
parent cb8e1d2ebb
commit 4fbae210ce
7 changed files with 49 additions and 66 deletions
+20 -11
View File
@@ -30,8 +30,8 @@ function _create() {
mkdir -p "$MIAOU_CONFIGDIR/apps/odoo12"
longport=$((port + 1000))
APP_PORT=$port LONG_PORT=$longport APP_NAME=$shortname tera -e -t "$MIAOU_DIR/templates/apps/odoo12/odoo.conf.j2" -o "$MIAOU_CONFIGDIR/apps/odoo12/$shortname.conf" "$MIAOU_CONFIGDIR/miaou.expanded.yaml" >/dev/null
APP_NAME=$shortname tera -t "$MIAOU_DIR/templates/apps/odoo12/odoo.service.j2" --env-only -o "$MIAOU_CONFIGDIR/apps/odoo12/$longname.service" >/dev/null
APP_PORT=$port LONG_PORT=$longport APP_NAME=$shortname tera -e -t "$MIAOU_BASEDIR/templates/apps/odoo12/odoo.conf.j2" -o "$MIAOU_CONFIGDIR/apps/odoo12/$shortname.conf" "$MIAOU_CONFIGDIR/miaou.expanded.yaml" >/dev/null
APP_NAME=$shortname tera -t "$MIAOU_BASEDIR/templates/apps/odoo12/odoo.service.j2" --env-only -o "$MIAOU_CONFIGDIR/apps/odoo12/$longname.service" >/dev/null
echo "creating templates ... OK"
echo "copying files over container <$container> ... "
@@ -44,10 +44,11 @@ function _create() {
db-psql create "$longname"
echo "create empty database <$longname> ... OK"
#FIXME: load credential from data argument wth yq parsing!!!
admin_username=$(cat "$data" | yq '.admin.username')
[[ $admin_username == 'null ' ]] && echoerr "odoo12 recipe requires \`data:admin:username\` into miaou.yaml service definition of <$fqdn>" && exit 1
credential_username=$(load_yaml_from_expanded credential.username)
credential_password=$(load_yaml_from_expanded credential.password)
admin_password=$(cat "$data" | yq '.admin.password')
[[ $admin_password == 'null ' ]] && echoerr "odoo12 recipe requires \`data:admin:password\` into miaou.yaml service definition of <$fqdn>" && exit 1
cat <<EOF | lxc_exec "$container"
set -Eeuo pipefail
@@ -65,8 +66,7 @@ function _create() {
chmod u+w -R "/home/odoo/data-$shortname"
echo "TODO: change administrator password, default credential applied!"
echo "UPDATE res_users SET login='$credential_username', password='$credential_password' WHERE id=2" | PGPASSWORD=$longname psql -U $longname -h ct1.lxd
echo "UPDATE res_users SET login='$admin_username', password='$admin_password' WHERE id=2" | PGPASSWORD=$longname psql -U $longname -h ct1.lxd
EOF
else
echo "database already exists!"
@@ -99,7 +99,7 @@ function _delete() {
}
function usage() {
echo "Usage: $COMMAND_NAME -c|r|u|d --port PORT --container CONTAINER --name NAME"
echo "Usage: $COMMAND_NAME -c|r|u|d --port PORT --fqdn FQDN --container CONTAINER --name NAME --data DATA"
exit 2
}
@@ -111,16 +111,18 @@ COMMAND_NAME=$(basename "$0")
# read the options
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn: -- "$@")
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,data: -- "$@")
# shellcheck disable=SC2181
[[ "$?" -eq 0 ]] || usage
eval set -- "$TEMP"
action="unset"
port="unset"
fqdn="unset"
container="unset"
shortname="unset"
longname="unset"
data="unset"
# extract options and their arguments into variables.
while true; do
@@ -130,6 +132,7 @@ while true; do
shift 2
;;
--fqdn)
fqdn=$2
shift 2
;;
--container)
@@ -141,6 +144,10 @@ while true; do
longname="odoo12-$shortname"
shift 2
;;
--data)
data=$2
shift 2
;;
-c)
[[ "$action" == "unset" ]] || usage
action="_create"
@@ -166,7 +173,7 @@ while true; do
break
;;
*)
echo "Internal error!"
echoerr "Internal error!"
exit 1
;;
esac
@@ -175,8 +182,10 @@ done
[[
"$action" != unset &&
"$port" != unset &&
"$fqdn" != unset &&
"$container" != unset &&
"$shortname" != unset ]] || usage
"$shortname" != unset &&
"$data" != unset ]] || usage
. "$MIAOU_BASEDIR/lib/init.sh"