Files
rap/skel/run-script
T
2026-04-17 02:23:45 -03:00

44 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
# Ejecuta todos los scripts referidos a este evento que se encuentren
# dentro del directorio scripts/
sanitize () {
tr -cd a-z0-9
}
lowercase () {
tr A-Z a-z
}
CUR="$(readlink -f "$0")"
cd "${CUR%/*}"
# Sanitización de variables comunes
NODE="$(echo "${NODE}" | lowercase | sanitize )"
INTERFACE="$(echo "${INTERFACE}" | lowercase | sanitize)"
NETNAME="$(echo "${NETNAME}" | lowercase | sanitize)"
SUBNET="$(echo "${SUBNET}" | tr -d '\n' | \
grep -E '([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}')"
# tinc.conf(5)
# Exporta todas las variables de entorno para que las puedan tomar los
# subscripts
export NETNAME NAME DEVICE INTERFACE NODE REMOTEADDRESS REMOTEPORT \
SUBNET WEIGHT
# Extrae {host,subnet,etc}
event=${0##*/}; event=${event%-*}
# Extrae {up,down}
state=${0##*/}; state=${state#*-}
# evitar que el script falle cuando no hay ningun script
type shopt >/dev/null && shopt -s nullglob
for _script in scripts/${event}-*; do
# si no hay nullglob va a llegar un archivo con * literal (ej. ash)
test ! -e "${_script}" && continue
"${_script}" ${state} ${event}
done