Mauro Rosero P
39c7aecbae
- Se crea una rama devs de trabajo o desarrollo - Se crea una rama v<n> donde <n> representa la versión de odoo para producción
215 lines
4.5 KiB
Bash
215 lines
4.5 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Library: base.lib
|
|
# Modified: 2024/11/30 15:27:00
|
|
# Derechos de Autor (C) [2024] [Mauro Rosero P. <mauro@roser.one>]
|
|
#
|
|
# Este programa es software libre: usted puede redistribuirlo y/o modificarlo
|
|
# bajo los términos de la Licencia Pública Affero General de GNU tal como
|
|
# lo publica la Free Software Foundation, ya sea la versión 3 de la licencia,
|
|
# o (a su elección) cualquier versión posterior.
|
|
#
|
|
# Este programa se distribuye con la esperanza de que sea útil,
|
|
# pero SIN NINGUNA GARANTÍA; sin siquiera la garantía implícita de
|
|
# COMERCIABILIDAD o IDONEIDAD PARA UN PROPÓSITO PARTICULAR. Consulte la
|
|
# Licencia Pública Affero General de GNU para obtener más detalles.
|
|
#
|
|
# Debería haber recibido una copia de la Licencia Pública Affero General
|
|
# junto con este programa. Si no la recibió, consulte <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
# Test library
|
|
function baselib_test() {
|
|
echo "Base Library loaded!"
|
|
exit 1
|
|
}
|
|
|
|
# Load messages
|
|
function load_messages() {
|
|
local BIN_PATH=$1
|
|
local MSG_PATH=$2
|
|
local LANGUAGE=$3
|
|
local MSG_FILE=$4
|
|
|
|
if [ -f $BIN_PATH/$MSG_PATH/$MSG_FILE.$LANGUAGE ]
|
|
then
|
|
source $BIN_PATH/$MSG_PATH/$MSG_FILE.$LANGUAGE
|
|
else
|
|
source $BIN_PATH/$MSG_PATH/$MSG_FILE.es
|
|
fi
|
|
}
|
|
|
|
# Display text header apps
|
|
function display_text_header() {
|
|
local PROJECT=$1
|
|
local tittle=$2
|
|
|
|
clear
|
|
echo "$(cat < $PROJECT/config/project.head) $tittle"
|
|
echo "============================================================"
|
|
}
|
|
|
|
# Verify if your program or command is installed
|
|
function command_installed() {
|
|
local PROGRAM=$1
|
|
|
|
if command -v $PROGRAM &> /dev/null; then
|
|
return 0
|
|
fi
|
|
|
|
# No program or command is installed
|
|
return 1
|
|
}
|
|
|
|
# Install os packages
|
|
function os_pkgs_install() {
|
|
|
|
local PACKAGE=$1
|
|
|
|
echo "${pkg_install_begin} ${PACKAGE}"
|
|
if [ "$(uname)" == "Darwin" ]; then
|
|
# En macOS, a través de Homebrew
|
|
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
|
brew install $PACKAGE
|
|
elif [ -f /etc/debian_version ] || [ -f /etc/os-release ]; then
|
|
# En sistemas Debian y derivados, a través de apt
|
|
apt update
|
|
apt install -y $PACKAGE
|
|
elif [ -f /etc/redhat-release ]; then
|
|
# En sistemas Red Hat y derivados, a través de dnf
|
|
dnf install -y $PACKAGE
|
|
elif [ -f /etc/arch-release ]; then
|
|
# En Arch Linux, a través de pacman
|
|
pacman -Sy --noconfirm $PACKAGE
|
|
elif [ -f /etc/rc.conf ]; then
|
|
# En BSD, a través de pkg
|
|
pkg install -y $PACKAGE
|
|
else
|
|
echo "${os_nofound}"
|
|
exit 1
|
|
fi
|
|
echo "${pkg_install_success} ${PACKAGE}"
|
|
|
|
}
|
|
|
|
# Update or upgrade OS Packages
|
|
function os_update() {
|
|
|
|
if [ "$(uname)" == "Darwin" ]; then
|
|
echo "$os_update (BREW)"
|
|
brew upgrade
|
|
elif [ -f /etc/debian_version ] || [ -f /etc/os-release ]; then
|
|
echo "$os_update (APT)"
|
|
apt update && apt upgrade -y
|
|
elif [ -f /etc/redhat-release ]; then
|
|
echo "$os_update (DNF)"
|
|
dnf update -y
|
|
elif [ -f /etc/arch-release ]; then
|
|
echo "$os_update (PACMAN)"
|
|
pacman -Syu
|
|
elif [ -f /etc/rc.conf ]; then
|
|
echo "$os_update (PKG)"
|
|
pkg update && pkg upgrade
|
|
else
|
|
echo "${os_nofound}"
|
|
exit 1
|
|
fi
|
|
|
|
}
|
|
|
|
# Check for container manager installed
|
|
function container_mode() {
|
|
|
|
command_installed "podman"
|
|
if [ $? -eq 0 ]
|
|
then
|
|
return 0
|
|
else
|
|
command_installed "docker"
|
|
if [ $? -eq 0 ]
|
|
then
|
|
return 1
|
|
fi
|
|
fi
|
|
|
|
# Exit with code 255 if not docker or podman installed
|
|
return 255
|
|
|
|
}
|
|
|
|
# Git init repository
|
|
function git_init() {
|
|
|
|
local REPO_PATH=$1
|
|
local BRANCH=$2
|
|
|
|
git init "$REPO_PATH" -b $BRANCH
|
|
return $?
|
|
|
|
}
|
|
|
|
# Git add tracked files to repository
|
|
function git_add_full() {
|
|
|
|
local REPO_PATH=$1
|
|
|
|
cd $REPO_PATH
|
|
if [ $? -eq 0 ]; then
|
|
git add .
|
|
return $?
|
|
else
|
|
return 255
|
|
fi
|
|
|
|
}
|
|
|
|
# Git add tracked files to repository
|
|
function git_commit() {
|
|
|
|
local REPO_PATH=$1
|
|
local GIT_MESSAGES=$2
|
|
|
|
cd $REPO_PATH
|
|
if [ $? -eq 0 ]; then
|
|
git commit -m "$GIT_MESSAGES"
|
|
return $?
|
|
else
|
|
return 255
|
|
fi
|
|
|
|
}
|
|
|
|
# Git clone repository
|
|
function git_clone_pull() {
|
|
|
|
local REPO_PATH=$1
|
|
local REPO_REMOTE=$2
|
|
local APPS=$3
|
|
|
|
if [ ! -d $REPO_PATH/$APPS ]
|
|
then
|
|
cd $REPO_PATH
|
|
if [ $? -eq 0 ]; then
|
|
git clone $REPO_REMOTE $APPS
|
|
return $?
|
|
else
|
|
return 255
|
|
fi
|
|
else
|
|
cd $REPO_PATH/$APPS
|
|
if [ $? -eq 0 ]; then
|
|
git pull
|
|
return $?
|
|
else
|
|
return 255
|
|
fi
|
|
fi
|
|
}
|
|
|
|
function check_server() {
|
|
|
|
local SERVER=$1
|
|
|
|
ping -c 1 $SERVER > /dev/null 2>&1 && return 0 || return 1
|
|
|
|
}
|