rap/lib/exec/publish

56 lines
1.6 KiB
Bash
Executable File

#!/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 curl
while getopts "dh" arg; do
case $arg in
h) help ${self} ; exit 0;;
esac
done
let OPTIND--; shift ${OPTIND}
if test -z "${1}" ; then
fatal_error "Se necesita un nombre de nodo"
fi
# Obtener el nombre y archivo del host (tb chequea si existe o no)
nodename="$(get_node_name "${1:-$HOSTNAME}")"
nodefile="$(get_node_file "${1}")"
msg "Mandando archivo de nodo"
url="${KEYSERVER}/${nodename}"
$verbose && msg "Url: %s. Archivo de host %s" "*${url}*" "*${nodefile}*"
respcode=$(curl -sL -o /dev/null -w "%{http_code}" -F "host=@${nodefile}" "${url}")
$verbose && msg "Response code: %s" "*${respcode}*"
if [ "${respcode}" -eq "201" ]; then
msg "Nodo registrado!"
elif [ "${respcode}" -eq "403" ]; then
fatal_error "Archivo denegado"
else
fatal_error "Error en servidor, código ${respcode}"
fi
exit 0