Nombre del autor:admin

Instalar ultimo libreoffice desde la web en debian/ubuntu

Este script es solo un ejemplo de bash avanzado, puede fallar si aunque sea se modifica algo en la url principal o dentro del código html.

#!/bin/bash

# Variables
CACHE_FOLDER=/tmp
DOWNLOAD_DIR=${CACHE_FOLDER}/Libreoffice
LIBREOFFICE_URL="https://download.documentfoundation.org/libreoffice/stable/"
VERSION=$(wget -qO- $LIBREOFFICE_URL | grep -oP '[0-9]+(\.[0-9]+)+' | sort -V | tail -1)
VERSION_INSTALLED=$(/usr/local/bin/libreoffice* --version 2>/dev/null | awk '{print $2}' )

#sudo find $DOWNLOAD_DIR -type f -name "*.tar.gz" -exec rm {} \; >/dev/null 2>&1
 sudo find $DOWNLOAD_DIR -type f -name "*.deb"    -exec rm {} \; >/dev/null 2>&1
#sudo rm -rf $DOWNLOAD_DIR >/dev/null 2>&1

# TODO remove this line
#export LANG=es_AR.UTF-8

# Detectar el idioma del sistema
LANGUAGE=$(echo $LANG | cut -d'_' -f1)

# Mensajes en español e inglés
if [ "$LANGUAGE" == "es" ]; then
        LO_LANG=es
        MSG_INSTALLED="LibreOffice está instalado. ---------------------------"
           MSG_PROMPT="¿Quieres eliminar LibreOffice? (s/n): "
         MSG_REMOVING="Eliminando LibreOffice. -------------------------------"
          MSG_REMOVED="LibreOffice ha sido eliminado. ------------------------"
      MSG_NOT_REMOVED="No se ha eliminado LibreOffice. -----------------------"
    MSG_NOT_INSTALLED="LibreOffice no está instalado. ------------------------"
         MSG_SAME_VER="No es necesario actualizar. Esta actualizado. ---------"
          MSG_UPGRADE="Es necesario actualizar. ------------------------------"
       ACCEPTED_REGEX="^[Ss]$"
      MSG_DOWNLOADING="Descargando LibreOffice. ------------------------------"
    MSG_UNCOMPRESSING="Descomprimiendo los archivos tar. ---------------------"
       MSG_INSTALLING="Instalando LibreOffice y sus paquetes de lenguaje. ----"
          MSG_OPENING="Abriendo todas las aplicaciones para probarlas. -------"
             MSG_DONE="Se finalizó la instalación de Libreoffice $VERSION"
else
        if [ "$LANGUAGE" == "de" ] || [ "$LANGUAGE" == "fr" ] || [ "$LANGUAGE" == "ja" ] || [ "$LANGUAGE" == "pl" ] \
        || [ "$LANGUAGE" == "ru" ] || [ "$LANGUAGE" == "ro" ] || [ "$LANGUAGE" == "it" ] || [ "$LANGUAGE" == "ko" ] \
        || [ "$LANGUAGE" == "gl" ]      ; then                                                                                                                                               
                LO_LANG=$LANGUAGE                                                                                                                                                            
        elif [ "$LANGUAGE" == "en" ] ; then                                                                                                                                                  
                LO_LANG=""                                                                                                                                                                   
        else                                                                                                                                                                                 
                LANG_LIST=$(wget -qO- ${LIBREOFFICE_URL}${VERSION}/deb/x86_64/ | grep -oP 'langpack_\K[^.]+(?=\.tar\.gz<)')                                                                  
                OPTIONS=()                                                                                                                                                                   
                for LANG in $LANG_LIST; do
                    OPTIONS+=("$LANG" "$LANG")
                done
                LO_LANG=$(whiptail --title "Select your language" --menu "Use the arrows and enter to select:" 20 60 10 "${OPTIONS[@]}" 3>&1 1>&2 2>&3)
        fi
        MSG_INSTALLED="LibreOffice is installed. -----------------------------"
           MSG_PROMPT="Do you want to remove LibreOffice? (y/n): "
         MSG_REMOVING="Removing LibreOffice. ---------------------------------"
          MSG_REMOVED="LibreOffice has been removed. -------------------------"
      MSG_NOT_REMOVED="LibreOffice was not removed. --------------------------"
    MSG_NOT_INSTALLED="LibreOffice is not installed. -------------------------"
         MSG_SAME_VER="Upgrade is not needed. It is up to date. --------------"
          MSG_UPGRADE="Upgrade is needed. ------------------------------------"
       ACCEPTED_REGEX="^[Yy]$"
      MSG_DOWNLOADING="Downloading LibreOffice. ------------------------------"
    MSG_UNCOMPRESSING="Uncompressing tar files. ------------------------------"
       MSG_INSTALLING="Installing LibreOffice and its language pack. ---------"
          MSG_OPENING="Opening all applications to test. ---------------------"
             MSG_DONE="Installation done. Libreoffice $VERSION "
