#!/usr/bin/env bash # # lib/exec/add-host # # Copyright (c) 2020- RAP # Copyright (c) 2011-2016 LibreVPN # # 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 # . . "${RAP_LIBDIR}"/common UPDATE=false FORCE=false while getopts "ufhd" arg; do case $arg in u) UPDATE=true; FORCE=true ;; f) FORCE=true ;; h) help ${self} ; exit 0;; esac done let OPTIND--; shift ${OPTIND} node="$(get_node_name "$1")"; shift nodedir="$(get_node_dir ${node})" # Si estamos actualizando, la lista de hosts es la que ya esta cargada ${UPDATE} || hosts=("$@") ${UPDATE} && hosts=($(shopt -s nullglob; echo "${nodedir}"/hosts/* | sed "s,${nodedir}/hosts/,,g")) # Recorrer todos los host que se pasaron for _host in "${hosts[@]}"; do # Generar el archivo y encontrarlo, saltear si no existe _hostfile="$(get_host_file "${_host}")" _hostdest="${nodedir}/hosts/${_host}" if test ! -f "${_hostfile}"; then error "El archivo host de %s no existe, salteando..." ${_host} continue fi # Saltear si no el host existe y no estamos forzando o actualizando if test -f "${_hostdest}"; then ${FORCE} || continue fi msg "Copiando el archivo host de %s" ${_host} # Copiar el contenido del archivo cat "${_hostfile}" > "${nodedir}/hosts/${_host}" done exit $?