#!/bin/sh # Ejecuta todos los scripts referidos a este evento que se encuentren # dentro del directorio scripts/ sanitize () { tr -cd "[:alnum:]" } lowercase () { tr "[:upper:]" "[:lower:]" } CUR="$(readlink -f "$0")" cd "${CUR%/*}" # Sanitización de variables comunes NODE="$(echo "${NODE}" | sanitize | lowercase)" INTERFACE="$(echo "${INTERFACE}" | sanitize | lowercase)" NETNAME="$(echo "${NETNAME}" | sanitize | lowercase)" 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