fi

# TODO remove this line
export LC_ALL=C LANGUAGE=C LANG=C

# Verificar si LibreOffice está instalado
dpkg -l | grep libreoffice &> /dev/null

if [ $? -eq 0 ]; then
    echo "$MSG_INSTALLED"
    dpkg -l | grep libreoffice
    echo $VERSION_INSTALLED | grep $VERSION >/dev/null
    if [ "$?" == "0" ] ; then
        echo WEB "$VERSION" LOCAL "$VERSION_INSTALLED"
        echo "$MSG_SAME_VER"
        exit
    else
        echo WEB "$VERSION" LOCAL "$VERSION_INSTALLED"
        echo "$MSG_UPGRADE"
    fi
    read -p "$MSG_PROMPT" respuesta
    if [[ "$respuesta" =~ $ACCEPTED_REGEX ]]; then
        echo "$MSG_REMOVING"
        sudo apt-get remove --purge -y $(dpkg -l | awk '{print $2}' | grep ^libreoffice) >/dev/null
        sudo apt-get autoremove -y >/dev/null
        sudo apt-get clean >/dev/null 2>&1
        echo "$MSG_REMOVED"
    else
        echo "$MSG_NOT_REMOVED"
    fi
else
    echo "$MSG_NOT_INSTALLED"
fi

echo "$MSG_DOWNLOADING"
        sudo mkdir -p $DOWNLOAD_DIR >/dev/null 2>&1
        sudo wget --show-progress -qN ${LIBREOFFICE_URL}${VERSION}/deb/x86_64/LibreOffice_${VERSION}_Linux_x86-64_deb.tar.gz -P $DOWNLOAD_DIR
        if [ ! -z "$LO_LANG" ] ; then
                sudo wget --show-progress -qN ${LIBREOFFICE_URL}${VERSION}/deb/x86_64/LibreOffice_${VERSION}_Linux_x86-64_deb_langpack_$LO_LANG.tar.gz -P $DOWNLOAD_DIR
                sudo wget --show-progress -qN ${LIBREOFFICE_URL}${VERSION}/deb/x86_64/LibreOffice_${VERSION}_Linux_x86-64_deb_helppack_$LO_LANG.tar.gz -P $DOWNLOAD_DIR
        fi

echo "$MSG_UNCOMPRESSING"
        sudo tar -xzf $DOWNLOAD_DIR/LibreOffice_${VERSION}_Linux_x86-64_deb.tar.gz -C $DOWNLOAD_DIR
        if [ ! -z "$LO_LANG" ] ; then
                sudo tar -xzf $DOWNLOAD_DIR/LibreOffice_${VERSION}_Linux_x86-64_deb_langpack_$LO_LANG.tar.gz -C $DOWNLOAD_DIR
                sudo tar -xzf $DOWNLOAD_DIR/LibreOffice_${VERSION}_Linux_x86-64_deb_helppack_$LO_LANG.tar.gz -C $DOWNLOAD_DIR
        fi

echo "$MSG_INSTALLING"
        sudo dpkg -i $(find $DOWNLOAD_DIR/ -type f -name \*.deb) >/dev/null 2>&1
        sudo apt install --fix-broken -y >/dev/null 2>&1
