Script de comando status; variables globales nuevas; nueva función de mensage naranja
This commit is contained in:
parent
b394eb8458
commit
cf9e22ea22
115
lib/exec/status
Executable file
115
lib/exec/status
Executable file
@ -0,0 +1,115 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# lib/exec/publish
|
||||||
|
#
|
||||||
|
# Copyright (c) 2020- RAP <contacto@partidopirata.com.ar>
|
||||||
|
# Copyright (c) 2011-2016 LibreVPN <vpn@hackcoop.com.ar>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation; either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General
|
||||||
|
# Public License along with this program. If not, see
|
||||||
|
# <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
. "${RAP_LIBDIR}"/common
|
||||||
|
|
||||||
|
requires systemctl grep ps wc ip
|
||||||
|
|
||||||
|
while getopts "dh" arg; do
|
||||||
|
case $arg in
|
||||||
|
h) help ${self} ; exit 0;;
|
||||||
|
d) set -x;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
let OPTIND--; shift ${OPTIND}
|
||||||
|
|
||||||
|
# Se usa mucho el "|| :" (pipe a la nada) para evitar que se corte
|
||||||
|
# el script cuando devuelven mal los comandos
|
||||||
|
|
||||||
|
# Proceso de tinc
|
||||||
|
tincps="$(ps --no-headers -C tincd,tincd_pip -o pid,cmd || :)"
|
||||||
|
if [ "${tincps}" = "" ]; then
|
||||||
|
notincps=true
|
||||||
|
msg_orange "No se encontró el proceso de tinc"
|
||||||
|
elif [ "$(echo "${tincps}" | wc -l)" -ne 1 ]; then
|
||||||
|
manytincsps=true
|
||||||
|
msg_orange "Se encontró más de un proceso de tinc"
|
||||||
|
else
|
||||||
|
msg "Se encontró el proceso de tinc"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Servicio principal de tinc
|
||||||
|
tincsvstatus="$(systemctl status tinc 2>/dev/null || :)"
|
||||||
|
if [ "${tincsvstatus}" = "" ]; then
|
||||||
|
notincsv=true
|
||||||
|
msg_orange "No se encontró el servicio principal de tinc"
|
||||||
|
else
|
||||||
|
tincsv="$(systemctl show tinc)"
|
||||||
|
echo "${tincsv}" | grep -q UnitFileState=enabled && enabled=si || enabled=no
|
||||||
|
echo "${tincsv}" | grep -q ActiveState=active && active=si || active=no
|
||||||
|
msgtxt="Se encontró el servicio principal de tinc: inicio en arranque=${enabled}, activo ahora=${active}"
|
||||||
|
if [ "${active}" = si ]; then msg "${msgtxt}"
|
||||||
|
else msg_orange "${msgtxt}"; fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Servicio de tinc@rap (si existe el principal)
|
||||||
|
if [ "${notincsv}" != true ]; then
|
||||||
|
tincrapsvstatus="$(systemctl status tinc@rap || :)"
|
||||||
|
if [ "${tincrapsvstatus}" = "" ]; then
|
||||||
|
msg_orange "No se encontró el servicio de tinc@rap"
|
||||||
|
else
|
||||||
|
tincsv="$(systemctl show tinc@rap)"
|
||||||
|
echo "${tincsv}" | grep -q UnitFileState=enabled && enabled=si || enabled=no
|
||||||
|
echo "${tincsv}" | grep -q ActiveState=active && active=si || active=no
|
||||||
|
msgtxt="Se encontró el servicio de tinc@rap: inicio en arranque=${enabled}, activo ahora=${active}"
|
||||||
|
if [ "${active}" = si ]; then msg "${msgtxt}"
|
||||||
|
else msg_orange "${msgtxt}"; fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Interface de red
|
||||||
|
iplink="$(ip link show "${NETWORK}" 2>/dev/null || :)"
|
||||||
|
if [ "${iplink}" = "" ]; then
|
||||||
|
msg_orange "No se encontró la interface de red de la rap"
|
||||||
|
else
|
||||||
|
echo "${iplink}" | grep -q 'state UNKNOWN' && interface=true || interface=false
|
||||||
|
if [ "${interface}" != true ]; then
|
||||||
|
msg_orange "Interface de red de la rap encontrada, pero caída"
|
||||||
|
else
|
||||||
|
msg "Interface de red de la rap encontrada y andando"
|
||||||
|
# IPv6 local
|
||||||
|
ipaddress="$(ip address show "${NETWORK}" | grep inet6 | tr -s ' ' | cut -d' ' -f3)"
|
||||||
|
if [ "${ipaddress}" = "" ]; then
|
||||||
|
msg_orange "No se encontró ninguna IP de rap"
|
||||||
|
elif [ "$(echo "${ipaddress}" | wc -l)" -eq 1 ]; then
|
||||||
|
msg_orange "Se encontró una sola IP: ${ipaddress}"
|
||||||
|
else
|
||||||
|
iprap="$(echo "${ipaddress}" | grep "${ULA_PREFIX}" || :)"
|
||||||
|
if [ "${iprap}" = "" ]; then
|
||||||
|
msg_orange "Se encontraron varias IPs de rap, pero ninguna válida"
|
||||||
|
else
|
||||||
|
msg "Tu IP de rap es: ${iprap}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Archivo de hosts
|
||||||
|
hostslines="$(grep "${HOSTS_COMMENT}" /etc/hosts | cut -d' ' -f1,2)"
|
||||||
|
if [ "${hostslines}" = "" ]; then
|
||||||
|
msg_orange "No se encontraron nodos en el archivo de hosts"
|
||||||
|
else
|
||||||
|
msg "Nodos en el archivo de hosts:"
|
||||||
|
echo "${hostslines}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
exit 0
|
5
lib/msg
5
lib/msg
@ -87,6 +87,11 @@ msg() {
|
|||||||
_msg "${DC}$msg" "$@"
|
_msg "${DC}$msg" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
msg_orange() {
|
||||||
|
msg="$(gettext "$1")"; shift
|
||||||
|
_msg "${YELLOW}$msg${ALL_OFF}" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
error() {
|
error() {
|
||||||
msg="$(gettext "$1")"; shift
|
msg="$(gettext "$1")"; shift
|
||||||
_msg "${BOLD}${RED}$(gettext "ERROR:")${ALL_OFF} ${DC}${msg}" "$@"
|
_msg "${BOLD}${RED}$(gettext "ERROR:")${ALL_OFF} ${DC}${msg}" "$@"
|
||||||
|
2
rap
2
rap
@ -24,6 +24,8 @@
|
|||||||
# o de la shell) o usar directorios locales
|
# o de la shell) o usar directorios locales
|
||||||
export RAP="$(readlink -f $0)"
|
export RAP="$(readlink -f $0)"
|
||||||
export NETWORK="${NETWORK:-$(basename "${RAP}")}"
|
export NETWORK="${NETWORK:-$(basename "${RAP}")}"
|
||||||
|
export HOSTS_COMMENT="# Managed by tinc ${NETWORK}"
|
||||||
|
export ULA_PREFIX="fd00:1312:acab::"
|
||||||
export TINC="${TINC:-"/etc/tinc/${NETWORK}"}"
|
export TINC="${TINC:-"/etc/tinc/${NETWORK}"}"
|
||||||
|
|
||||||
export RAP_DIR="${RAP_DIR:-$(dirname "$RAP")}"
|
export RAP_DIR="${RAP_DIR:-$(dirname "$RAP")}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user