#!/bin/bash # # Library: bootstrap.lib # Description: Bootstrap Developers Library # Modified: 2024/11/30 15:27:00 # Derechos de Autor (C) [2024] [Mauro Rosero P. ] # # 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 . SOPS_VERSION=3.9.2 PRITUNL_SIGN=7568D9BB55FF9E5287D586017AE645C0CF8E292A PRITUNL_UPDT=1.3.4099.99 UBUNTU_LIST=("jammy" "noble" "oracular") UBUNTU_UPDT_LIST=("noble" "oracular") # Install pritunl vpn package function install_pritunl() { if [ "$(uname)" == "Darwin" ]; then # En macOS, instalamos o actualizamos Python a través de Homebrew brew install git go node bash <(curl -s https://raw.githubusercontent.com/pritunl/pritunl-client-electron/master/tools/install_macos.sh) return $? fi OS_INFO=$(lsb_release -a 2>/dev/null) if [ $? -eq 0 ]; then OS_VERSION=$(echo "$OS_INFO" | grep "Codename" | awk '{print $2}' | tr -d ' ') else OS_INFO=$(cat /etc/os-release 2>/dev/null) OS_VERSION=$(echo "$OS_INFO" | grep "VERSION_CODENAME" | awk -F ': +' '{print $2}') fi if echo "$OS_INFO" | grep -q "Ubuntu"; then if printf "%s\n" "${UBUNTU_LIST[@]}" | grep -q "^${OS_VERSION}$" then if [ ! -f /etc/apt/sources.list.d/pritunl.list ]; then echo "deb https://repo.pritunl.com/stable/apt $OS_VERSION main" > /etc/apt/sources.list.d/pritunl.list fi if [ ! -f /etc/apt/trusted.gpg.d/pritunl.asc ]; then gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys $PRITUNL_SIGN gpg --armor --export $PRITUNL_SIGN | tee /etc/apt/trusted.gpg.d/pritunl.asc fi apt update apt install pritunl-client-electron -y local rc=$? if [ $rc -eq 0 ]; then systemctl daemon-reload rc=$? fi return $rc fi fi return 10 } # Update pritunl vpn package function update_pritunl() { OS_INFO=$(lsb_release -a 2>/dev/null) if [ $? -eq 0 ]; then OS_VERSION=$(echo "$OS_INFO" | grep "Codename" | awk '{print $2}' | tr -d ' ') else OS_INFO=$(cat /etc/os-release 2>/dev/null) OS_VERSION=$(echo "$OS_INFO" | grep "VERSION_CODENAME" | awk -F ': +' '{print $2}') fi if echo "$OS_INFO" | grep -q "Ubuntu"; then if printf "%s\n" "${UBUNTU_UPDT_LIST[@]}" | grep -q "^${OS_VERSION}$" then cd /tmp wget https://github.com/pritunl/pritunl-client-electron/releases/download/$PRITUNL_UPDT/pritunl-client-electron_$PRITUNL_UPDT-0ubuntu1.${OS_VERSION}_amd64.deb dpkg -i pritunl-client-electron_$PRITUNL_UPDT-0ubuntu1.${OS_VERSION}_amd64.deb return $? fi fi return 10 } # Install python3 package function python3_install() { echo "${pymsg_001}" if [ "$(uname)" == "Darwin" ]; then # En macOS, instalamos o actualizamos Python a través de Homebrew /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" brew install python elif [ -f /etc/debian_version ] || [ -f /etc/os-release ]; then # En sistemas Debian y derivados, instalamos o actualizamos Python a través de apt apt update apt install -y python3 elif [ -f /etc/redhat-release ]; then # En sistemas Red Hat, instalamos o actualizamos Python a través de yum dnf install -y python3 elif [ -f /etc/arch-release ]; then # En Arch Linux, instalamos o actualizamos Python a través de pacman pacman -Sy --noconfirm python elif [ -f /etc/rc.conf ]; then # En BSD, instalamos o actualizamos Python a través de pkg pkg install -y python3 else echo "${os_nofound}" exit 1 fi echo "${pymsg_003}" } # Update python3 package function python3_update() { echo "Actualizando Python..." # Verificar si Python está instalado command_installed python3 if [ $? -ne 0 ]; then # Si Python no está instalado, llamamos a la función de instalación python3_install return $? fi # Actualizar Python según el sistema operativo if [ "$(uname)" == "Darwin" ]; then # En macOS, actualizamos Python a través de Homebrew brew upgrade python elif [ -f /etc/debian_version ] || [ -f /etc/os-release ]; then # En sistemas Debian y derivados apt update apt install --only-upgrade -y python3 elif [ -f /etc/redhat-release ]; then # En sistemas Red Hat dnf upgrade -y python3 elif [ -f /etc/arch-release ]; then # En Arch Linux pacman -Syu --noconfirm python elif [ -f /etc/rc.conf ]; then # En BSD pkg upgrade -y python3 else echo "${os_nofound}" return 1 fi echo "Python actualizado correctamente." return 0 } # Install pip package function pip_install() { echo "Instalando pip..." if [ "$(uname)" == "Darwin" ]; then # En macOS, instalamos o actualizamos pip a través de Homebrew brew install python-pip elif [ -f /etc/debian_version ] || [ -f /etc/os-release ]; then # En sistemas Debian y derivados, instalamos o actualizamos pip a través de apt apt update apt install -y python3-pip elif [ -f /etc/redhat-release ]; then # En sistemas Red Hat, instalamos o actualizamos pip a través de yum dnf install -y python3-pip elif [ -f /etc/arch-release ]; then # En Arch Linux, instalamos o actualizamos pip a través de pacman pacman -Sy --noconfirm python-pip elif [ -f /etc/rc.conf ]; then # En BSD, instalamos o actualizamos pip a través de pkg pkg install -y python3-pip else echo "${os_nofound}" exit 1 fi echo "Pip instalado correctamente." } # Update pip package function pip_update() { echo "Actualizando pip..." # Verificar si pip está instalado command_installed pip3 if [ $? -ne 0 ]; then # Si pip no está instalado, llamamos a la función de instalación pip_install return $? fi # Actualizar pip usando el método adecuado según el sistema operativo if [ "$(uname)" == "Darwin" ]; then # En macOS, actualizamos pip a través de Homebrew brew upgrade python-pip elif [ -f /etc/debian_version ] || [ -f /etc/os-release ]; then # En sistemas Debian y derivados apt update apt install --only-upgrade -y python3-pip # También actualizar usando el propio pip python3 -m pip install --upgrade pip elif [ -f /etc/redhat-release ]; then # En sistemas Red Hat dnf upgrade -y python3-pip # También actualizar usando el propio pip python3 -m pip install --upgrade pip elif [ -f /etc/arch-release ]; then # En Arch Linux pacman -Syu --noconfirm python-pip elif [ -f /etc/rc.conf ]; then # En BSD pkg upgrade -y python3-pip # También actualizar usando el propio pip python3 -m pip install --upgrade pip else echo "${os_nofound}" return 1 fi echo "Pip actualizado correctamente." return 0 } # Install mozilla sops package on os system supported function sops_install() { echo "${bomsg_006}" if [ "$(uname)" == "Darwin" ]; then # En macOS, instalamos o actualizamos Python a través de Homebrew brew install sops return $? fi # Get architecture info cd /tmp local arch=$(uname -m) case $arch in x86_64) # Download the binary curl -LO https://github.com/getsops/sops/releases/download/v$SOPS_VERSION/sops-v$SOPS_VERSION.linux.amd64 if [ $? -eq 0 ]; then # Move the binary in to your PATH mv sops-v$SOPS_VERSION.linux.amd64 /usr/local/bin/sops if [ $? -eq 0 ]; then # Make the binary executable chmod a+x /usr/local/bin/sops else return 1 fi else return 1 fi ;; arm*) # Download the binary curl -LO https://github.com/getsops/sops/releases/download/v$SOPS_VERSION/sops-v$SOPS_VERSION.linux.arm64 if [ $? -eq 0 ]; then # Move the binary in to your PATH mv sops-v$SOPS_VERSION.linux.arm64 /usr/local/bin/sops if [ $? -eq 0 ]; then # Make the binary executable chmod a+x /usr/local/bin/sops else return 1 fi else return 1 fi ;; *) echo "$bomsg_005 $arch" return 2 ;; esac echo "${bomsg_007}" return 0 } # Install podman package function podman_install() { echo "${pdmsg_001}" if [ "$(uname)" == "Darwin" ]; then # En macOS, instalamos o actualizamos Python a través de Homebrew /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" brew tap containers/podman brew install podman elif [ -f /etc/debian_version ] || [ -f /etc/os-release ]; then # En sistemas Debian y derivados, instalamos o actualizamos Python a través de apt apt update apt install -y podman podman-compose elif [ -f /etc/redhat-release ]; then # En sistemas Red Hat, instalamos o actualizamos Python a través de dnf dnf install -y epel-release dnf install -y podman podman-compose elif [ -f /etc/arch-release ]; then # En Arch Linux, instalamos o actualizamos Python a través de pacman pacman -Sy --noconfirm podman podman-compose fuse-overlayfs elif [ -f /etc/rc.conf ]; then # En BSD, instalamos o actualizamos Python a través de pkg pkg install -y podman-suite else echo "${os_nofound}" exit 1 fi echo "${pdmsg_003}" } function ansible_install() { echo "${anmsg_001}" python3 -m pip install --upgrade pip python3 -m pip install --user ansible if [ $? -eq 0 ] then echo "${anmsg_003}" return 0 fi echo "${anmsg_002}" exit 1 } # Set how unprivileged port 53 (dns) function unprivileged_port53() { local sysctlfile=/etc/sysctl.conf local line="net.ipv4.ip_unprivileged_port_start=53" if [[ ! -f $sysctlfile ]]; then return 1 fi if ! grep -q "$line" "$sysctlfile"; then echo "$line" >> $sysctlfile fi sysctl -p return $? } # Install oathtool package function oathtool_install() { echo "Instalando oathtool (herramienta para TOTP/HOTP)..." if [ "$(uname)" == "Darwin" ]; then # En macOS, instalamos a través de Homebrew brew install oath-toolkit elif [ -f /etc/debian_version ] || [ -f /etc/os-release ]; then # En sistemas Debian y derivados apt update apt install -y oathtool elif [ -f /etc/redhat-release ]; then # En sistemas Red Hat dnf install -y oath-toolkit elif [ -f /etc/arch-release ]; then # En Arch Linux pacman -Sy --noconfirm oath-toolkit elif [ -f /etc/rc.conf ]; then # En BSD pkg install -y oath-toolkit else echo "${os_nofound}" return 1 fi echo "oathtool instalado correctamente." return 0 } # Install zbar package function zbar_install() { echo "Instalando zbar (herramienta para lectura de códigos QR)..." if [ "$(uname)" == "Darwin" ]; then # En macOS, instalamos a través de Homebrew brew install zbar elif [ -f /etc/debian_version ] || [ -f /etc/os-release ]; then # En sistemas Debian y derivados apt update apt install -y zbar-tools elif [ -f /etc/redhat-release ]; then # En sistemas Red Hat dnf install -y zbar elif [ -f /etc/arch-release ]; then # En Arch Linux pacman -Sy --noconfirm zbar elif [ -f /etc/rc.conf ]; then # En BSD pkg install -y zbar else echo "${os_nofound}" return 1 fi echo "zbar instalado correctamente." return 0 }