<<'SKIPTHIS'
echo "$MSG_OPENING"
        LANG=$LANG /usr/local/bin/libreoffice* --base    >/dev/null 2>&1 &
        sleep 2
        LANG=$LANG /usr/local/bin/libreoffice* --calc    >/dev/null 2>&1 &
        sleep 2
        LANG=$LANG /usr/local/bin/libreoffice* --draw    >/dev/null 2>&1 &
        sleep 2
        LANG=$LANG /usr/local/bin/libreoffice* --impress >/dev/null 2>&1 &
        sleep 2
        LANG=$LANG /usr/local/bin/libreoffice* --math    >/dev/null 2>&1 &
        sleep 2
        LANG=$LANG /usr/local/bin/libreoffice* --writer  >/dev/null 2>&1 &
        sleep 2
        LANG=$LANG /usr/local/bin/libreoffice*           >/dev/null 2>&1 &
SKIPTHIS

echo "$MSG_DONE"
        dpkg -l | grep libreoffice

Las siguientes son versiones viejas

#!/bin/bash
#Optional remove any old libreoffice
#apt remove --purge libreoffice* && apt autoremove -y

echo "Downloading Libreoffice -------------------------------------"
        # Variables
        CACHE_FOLDER=/var/cache/apt/archives
        LO_LANG=es  # Idioma para la instalación
        export LC_ALL=C LANGUAGE=C LANG=C
        export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
        DOWNLOAD_DIR=${CACHE_FOLDER}/Libreoffice
        LIBREOFFICE_URL="https://download.documentfoundation.org/libreoffice/stable/"
        VERSION=$(wget -qO- $LIBREOFFICE_URL | grep -oP '[0-9]+(\.[0-9]+)+' | sort -V | tail -1)

        mkdir -p $DOWNLOAD_DIR >/dev/null 2>&1
        wget -qN ${LIBREOFFICE_URL}${VERSION}/deb/x86_64/LibreOffice_${VERSION}_Linux_x86-64_deb.tar.gz -P $DOWNLOAD_DIR
        wget -qN ${LIBREOFFICE_URL}${VERSION}/deb/x86_64/LibreOffice_${VERSION}_Linux_x86-64_deb_langpack_$LO_LANG.tar.gz -P $DOWNLOAD_DIR
        tar -xzf $DOWNLOAD_DIR/LibreOffice_${VERSION}_Linux_x86-64_deb.tar.gz -C $DOWNLOAD_DIR
        tar -xzf $DOWNLOAD_DIR/LibreOffice_${VERSION}_Linux_x86-64_deb_langpack_$LO_LANG.tar.gz -C $DOWNLOAD_DIR

echo Installing LibreOffice and its language pack ----------------
        dpkg -i $(find $DOWNLOAD_DIR/ -type f -name \*.deb)
        apt install --fix-broken -y
        echo LibreOffice \$VERSION installation done.

#!/bin/bash
inestable=no
if [ "$inestable" == "no" ]; then 
        filtro="-v"
else
        filtro=""
fi
paquetes=$(dpkg -l | grep libreoffice | grep $filtro dev | awk '{print $2}')
if [ ! -z "$paquetes" ] ; then
        echo Esto es lo que tenemos hoy dia
        echo $paquetes

        echo Limpiando todo
        echo --desinstalando
        sudo apt remove $paquetes

        paquetes_restantes=$(dpkg -l | grep libreoffice | grep $filtro dev | awk '{print $2}')
        if [ ! -z "$paquetes_restantes" ] ; then
                echo --limpiando
                sudo dpkg --purge $paquetes_restantes
        fi
echo Listo
fi

#find /tmp/  -name "*?ibre?ffice*" -exec rm -rf {} \;

#padre base de la version
base_inestable0=libreoffice-24

#url base de dailys
base_inestable1=https://dev-builds.libreoffice.org/daily/

#hija base de la version
##TODO Esto seguramente haya que ponerle un tail o algo cuando hayan mas versiones 24
base_inestable2=$(curl -s $base_inestable1 | grep href | grep $base_inestable0 | cut -d "=" -f 7 | sed 's/\"//g' | cut -d "/" -f 1)

