recipe odoo data
This commit is contained in:
@@ -1,18 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
MIAOU_DIR="$(dirname "$0")/../.."
|
|
||||||
readonly MIAOU_DIR
|
|
||||||
|
|
||||||
function init_strict() {
|
|
||||||
set -Eeuo pipefail
|
|
||||||
# shellcheck source=/dev/null
|
|
||||||
source "$MIAOU_DIR/lib/functions.sh"
|
|
||||||
# shellcheck source=/dev/null
|
|
||||||
source "/opt/miaou-bash/lib/functions.sh"
|
|
||||||
trap 'trap_error $? $LINENO $BASH_LINENO "$BASH_COMMAND" $(printf "::%s" ${FUNCNAME[@]})' ERR
|
|
||||||
}
|
|
||||||
|
|
||||||
## main
|
|
||||||
init_strict
|
|
||||||
sudo_required
|
|
||||||
build_miaou_image "bullseye"
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
MIAOU_DIR="$(dirname "$0")/../.."
|
|
||||||
readonly MIAOU_DIR
|
|
||||||
|
|
||||||
function init_strict() {
|
|
||||||
set -Eeuo pipefail
|
|
||||||
# shellcheck source=/dev/null
|
|
||||||
source "$MIAOU_DIR/lib/functions.sh"
|
|
||||||
# shellcheck source=/dev/null
|
|
||||||
source "/opt/miaou-bash/lib/functions.sh"
|
|
||||||
|
|
||||||
trap 'trap_error $? $LINENO $BASH_LINENO "$BASH_COMMAND" $(printf "::%s" ${FUNCNAME[@]})' ERR
|
|
||||||
}
|
|
||||||
|
|
||||||
## main
|
|
||||||
init_strict
|
|
||||||
sudo_required
|
|
||||||
build_miaou_image "buster"
|
|
||||||
@@ -34,7 +34,7 @@ function _create() {
|
|||||||
echo "creating CagettePéi instance for <$shortname> ... "
|
echo "creating CagettePéi instance for <$shortname> ... "
|
||||||
|
|
||||||
mkdir -p "$MIAOU_CONFIGDIR/apps/cagettepei"
|
mkdir -p "$MIAOU_CONFIGDIR/apps/cagettepei"
|
||||||
APP_PORT=$port APP_NAME=$shortname tera -e --env-key env -t "$MIAOU_DIR/templates/apps/cagettepei/cagettepei-host.j2" -o "$MIAOU_CONFIGDIR/apps/cagettepei/$longname.conf" "$MIAOU_CONFIGDIR/miaou.expanded.yaml"
|
APP_PORT=$port APP_NAME=$shortname tera -e --env-key env -t "$MIAOU_BASEDIR/templates/apps/cagettepei/cagettepei-host.j2" -o "$MIAOU_CONFIGDIR/apps/cagettepei/$longname.conf" "$MIAOU_CONFIGDIR/miaou.expanded.yaml"
|
||||||
echo "creating templates ... OK"
|
echo "creating templates ... OK"
|
||||||
|
|
||||||
echo "copying files over container <$container> ... "
|
echo "copying files over container <$container> ... "
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ EOF
|
|||||||
echo "generating configuration files from templates... "
|
echo "generating configuration files from templates... "
|
||||||
mkdir -p "$MIAOU_CONFIGDIR/apps/dolibarr/$shortname"
|
mkdir -p "$MIAOU_CONFIGDIR/apps/dolibarr/$shortname"
|
||||||
PHP_VERSION=$(lxc exec "$container" -- dpkg -l php-fpm | grep "^ii" | cut -d ':' -f2 | cut -d '+' -f1)
|
PHP_VERSION=$(lxc exec "$container" -- dpkg -l php-fpm | grep "^ii" | cut -d ':' -f2 | cut -d '+' -f1)
|
||||||
APP_PORT=$port APP_NAME=$longname PHP_VERSION=$PHP_VERSION tera -e -t "$MIAOU_DIR/templates/apps/dolibarr/host.j2" -o "$MIAOU_CONFIGDIR/apps/dolibarr/$shortname/host.conf" "$MIAOU_CONFIGDIR/miaou.expanded.yaml" >/dev/null
|
APP_PORT=$port APP_NAME=$longname PHP_VERSION=$PHP_VERSION tera -e -t "$MIAOU_BASEDIR/templates/apps/dolibarr/host.j2" -o "$MIAOU_CONFIGDIR/apps/dolibarr/$shortname/host.conf" "$MIAOU_CONFIGDIR/miaou.expanded.yaml" >/dev/null
|
||||||
|
|
||||||
echo "copying configuration files onto container <$container>... "
|
echo "copying configuration files onto container <$container>... "
|
||||||
lxc file push --uid 0 --gid 0 "$MIAOU_CONFIGDIR/apps/dolibarr/$shortname/host.conf" "$container/etc/nginx/sites-available/$longname.conf"
|
lxc file push --uid 0 --gid 0 "$MIAOU_CONFIGDIR/apps/dolibarr/$shortname/host.conf" "$container/etc/nginx/sites-available/$longname.conf"
|
||||||
|
|||||||
+20
-11
@@ -30,8 +30,8 @@ function _create() {
|
|||||||
mkdir -p "$MIAOU_CONFIGDIR/apps/odoo12"
|
mkdir -p "$MIAOU_CONFIGDIR/apps/odoo12"
|
||||||
|
|
||||||
longport=$((port + 1000))
|
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_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_DIR/templates/apps/odoo12/odoo.service.j2" --env-only -o "$MIAOU_CONFIGDIR/apps/odoo12/$longname.service" >/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 "creating templates ... OK"
|
||||||
|
|
||||||
echo "copying files over container <$container> ... "
|
echo "copying files over container <$container> ... "
|
||||||
@@ -44,10 +44,11 @@ function _create() {
|
|||||||
db-psql create "$longname"
|
db-psql create "$longname"
|
||||||
echo "create empty database <$longname> ... OK"
|
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)
|
admin_password=$(cat "$data" | yq '.admin.password')
|
||||||
credential_password=$(load_yaml_from_expanded credential.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"
|
cat <<EOF | lxc_exec "$container"
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
@@ -65,8 +66,7 @@ function _create() {
|
|||||||
|
|
||||||
chmod u+w -R "/home/odoo/data-$shortname"
|
chmod u+w -R "/home/odoo/data-$shortname"
|
||||||
|
|
||||||
echo "TODO: change administrator password, default credential applied!"
|
echo "UPDATE res_users SET login='$admin_username', password='$admin_password' WHERE id=2" | PGPASSWORD=$longname psql -U $longname -h ct1.lxd
|
||||||
echo "UPDATE res_users SET login='$credential_username', password='$credential_password' WHERE id=2" | PGPASSWORD=$longname psql -U $longname -h ct1.lxd
|
|
||||||
EOF
|
EOF
|
||||||
else
|
else
|
||||||
echo "database already exists!"
|
echo "database already exists!"
|
||||||
@@ -99,7 +99,7 @@ function _delete() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function usage() {
|
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
|
exit 2
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,16 +111,18 @@ COMMAND_NAME=$(basename "$0")
|
|||||||
|
|
||||||
# read the options
|
# 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
|
# shellcheck disable=SC2181
|
||||||
[[ "$?" -eq 0 ]] || usage
|
[[ "$?" -eq 0 ]] || usage
|
||||||
eval set -- "$TEMP"
|
eval set -- "$TEMP"
|
||||||
|
|
||||||
action="unset"
|
action="unset"
|
||||||
port="unset"
|
port="unset"
|
||||||
|
fqdn="unset"
|
||||||
container="unset"
|
container="unset"
|
||||||
shortname="unset"
|
shortname="unset"
|
||||||
longname="unset"
|
longname="unset"
|
||||||
|
data="unset"
|
||||||
|
|
||||||
# extract options and their arguments into variables.
|
# extract options and their arguments into variables.
|
||||||
while true; do
|
while true; do
|
||||||
@@ -130,6 +132,7 @@ while true; do
|
|||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--fqdn)
|
--fqdn)
|
||||||
|
fqdn=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--container)
|
--container)
|
||||||
@@ -141,6 +144,10 @@ while true; do
|
|||||||
longname="odoo12-$shortname"
|
longname="odoo12-$shortname"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--data)
|
||||||
|
data=$2
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
-c)
|
-c)
|
||||||
[[ "$action" == "unset" ]] || usage
|
[[ "$action" == "unset" ]] || usage
|
||||||
action="_create"
|
action="_create"
|
||||||
@@ -166,7 +173,7 @@ while true; do
|
|||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Internal error!"
|
echoerr "Internal error!"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -175,8 +182,10 @@ done
|
|||||||
[[
|
[[
|
||||||
"$action" != unset &&
|
"$action" != unset &&
|
||||||
"$port" != unset &&
|
"$port" != unset &&
|
||||||
|
"$fqdn" != unset &&
|
||||||
"$container" != unset &&
|
"$container" != unset &&
|
||||||
"$shortname" != unset ]] || usage
|
"$shortname" != unset &&
|
||||||
|
"$data" != unset ]] || usage
|
||||||
|
|
||||||
. "$MIAOU_BASEDIR/lib/init.sh"
|
. "$MIAOU_BASEDIR/lib/init.sh"
|
||||||
|
|
||||||
|
|||||||
+21
-9
@@ -30,8 +30,8 @@ function _create() {
|
|||||||
mkdir -p "$MIAOU_CONFIGDIR/apps/odoo15"
|
mkdir -p "$MIAOU_CONFIGDIR/apps/odoo15"
|
||||||
|
|
||||||
longport=$((port + 1000))
|
longport=$((port + 1000))
|
||||||
APP_PORT=$port LONG_PORT=$longport APP_NAME=$shortname tera -e -t "$MIAOU_DIR/templates/apps/odoo15/odoo.conf.j2" -o "$MIAOU_CONFIGDIR/apps/odoo15/$shortname.conf" "$MIAOU_CONFIGDIR/miaou.expanded.yaml" >/dev/null
|
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_DIR/templates/apps/odoo15/odoo.service.j2" --env-only -o "$MIAOU_CONFIGDIR/apps/odoo15/$longname.service" >/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 "creating templates ... OK"
|
||||||
|
|
||||||
echo "copying files over container <$container> ... "
|
echo "copying files over container <$container> ... "
|
||||||
@@ -54,8 +54,11 @@ EOF
|
|||||||
db-psql create "$longname"
|
db-psql create "$longname"
|
||||||
echo "create empty database <$longname> ... OK"
|
echo "create empty database <$longname> ... OK"
|
||||||
|
|
||||||
credential_username=$(load_yaml_from_expanded credential.username)
|
admin_username=$(cat "$data" | yq '.admin.username')
|
||||||
credential_password=$(load_yaml_from_expanded credential.password)
|
[[ $admin_username == 'null ' ]] && echoerr "odoo12 recipe requires \`data:admin:username\` into miaou.yaml service definition of <$fqdn>" && exit 1
|
||||||
|
|
||||||
|
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"
|
cat <<EOF | lxc_exec "$container"
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
@@ -76,7 +79,7 @@ EOF
|
|||||||
su odoo -c "python3.9 /home/odoo/odoo15/odoo-bin -c /etc/odoo15/$shortname.conf --load-language fr_FR -d $longname --worker=0 --stop-after-init"
|
su odoo -c "python3.9 /home/odoo/odoo15/odoo-bin -c /etc/odoo15/$shortname.conf --load-language fr_FR -d $longname --worker=0 --stop-after-init"
|
||||||
|
|
||||||
echo change administrator password, default credential applied!
|
echo 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
|
EOF
|
||||||
else
|
else
|
||||||
@@ -112,7 +115,7 @@ function _delete() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function usage() {
|
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
|
exit 2
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,16 +127,18 @@ COMMAND_NAME=$(basename "$0")
|
|||||||
|
|
||||||
# read the options
|
# 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
|
# shellcheck disable=SC2181
|
||||||
[[ "$?" -eq 0 ]] || usage
|
[[ "$?" -eq 0 ]] || usage
|
||||||
eval set -- "$TEMP"
|
eval set -- "$TEMP"
|
||||||
|
|
||||||
action="unset"
|
action="unset"
|
||||||
port="unset"
|
port="unset"
|
||||||
|
fqdn="unset"
|
||||||
container="unset"
|
container="unset"
|
||||||
shortname="unset"
|
shortname="unset"
|
||||||
longname="unset"
|
longname="unset"
|
||||||
|
data="unset"
|
||||||
|
|
||||||
# extract options and their arguments into variables.
|
# extract options and their arguments into variables.
|
||||||
while true; do
|
while true; do
|
||||||
@@ -143,6 +148,7 @@ while true; do
|
|||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--fqdn)
|
--fqdn)
|
||||||
|
fqdn=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--container)
|
--container)
|
||||||
@@ -154,6 +160,10 @@ while true; do
|
|||||||
longname="odoo15-$shortname"
|
longname="odoo15-$shortname"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--data)
|
||||||
|
data=$2
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
-c)
|
-c)
|
||||||
[[ "$action" == "unset" ]] || usage
|
[[ "$action" == "unset" ]] || usage
|
||||||
action="_create"
|
action="_create"
|
||||||
@@ -179,7 +189,7 @@ while true; do
|
|||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Internal error!"
|
echoerr "Internal error!"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -188,8 +198,10 @@ done
|
|||||||
[[
|
[[
|
||||||
"$action" != unset &&
|
"$action" != unset &&
|
||||||
"$port" != unset &&
|
"$port" != unset &&
|
||||||
|
"$fqdn" != unset &&
|
||||||
"$container" != unset &&
|
"$container" != unset &&
|
||||||
"$shortname" != unset ]] || usage
|
"$shortname" != unset &&
|
||||||
|
"$data" != unset ]] || usage
|
||||||
|
|
||||||
. "$MIAOU_BASEDIR/lib/init.sh"
|
. "$MIAOU_BASEDIR/lib/init.sh"
|
||||||
|
|
||||||
|
|||||||
+6
-7
@@ -75,9 +75,7 @@ function archive_allconf() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function check_expand_conf() {
|
function check_expand_conf() {
|
||||||
PREFIX="miaou:conf:check"
|
|
||||||
if ! "$FORCE" && [ -f "$EXPANDED_CONF" ] && [ "$EXPANDED_CONF" -nt "$CONF" ] && [ "$EXPANDED_CONF" -nt "$DEFAULTS" ]; then
|
if ! "$FORCE" && [ -f "$EXPANDED_CONF" ] && [ "$EXPANDED_CONF" -nt "$CONF" ] && [ "$EXPANDED_CONF" -nt "$DEFAULTS" ]; then
|
||||||
echo "already expanded!"
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -415,15 +413,16 @@ function build_services() {
|
|||||||
|
|
||||||
domain=${item[0]}
|
domain=${item[0]}
|
||||||
subdomain=${item[1]}
|
subdomain=${item[1]}
|
||||||
data=$(yqm ".services.\"$domain\".\"$subdomain\".data")
|
data=$(yqm ".services.\"$domain\".\"$subdomain\".data|explode(.)")
|
||||||
echo "domain=$domain, subdomain=$subdomain, data=$data"
|
|
||||||
|
|
||||||
recipe="$MIAOU_BASEDIR/recipes/$app/crud.sh"
|
recipe="$MIAOU_BASEDIR/recipes/$app/crud.sh"
|
||||||
if [[ -f "$recipe" ]]; then
|
if [[ -f "$recipe" ]]; then
|
||||||
echo "read [$app:$name] onto container <$container>"
|
echo "read [$app:$name] onto container <$container>"
|
||||||
if ! "$recipe" -r --port "$port" --container "$container" --name "$name" --fqdn "$fqdn"; then
|
command="env MIAOU_BASEDIR=$MIAOU_BASEDIR MIAOU_CONFIGDIR=$MIAOU_CONFIGDIR $recipe --port $port --container $container --name $name --fqdn $fqdn"
|
||||||
|
[[ "$data" != "null" ]] && command+=" --data \"$data\""
|
||||||
|
if ! eval "$command -r" >/dev/null; then
|
||||||
echoinfo "CREATE RECIPE"
|
echoinfo "CREATE RECIPE"
|
||||||
"$recipe" -c --port "$port" --container "$container" --name "$name" --fqdn "$fqdn"
|
eval "$command -c"
|
||||||
echoinfo "CREATE RECIPE: OK"
|
echoinfo "CREATE RECIPE: OK"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -457,7 +456,7 @@ fi
|
|||||||
|
|
||||||
if containsElement options "config"; then
|
if containsElement options "config"; then
|
||||||
editor /etc/miaou/miaou.yaml
|
editor /etc/miaou/miaou.yaml
|
||||||
if diff -q /etc/miaou/miaou.yaml $HOME/.config/miaou/archived/miaou.yaml/previous; then
|
if diff -q /etc/miaou/miaou.yaml "$HOME"/.config/miaou/archived/miaou.yaml/previous; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user