78 lines
2.1 KiB
Bash
Executable File
78 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# lib/exec/install-script
|
|
#
|
|
# 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/>.
|
|
#
|
|
#
|
|
# Instala un script
|
|
# $0 script
|
|
# $1 nodo
|
|
# $2 evento
|
|
# $3 script
|
|
|
|
. "${RAP_LIBDIR}"/common
|
|
|
|
# Mostrar los eventos disponibles
|
|
list_events() {
|
|
for _e in tinc host subnet; do
|
|
msg "${_e}"
|
|
done
|
|
}
|
|
|
|
# Mostrar los scripts disponibles
|
|
list_scripts() {
|
|
ls ${RAP_SKELDIR}/scripts
|
|
}
|
|
|
|
VERBOSE=""
|
|
while getopts "dvhes" arg; do
|
|
case $arg in
|
|
h) help ${self} ; exit 0;;
|
|
v) VERBOSE=" -v " ;;
|
|
e) list_events ; exit 0 ;;
|
|
s) list_scripts ; exit 0 ;;
|
|
esac
|
|
done
|
|
let OPTIND--; shift ${OPTIND}
|
|
|
|
# Mostrar la ayuda si no hay argumentos
|
|
test -z "$1" && help ${self} && exit 0
|
|
|
|
node="$(get_node_name "${1}")" ; shift
|
|
node_dir="$(get_node_dir "$node")"
|
|
event="$(get_event "$1")" ; shift
|
|
script="$(get_script "$1")"
|
|
|
|
test -z "${script}" && fatal_error "El script %s no existe" "${script##*/}"
|
|
test -z "${node}" && fatal_error "El nodo %s no existe" "${node}"
|
|
test -z "${event}" && fatal_error "El evento %s no es válido" "${event}"
|
|
|
|
# Instalar run-script para este evento
|
|
for _state in up down; do
|
|
# No pisar los tinc-{up,down} con run-script
|
|
if test "${event}" != "tinc" ; then
|
|
# Y vincularla al evento-estado, de esta forma tenemos una sola copia
|
|
# siempre actualizada.
|
|
ln --force --symbolic run-script "${node_dir}/${event}-${_state}"
|
|
fi
|
|
done
|
|
|
|
# Instalar el script para el evento
|
|
ln --symbolic "${script}" "${node_dir}/scripts/${event}-${script##*/}"
|