#archivo final
base_inestable3=$(curl -s ${base_inestable1}${base_inestable2}/Linux-rpm_deb-x86_64@tb99-TDF/current/ | grep x86-64_deb.tar.gz | sed 's/href/@/g'  | cut -d '@' -f 3 | cut -d '"' -f 2)

#url final con archivo final
base_inestable4=${base_inestable1}${base_inestable2}/Linux-rpm_deb-x86_64@tb99-TDF/current/${base_inestable3}

#archivo lenguaje español
base_inestable5=$(curl -s ${base_inestable1}${base_inestable2}/Linux-rpm_deb-x86_64@tb99-TDF/current/ | grep Linux_x86-64_deb_langpack_es.tar.gz | sed 's/href/@/g'  | cut -d '@' -f 2 | cut -d '"' -f 2)

base_inestable6=${base_inestable1}${base_inestable2}/Linux-rpm_deb-x86_64@tb99-TDF/current/${base_inestable5}

#COMENTADO PARA DEBUG SOLAMENTE
#echo $base_inestable4
#echo $base_inestable6

entusiasta=$(curl -s https://www.libreoffice.org/download/download-libreoffice/ | grep href=\'/download/download-libreoffice| head -n1 | cut -d \= -f 4 | cut -d \& -f 1)

estable=$(curl -s https://www.libreoffice.org/download/download-libreoffice/ | grep href=\'/download/download-libreoffice| head -n2 | cut -d \= -f 4 | cut -d \& -f 1 | tail -n1)

version=$estable

if [ "$inestable" == "no" ] ; then 
        echo La version parece ser $version

        echo Descargandolo!!
        wget --show-progress -qcO /tmp/LibreOffice.tar.gz https://download.documentfoundation.org/libreoffice/stable/${version}/deb/x86_64/LibreOffice_${version}_Linux_x86-64_deb.tar.gz  #>/dev/null 2>&1
        wget --show-progress -qcO /tmp/LibreOffice_es.tar.gz https://download.documentfoundation.org/libreoffice/stable/${version}/deb/x86_64/LibreOffice_${version}_Linux_x86-64_deb_langpack_es.tar.gz 2>&1 | grep tmp #>/dev/null 2>&1
else
        echo La version inestable parece ser $base_inestable3
        wget --show-progress -qcO /tmp/LibreOffice.tar.gz $base_inestable4 
        wget --show-progress -qcO /tmp/LibreOffice_es.tar.gz $base_inestable6

fi


echo Descomprimiendo
cd /tmp
tar xzvf /tmp/LibreOffice.tar.gz >/dev/null 2>&1
tar xzvf /tmp/LibreOffice_es.tar.gz >/dev/null 2>&1


echo Instalando
sudo su -c "apt --fix-broken install -y"
find /tmp/ -type f -name "*.deb" -exec chmod +x {} \; >/dev/null 2>&1
if [ "$inestable" == "no" ] ; then
        sudo dpkg -i $(find /tmp/LibreOffice_${version}*_Linux_x86-64_deb/ -type f -name "*.deb")
        sudo dpkg -i $(find /tmp/LibreOffice_${version}*_Linux_x86-64_deb_langpack_es/ -type f -name "*.deb")
else
        sudo dpkg -i $(find /tmp/$(echo $base_inestable3 | sed 's/\.tar\.gz//g')/ -type f -name "*.deb")
        sudo dpkg -i $(find /tmp/$(echo $base_inestable5 | sed 's/\.tar\.gz//g')/ -type f -name "*.deb")

fi

Instalar ultimo libreoffice desde la web en debian/ubuntu Read More »

Leer un archivo y tomar acciones por lineas

En este ejemplo leemos el contenido de un archivo, que para el caso lo generamos antes en el ejemplo pero puede venir de otro lado.
El while en vez de usar el tipico “while read line” usamos el parámetro IFS para indicar el separador y luego de “read” colocamos en el orden correspondiente las variables que tengamos que usar más adelante. De esta forma no hace falta dividir el “line” con AWK y ECHO

#!/bin/bash

echo "Zapatos Verdes
Zapatillas Rojas
Botas Negras
Ojotas Blancas
Medias Azules" > archivo.txt

while IFS=" " read Articulo Color;do
    echo Articulo $Articulo  --  Color $Color 
done <archivo.txt | column -t

Versión original

#!/bin/bash

echo "Zapatos Verdes
Zapatillas Rojas
Botas Negras
Ojotas Blancas
Medias Azules" > archivo.txt

while read line;do
    Articulo=$(echo $line | awk '{print $1}')
       Color=$(echo $line | awk '{print $2}')
    echo Articulo $Articulo  --  Color $Color 
done <archivo.txt | column -t

Leer un archivo y tomar acciones por lineas Read More »

PowerDNS en Debian 12

Basado en parte de aquí

Prerequisitos

Servidor instalado, con hostname apuntado al ip y clave de root
Posterior instalamos mysql y nos logueamos.

sudo apt-get install mariadb-server -y
sudo mysql

Posteriormente creamos la base de datos, el usuario, su clave, flusheamos permisos y salimos

create database pdns;
grant all on pdns.* to pdnsadmin@localhost identified by 'password';
flush privileges;
exit;

Para instalar desde repositorio oficial y no el de la distribución es mejor porque está siempre actualizado. La información se sacó de acá

Instalar powerdns

Deshabilitamos el systemd-resolved, configuramos dns fijo

sudo systemctl disable --now systemd-resolved > /dev/null 2>&1
sudo rm -rf /etc/resolv.conf
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf

Crear archivo ‘/etc/apt/sources.list.d/pdns.list

#Authoritative
deb [signed-by=/etc/apt/keyrings/auth-48-pub.asc arch=amd64] http://repo.powerdns.com/debian bookworm-auth-48 main
#Recursor
deb [signed-by=/etc/apt/keyrings/rec-49-pub.asc arch=amd64] http://repo.powerdns.com/debian bookworm-rec-49 main

Crear otro archivo ‘/etc/apt/preferences.d/auth-48’

Package: auth*
Pin: origin repo.powerdns.com
Pin-Priority: 600

Crear un archivo más ‘/etc/apt/preferences.d/rec-49’

Package: rec*
Pin: origin repo.powerdns.com
Pin-Priority: 600

Ejecutar lo siguiente

echo -------------Curl--------------
sudo apt install curl -y
echo -------------keyrings Authoritative--------------
sudo install -d /etc/apt/keyrings; curl https://repo.powerdns.com/FD380FBB-pub.asc | sudo tee /etc/apt/keyrings/auth-48-pub.asc &&
echo -------------keyrings Recursor--------------
sudo install -d /etc/apt/keyrings; curl https://repo.powerdns.com/FD380FBB-pub.asc | sudo tee /etc/apt/keyrings/rec-49-pub.asc &&
sudo apt-get update &&
echo -------------pDNS Authoritative y Recursor--------------
sudo apt-get install pdns-server pdns-recursor pdns-backend-mysql -y

Creamos esquema en la base de datos (colocando la clave de arriba) y posteriormente creamos el archivo de configuración

sudo mysql -u pdnsadmin -p pdns < /usr/share/pdns-backend-mysql/schema/schema.mysql.sql
sudo vi /etc/powerdns/pdns.d/pdns.local.gmysql.conf

Dentro del archivo colocamos lo siguiente

# MySQL Configuration
#
# Launch gmysql backend
launch+=gmysql

# gmysql parameters
gmysql-host=127.0.0.1
gmysql-port=3306
gmysql-dbname=pdns
gmysql-user=pdnsadmin
gmysql-password=password
gmysql-dnssec=yes
# gmysql-socket=

Aplicamos los permisos correctos al archivo

sudo chmod 640 /etc/powerdns/pdns.d/pdns.local.gmysql.conf
sudo chown pdns:pdns /etc/powerdns/pdns.d/pdns.local.gmysql.conf

Detenemos el servicio y lo probamos manualmente con los siguientes comandos

sudo systemctl stop pdns
sudo systemctl stop pdns-recursor
sudo pdns_server --daemon=no --guardian=no --loglevel=9

Deberíamos ver algo asi

Sep 09 22:15:45 gmysql Connection successful. Connected to database ‘pdns’ on ‘127.0.0.1’.
Sep 09 22:15:45 Creating backend connection for TCP
Sep 09 22:15:45 gmysql Connection successful. Connected to database ‘pdns’ on ‘127.0.0.1’.
Sep 09 22:15:45 About to create 3 backend threads for UDP
Sep 09 22:15:45 gmysql Connection successful. Connected to database ‘pdns’ on ‘127.0.0.1’.
Sep 09 22:15:45 gmysql Connection successful. Connected to database ‘pdns’ on ‘127.0.0.1’.
Sep 09 22:15:45 gmysql Connection successful. Connected to database ‘pdns’ on ‘127.0.0.1’.
Sep 09 22:15:45 Done launching threads, ready to distribute questions

Luego, salimos con CONTROL + C y a continuación iniciamos el servicio y chequeamos el estado

sudo systemctl start pdns
sudo systemctl status pdns

Deberíamos verlo active (running) y a su vez enabled

● pdns.service – PowerDNS Authoritative Server
Loaded: loaded (/lib/systemd/system/pdns.service; enabled; preset: enabled)
Active: active (running) since Sat 2023-09-09 22:21:16 -03; 54ms ago

Veríamos el servicio escuchando en el 53 tanto en udp como tcp

ss -alnp4 | grep pdns

udp UNCONN 0 0 0.0.0.0:53 0.0.0.0:* users:((“pdns_server”,pid=4245,fd=5))
tcp LISTEN 0 128 0.0.0.0:53 0.0.0.0:* users:((“pdns_server”,pid=4245,fd=7))

Instalar pDNS Admin

Instalamos NGINX y otras dependencias (información oficial aquí)

sudo apt-get install nginx python3-dev libsasl2-dev libldap2-dev libssl-dev libxml2-dev libxslt1-dev libxmlsec1-dev libffi-dev pkg-config apt-transport-https virtualenv build-essential libmariadb-dev git python3-flask libpq-dev python3.11 pip -y

sudo apt install -y python3-dev git libsasl2-dev libldap2-dev python3-venv libmariadb-dev pkg-config build-essential curl libpq-dev

Instalamos node y también yarn (información oficial aquí y aquí)

echo -------------Node-------------------------
sudo apt-get update && sudo apt-get install -y ca-certificates curl gnupg
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update && sudo apt-get install nodejs -y

echo ------------Yarn-------------------
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install yarn

Clonamos, creamos un virtual environment, instalamos dependencias y salimos del ambiente

sudo git clone https://github.com/ngoduykhanh/PowerDNS-Admin.git /var/www/html/pdns
cd /var/www/html/pdns/

sudo chmod 777 -R flask
virtualenv -p python3 flask
source ./flask/bin/activate
pip install -r requirements.txt
deactivate

python3 -m venv ./venv
pip install --upgrade pip
pip install -r requirements.txt

PowerDNS en Debian 12 Read More »

Porcentaje de uso cpu y ram

#!/bin/bash
totalram=$(free | grep Mem | awk '{print $2}')
enusoram=$(free | grep Mem | awk '{print $3}')
carga=$(uptime | awk 'NF{print $(NF-1)}' | sed 's/\.//g' | sed 's/\,//g' )
cpus=$(lscpu | grep CPU\(s\)| head -n1 | awk '{print $2}')
let ram=$enusoram*100/$totalram
let cpu=$(($carga))/$(($cpus))
echo $(hostname) cpu=$cpu %  ram=$ram %

Porcentaje de uso cpu y ram Read More »

Esperar a hilos hijos

#!/bin/bash

echo -----------opcion 1------------------
for i in {1..254} 
 do ping -W 1 -c 1 192.168.0.${i} >/dev/null 2>&1 &
    pids[${i}]=$!
 done > /dev/null 2>&1

echo -n esperando ...
for pid in ${pids[*]}; do
    wait $pid
done

echo ---------opcion 2----------------------

for i in {1..254} 
 do ping -W 1 -c 1 192.168.0.${i} >/dev/null 2>&1 &
 done > /dev/null 2>&1

echo -n esperando ...for job in `jobs -p`; do
   wait $job 
done
echo listo

Esperar a hilos hijos Read More »

Scroll al inicio