From 56770254a1b09684474ddd32a4592a6555956c43 Mon Sep 17 00:00:00 2001 From: Mauro Rosero P Date: Tue, 3 Dec 2024 11:02:16 -0500 Subject: [PATCH] =?UTF-8?q?[IMPROVED]=20Creaci=C3=B3n=20de=20proyecto=20od?= =?UTF-8?q?oo=20nuevo=20-=20Se=20copian=20los=20modulos=20apps=20(base,=20?= =?UTF-8?q?ia=20y=20devs)=20desde=20los=20packs.=20Esto=20es=20el=20sistem?= =?UTF-8?q?a=20de=20aplicaciones=20odoo=20base?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/lib/base.lib | 5 +++ bin/lib/odoo.lib | 47 ++++++++++++++++++++++++ bin/msg/odoo.es | 9 ++++- bin/project.sh | 94 ++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 135 insertions(+), 20 deletions(-) diff --git a/bin/lib/base.lib b/bin/lib/base.lib index 3e54400..156effc 100644 --- a/bin/lib/base.lib +++ b/bin/lib/base.lib @@ -38,6 +38,7 @@ function load_messages() { fi } +# Display text header apps function display_text_header() { local PROJECT=$1 local tittle=$2 @@ -47,6 +48,8 @@ function display_text_header() { echo "==========================================================" } + + # Verify if your program or command is installed function command_installed() { local PROGRAM=$1 @@ -59,6 +62,7 @@ function command_installed() { return 1 } +# Install os packages function os_pkgs_install() { local PACKAGE=$1 @@ -114,6 +118,7 @@ function os_update() { } +# Check for container manager installed function container_mode() { command_installed "podman" diff --git a/bin/lib/odoo.lib b/bin/lib/odoo.lib index 99ff60f..e45a073 100644 --- a/bin/lib/odoo.lib +++ b/bin/lib/odoo.lib @@ -31,14 +31,39 @@ ODOO_CFG=config ODOO_SET=odoo.conf ODOO_LOG=odoo.log +ODOO_DEF_VERS="18" +ODOO_CFG_VARS=("18") + +ODOO_PKG_BASE=base +ODOO_PKG_DEVS=devs +ODOO_PKG_INAR=ia + +ODOO_CFG_PREF=odoo.v ODOO_CFG_BASE=odoo.base.conf ODOO_CFG_SAAS=odoo.saas.conf +ODOO_CFG_PACK=packs # Test odoo library function odoolib_test() { echo "Odoo Library loaded!" } +# Check for odoo version supported +function odoo_verscheck() { + + local value=$1 + + for item in "${ODOO_CFG_VARS[@]}" + do + if [[ "$item" == "$value" ]] + then + return 0 + fi + done + return 1 + +} + # Create odoo project structured path function odoo_structure() { @@ -59,6 +84,7 @@ function odoo_structure() { fi fi fi + } # Copy docker file to build @@ -76,6 +102,7 @@ function copy_dockerfile() { echo "[x] $odmsg_009" fi fi + } # Copy odoo config template file to etc @@ -93,6 +120,7 @@ function copy_odooconfig() { echo "[x] $odmsg_010 $ODOOFILE" fi fi + } # Create new odoo log file @@ -109,4 +137,23 @@ function create_odoolog() { echo "[x] $odmsg_011" fi fi + +} + +# Copy odoo/version modules to apps +function copy_odooapps() { + + local ODOO_PATH=$1 + local ODOO_PROJ=$2 + local APPS=$4 + local VERSION=$3 + + cp -rf $ODOO_PATH/$ODOO_CFG_PACK/${ODOO_CFG_PREF}${VERSION}/${APPS} "$ODOO_PATH/$ODOO_PROJ/$ODOO_APP/" + if [ $? -eq 0 ] + then + echo "[x] $odmsg_012_1 $APPS $odmsg_012_2" + else + echo "[-] $odmsg_012_1 $APPS $odmsg_012_3" + fi + } diff --git a/bin/msg/odoo.es b/bin/msg/odoo.es index 41641ac..c01d123 100644 --- a/bin/msg/odoo.es +++ b/bin/msg/odoo.es @@ -15,7 +15,7 @@ odmsg_000="(ODOO TOOLS)" odmsg_001="- INICIALIZACIÓN" odmsg_002="Ambiente de desarrollo Odoo no instalado!" odmsg_003_1="Uso:" -odmsg_003_2=" [--help] [--version]" +odmsg_003_2=" [--help] [--version] [--odoo ]" odmsg_004="Descripción: Este script requiere un argumento obligatorio." odmsg_005="Opciones:" odmsg_006=" --help Muestra este mensaje de ayuda." @@ -25,3 +25,10 @@ odmsg_008_2="fue creada!" odmsg_009="Dockerfile fue creado!" odmsg_010="odoo.conf creado desde" odmsg_011="Archivo de auditoria odoo (odoo.log) fue inicializado!" +odmsg_012_1="Paquete de odoo" +odmsg_012_2="ha sido actualizado!" +odmsg_012_3="no fue actualizado!" +odmsg_013="Error: Se requiere un argumento para --odoo." +odmsg_014_1="Versión de Odoo" +odmsg_014_2="no es soportada!" +odmsg_015=" --odoo Identifica la versión de odoo a configurar. Default:" diff --git a/bin/project.sh b/bin/project.sh index 8d5da76..c5df026 100755 --- a/bin/project.sh +++ b/bin/project.sh @@ -48,39 +48,95 @@ function help() { echo "$odmsg_005" echo "$odmsg_006" echo "$odmsg_007" + echo "$odmsg_015 $ODOO_DEF_VERS" } # Display Headers display_text_header $BIN_HOME "${odmsg_000} ${odmsg_001}" # Check for arguments option -for arg in "$@"; do - case $arg in - --help) - help - exit 0 - ;; - --version) - echo "$head_version $VERSION" - exit 0 - ;; - esac +help=false +version=false +while [[ $# -gt 0 ]]; do + case $1 in + --help) + help=true + shift + ;; + --version) + version=true + shift + ;; + --odoo) + if [[ -n $2 ]]; then + ODOO_VERS="$2" + shift 2 + else + echo "$odmsg_013" + exit 1 + fi + ;; + *) + if [[ -z $PROJECT_NAME ]]; then + PROJECT_NAME="$1" + shift + else + help + echo "zzzzzzzz" + exit 1 + fi + ;; + esac done -# Check if mandatory argument is provided -if [ -z "$1" ]; then - help - exit 1 +# Check to show help +if $help; then + help + echo "$help" + exit 0 +fi + +# Check to show command version +if $version; then + echo "$head_version $VERSION" + exit 0 +fi + +# Check for empty project path +if [[ -z $PROJECT_NAME ]]; then + help + exit 1 +fi + +# Set odoo default version, if odoo version is not defined +if [[ ! -n $ODOO_VERS ]]; then + ODOO_VERS=$ODOO_DEF_VERS +fi + +# Check if odoo version is supported +odoo_verscheck ODOO_VERS +if [ $? -eq 0 ]; then + echo "[-] $odmsg_014_1 $ODOO_VERS $odmsg_014_2" + exit 2 fi # Create odoo project path -odoo_structure $BIN_HOME "$1" +odoo_structure $BIN_HOME "$PROJECT_NAME" # Copy dockerfile template file to build (local) -copy_dockerfile $BIN_HOME "$1" "$BIN_HOME/$ODOO_CFG/$DOCKER_LOCAL" +copy_dockerfile $BIN_HOME "$PROJECT_NAME" "$BIN_HOME/$ODOO_CFG/$DOCKER_LOCAL" # Copy odoo config template file to etc (base) -copy_odooconfig $BIN_HOME "$1" "$BIN_HOME/$ODOO_CFG/$ODOO_CFG_BASE" +copy_odooconfig $BIN_HOME "$PROJECT_NAME" "$BIN_HOME/$ODOO_CFG/$ODOO_CFG_BASE" # Create odoo.log on etc -create_odoolog $BIN_HOME "$1" +create_odoolog $BIN_HOME "$PROJECT_NAME" + +# Copy odoo base apps to project +copy_odooapps $BIN_HOME "$PROJECT_NAME" "${ODOO_VERS}" $ODOO_PKG_BASE + +# Copy odoo devs apps to project +copy_odooapps $BIN_HOME "$PROJECT_NAME" "${ODOO_VERS}" $ODOO_PKG_DEVS + +# Copy odoo ai apps to project +copy_odooapps $BIN_HOME "$PROJECT_NAME" "${ODOO_VERS}" $ODOO_PKG_INAR