devs/bin/vpn_install.sh

159 lines
3.8 KiB
Bash
Executable file

#!/bin/bash
#Script : vpn_install.sh
#Apps : MRDEVS TOOLS
#Description : Instala Cliente de VPN PRITUNL
#Author : Mauro Rosero Pérez
#Company Email : mauro@rosero.one
#Personal Email : mauro.rosero@gmail.com
#Created : 2024/12/01 15:27:00
#Modified : 2025/03/19 11:57:08
#Version : 1.2.0
#Use Notes :
#==============================================================================
# Derechos de Autor [2025] [Mauro Rosero P. <mauro@rosero.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/>.
# Configuración inicial
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Leer DEVSPATH desde el archivo de configuración o usar "devs" por defecto
if [ -f "$SCRIPT_DIR/config/devspath.dat" ]; then
DEVSPATH=$(cat "$SCRIPT_DIR/config/devspath.dat")
else
DEVSPATH="devs"
fi
BIN_HOME="$HOME/$DEVSPATH"
BIN_BASE="bin"
BIN_LIBS="lib"
BIN_MESG="msg"
BIN_CFGS="config"
VERSION=$(cat "$BIN_HOME/$BIN_BASE/$BIN_CFGS/version")
# CHECK SHELL LANGUAGE
BIN_LANG=${LANG:0:2}
# Importar bibliotecas necesarias
source "${BIN_HOME}/${BIN_BASE}/${BIN_LIBS}/base.lib"
# Cargar mensajes en el idioma del sistema o español por defecto
load_messages "${BIN_HOME}/${BIN_BASE}" "${BIN_MESG}" "${BIN_LANG}" "head"
# Variables globales
title="${head_000} ${head_002}"
function load_bootstrap_msg() {
local BIN_PATH=$1
local MSG_PATH=$2
local LANGUAGE=$3
# Load head messages
load_messages $BIN_PATH $MSG_PATH $LANGUAGE "head"
# Load bootstrap messages
load_messages $BIN_PATH $MSG_PATH $LANGUAGE "bootstrap"
}
# Function to display help message
function help() {
echo "$bomsg_101_1 $0 $bomsg_101_2"
echo "$bomsg_102"
echo "$bomsg_103"
echo "$bomsg_104"
echo "$bomsg_105"
echo "$bomsg_106"
}
function install() {
local BIN_PATH=$1
local LIBRARY=$2
local MESSAGES=$3
local INSTALL_LANG=$4
local UPDATE=$5
# Load base bash library
BIN_HOME=$BIN_PATH
source $BIN_PATH/$LIBRARY/base.lib
# Load bootstrap bash library
source $BIN_PATH/$LIBRARY/bootstrap.lib
# Load bootstrap messages
load_bootstrap_msg $BIN_PATH $MESSAGES $INSTALL_LANG
# Install pritunl vpn client (gui)
if $UPDATE; then
update_pritunl
rc=$?
else
install_pritunl
rc=$?
fi
case $rc in
0)
echo "$bomsg_013"
;;
10)
echo "$bomsg_014"
;;
*)
echo "$bomsg_012"
;;
esac
}
# Check for arguments option
help=false
version=false
update=false
title=$bomsg_010
while [[ $# -gt 0 ]]; do
case $1 in
--help)
help=true
shift
;;
--version)
version=true
shift
;;
--update)
title="$bomsg_015"
update=true
shift
;;
esac
done
# Check to show help
if $help; then
help
exit 0
fi
# Check to show command version
if $version; then
echo "$head_version $VERSION"
exit 0
fi
# Display Headers
display_devstools_header "PRITUNL VPN"
# Run install with sudo
BIN_USER=$(echo $BIN_HOME/$BIN_BASE)
sudo bash -c "$(declare -f load_bootstrap_msg; declare -f install); install $BIN_USER $BIN_LIBS $BIN_MESG $BIN_LANG $update"