diff --git a/bin/configure.sh b/bin/configure.sh index 0ae5510..0b5a558 100755 --- a/bin/configure.sh +++ b/bin/configure.sh @@ -31,6 +31,10 @@ BIN_LANG=${LANG:0:2} source $BIN_HOME/$BIN_LIBS/base.lib #baselib_test +# LOAD CONSOLE BASH LIBRARY +source $BIN_HOME/$BIN_LIBS/console.lib +#consolelib_test + # LOAD ODOO BASH LIBRARY source $BIN_HOME/$BIN_LIBS/odoo.lib #odoolib_test @@ -43,16 +47,38 @@ load_messages $BIN_HOME $BIN_MESG $BIN_LANG "odoo" # Function to display help message function help() { - echo "$odmsg_003_1 $0 $odmsg_003_2" + echo "$odmsg_003_1 $0 $odmsg_019_2" echo "$odmsg_004" 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}" +function odoo_configure_form() { + + declare -a response c_lbl, c_hlp, c_mod, c_opt, c_val, c_dat + + # Define gpg capture form + c_lbl[0]="${odlbl_000}" + c_hlp[0]="${odhlp_000}" + c_mod[0]=1 + c_opt[0]=0 + c_val[0]=013 + c_dat[0]="${ODOO_CFG_VERS[@]}" + c_end=1 + + dialog_form +} + +########### MAIN PROGRAM ########### + +# Check if dialog is not installed, exited! +if ! command -v dialog >/dev/null 2>&1 +then + display_text_header $BIN_HOME "${odmsg_000} ${odmsg_101}" + echo "${head_001}" + exit 200 +fi # Check for arguments option help=false @@ -67,15 +93,6 @@ while [[ $# -gt 0 ]]; do 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" @@ -106,15 +123,38 @@ if [[ -z $PROJECT_NAME ]]; then exit 1 fi -# Set odoo default version, if odoo version is not defined -if [[ ! -n $ODOO_VERS ]]; then - ODOO_VERS=$ODOO_DEF_VERS +# Set program title +title="$(cat < $BIN_HOME/config/project.head) ${odmsg_000}" +apps_title="${odmsg_101} ${PROJECT_NAME^^}" + +# Check if os is valid! +get_osname +if [ "${os_name}" == "${head_unknow}" ] +then + dialog_error_box "${head_error}" "${head_os_error}" + exit 3 fi -# Check if odoo version is supported -odoo_verscheck $ODOO_VERS -if [ $? -ne 0 ]; then - echo "[-] $odmsg_014_1 $ODOO_VERS $odmsg_014_2" - exit 2 -fi +# Configure odoo devs environment for project +dialog_yesno "${odmsg_201} ${PROJECT_NAME}?" +case ${result} in + 0) + odoo_configure_form + case $? in + 0) + clear + exit 0 + ;; + *) + dialog_error_box "${head_info}" "${head_op_error}" + ;; + esac + ;; + *) + dialog_error_box "${head_info}" "${head_op_error}" + ;; +esac +# Clear console and exit +clear +exit 0 diff --git a/bin/lib/base.lib b/bin/lib/base.lib index aa0f104..2073022 100644 --- a/bin/lib/base.lib +++ b/bin/lib/base.lib @@ -206,6 +206,34 @@ function git_clone_pull() { fi } +# Check for valid os system +function get_osname() { + + if [ "$(uname)" == "Darwin" ]; then + # En macOS, instalamos o actualizamos a través de Homebrew + os_name=$(sw_vers -productVersion | awk -F '.' '{print "macOS " $1 "." $2}') + elif [ -f /etc/debian_version ] || [ -f /etc/os-release ]; then + # En sistemas Debian y derivados, instalamos o actualizamos a través de apt + os_name=$(grep "^ID_LIKE=" /etc/os-release | cut -d= -f2) + if grep -qi "${head_ubuntu}" /etc/os-release + then + os_name="${head_ubuntu}" + fi + elif [ -f /etc/redhat-release ]; then + # En sistemas Red Hat, instalamos o actualizamos a través de dnf + os_name=$(awk '{print $1}' /etc/redhat-release) + elif [ -f /etc/arch-release ]; then + # En Arch Linux, instalamos o actualizamos a través de pacman + os_name=$(grep '^NAME=' /etc/os-release | awk -F '"' '{print $2}') + elif [ -f /etc/rc.conf ]; then + # En BSD, instalamos o actualizamos a través de pkg + os_name=$(awk '{print $2}' /etc/version | awk -F '-' '{print $1}') + else + os_name="${head_unknow}" + fi + +} + function check_server() { local SERVER=$1 diff --git a/bin/lib/console.lib b/bin/lib/console.lib index 29e3dc8..1773c34 100755 --- a/bin/lib/console.lib +++ b/bin/lib/console.lib @@ -23,6 +23,11 @@ CROWS=8 CX=4 CY=2 +# Test console library +function consolelib_test() { + echo "Console Library loaded!" +} + # Dialog Yes/No Question function dialog_yesno() { @@ -165,6 +170,8 @@ function dialog_validate_input() { local value="$2" local label="$3" + local valid_data="$4" + local email_regex='^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$' local gpg_duration_regex="^[0-9]+([dmy])?$" local domain_regex="^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|([a-zA-Z0-9]+[a-zA-Z0-9-]*[a-zA-Z0-9]+))(\.([a-zA-Z]{2,})){1,}$" @@ -209,6 +216,17 @@ function dialog_validate_input() { return 1 fi ;; + 013) + for item in "${valid_data}" + do + if [[ "$item" == "$value" ]] + then + return 0 + fi + done + dialog_error_box "${head_error}" "${vldt_013}" + return 1 + ;; esac done fi @@ -230,7 +248,7 @@ function dialog_form() { dialog_input_box "[${control}] ${c_lbl[control]}" "${c_hlp[control]}" if [ ${codex} -eq 0 ] then - dialog_validate_input "${c_val[control]}" "${value}" "${c_lbl[control]}" + dialog_validate_input "${c_val[control]}" "${value}" "${c_lbl[control]}" "${c_dat[control]}" if [ $? -eq 0 ] then response[control]="${value}" @@ -345,4 +363,6 @@ function dialog_form() { esac done + return 0 + } diff --git a/bin/lib/odoo.lib b/bin/lib/odoo.lib index f2bf287..bb8d05c 100644 --- a/bin/lib/odoo.lib +++ b/bin/lib/odoo.lib @@ -33,7 +33,7 @@ ODOO_LOG=odoo.log ODOO_DEF_VERS="18" ODOO_DEF_BRCH=devs -ODOO_CFG_VARS=("18") +ODOO_CFG_VERS=("18") ODOO_PKG_BASE=base ODOO_PKG_DEVS=devs @@ -58,7 +58,7 @@ function odoo_verscheck() { local value=$1 - for item in "${ODOO_CFG_VARS[@]}" + for item in "${ODOO_CFG_VERS[@]}" do if [[ "$item" == "$value" ]] then diff --git a/bin/msg/head.es b/bin/msg/head.es index 13b1df2..f5a0963 100644 --- a/bin/msg/head.es +++ b/bin/msg/head.es @@ -12,13 +12,32 @@ #============================================================================== head_000="(MRDEVOPS TOOLS)" -head_001="El comando 'dialog' no está instalado. Por favor, ejecute bootstrap.sh." +head_001="El comando 'dialog' no está instalado. Por favor, ejecute bin/bootstrap.sh." head_installing="Instalando" head_info="INFO" head_warning="ADVERTENCIA" head_error="ERROR" head_unknow="UNKNOW" head_version="Versión" +head_ubuntu="ubuntu" +head_confirm="(confirmar)" +head_os_error="Operación Cancelada. No se pudo determinar el sistema operativo." +head_op_error="Operación cancelada por el operador!" +head_pause="Presiona Enter para continuar..." +head_error_unknow="Operación Cancelada. Se produjo un error desconocido!" +head_fail="Fail" +head_exit="Finalizar" +head_create="Adicionar" +head_delete="Eliminar" + +label_email="Correo Electrónico:" + +vldt_001="no puede estar en blanco..." +vldt_002="Contraseña incorrecta! Intente nuevamente." +vldt_010="Dirección de correo electrónico es inválida!" +vldt_011="Duración de clave gpg inválida!" +vldt_012="No es un nombre de dominio DNS válido!" +vldt_013="Valor incorrecto!" os_update="Actualizando sistema operativo " os_nofound="Sistemas operativos soportados: Ubuntu, Debian, Arch Linux, Fedora, Redhat, AlmaLinux, Rocky, Oracle Linux, FreeBSD, MacOS" diff --git a/bin/msg/odoo.es b/bin/msg/odoo.es index c855d21..544a27d 100644 --- a/bin/msg/odoo.es +++ b/bin/msg/odoo.es @@ -14,10 +14,11 @@ odmsg_000="(ODOO TOOLS)" odmsg_001="- INICIALIZACIÓN" odmsg_100="- INSTALAR" +odmsg_101="CONFIGURE PROYECTO" odmsg_002="Ambiente de desarrollo Odoo no instalado!" odmsg_003_1="Uso:" -odmsg_003_2=" [--help] [--version] [--odoo ]" -odmsg_004="Descripción: Este script requiere como argumento obligatorio." +odmsg_003_2=" [--help] [--version] [--odoo ]" +odmsg_004="Descripción: Este script requiere como argumento obligatorio." odmsg_005="Opciones:" odmsg_006=" --help Muestra este mensaje de ayuda." odmsg_007=" --version Muestra la versión del script." @@ -36,3 +37,11 @@ odmsg_015=" --odoo Identifica la versión de odoo a configurar. Default:" odmsg_016="Odoo Pack no instalado!" odmsg_017_2="[--help] [--version] [--odoo ]" odmsg_018="Descripción: Este script instala o actualiza el pack" +odmsg_019_2=" [--help] [--version]" + + +odmsg_201="Desea configurar ambiente de desarrollo para el proyecto" + +# Input: Versión Odoo +odlbl_000="Versión Odoo" +odhlp_000="Especificar la versión de odoo en uso"