92 lines
2.5 KiB
Bash
Executable File
92 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# lvpn
|
|
#
|
|
# Copyright (c) 2011-2013 LibreVPN <vpn@hackcoop.com.ar>
|
|
#
|
|
# See AUTHORS for a list of contributors
|
|
#
|
|
# 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/>.
|
|
#
|
|
#
|
|
# Versión autónoma
|
|
# Wrapper para correr los comandos al estilo `git comando parametros`
|
|
# Hay que crearlos en libdir/lvpn-comando
|
|
|
|
# ENV
|
|
# Tomar las variables de entorno (por ejemplo de un archivo de configuración
|
|
# o de la shell) o usar directorios locales
|
|
TINC="${TINC:-"/etc/tinc/lvpn"}"
|
|
NETWORK="$(basename "${TINC}")"
|
|
LVPN="$(readlink -f $0)"
|
|
|
|
LVPN_DIR="${LVPN_DIR:-$(dirname "$LVPN")}"
|
|
LVPN_CONTRIB="${LVPN_CONTRIB:-"${LVPN_DIR}/contrib"}"
|
|
LVPN_LIBDIR="${LVPN_LIBDIR:-${LVPN_DIR}/lib}"
|
|
LVPN_HOSTS="${LVPN_HOSTS:-${LVPN_DIR}/hosts}"
|
|
LVPN_BEADLE="${LVPN_HOSTS:-${LVPN_DIR}/beadle}"
|
|
KEYSIZE=${KEYSIZE:-4096}
|
|
# Flags para
|
|
TINCD_FLAGS="${TINCD_FLAGS:-"--logfile -U nobody"}"
|
|
PORT=${PORT:-655}
|
|
|
|
# Subnets
|
|
LVPN_SUBNET="${LVPN_SUBNET:-"192.168.9.0/24"}"
|
|
LVPN_SUBNET6="${LVPN_SUBNET6:-"2001:1291:200:83ab::/64"}"
|
|
|
|
# Para gettext
|
|
TEXTDOMAINDIR=${TEXTDOMAINDIR:-"/usr/share/locale"}
|
|
TEXTDOMAIN="$(basename "${LVPN}")"
|
|
|
|
export TINC NETWORK LVPN \
|
|
LVPN_DIR LVPN_CONTRIB LVPN_LIBDIR LVPN_HOSTS \
|
|
KEYSIZE TEXTDOMAINDIR TEXTDOMAIN \
|
|
LVPN_SUBNET LVPN_SUBNET6 TINCD_FLAGS PORT
|
|
|
|
export PATH="${LVPN_DIR}/bin:$PATH"
|
|
|
|
. "${LVPN_LIBDIR}/common"
|
|
|
|
list_commands() {
|
|
pushd "${LVPN_LIBDIR}" &>/dev/null
|
|
|
|
printf '%s\n' lvpn-* | sed "s/^lvpn-//"
|
|
|
|
popd &>/dev/null
|
|
}
|
|
|
|
while getopts "hc" arg; do
|
|
case $arg in
|
|
h) help lvpn ; exit 0;;
|
|
c) list_commands ; exit 0;;
|
|
esac
|
|
done
|
|
let OPTIND--; shift ${OPTIND}
|
|
|
|
test -z "$1" && help lvpn && exit 0
|
|
|
|
# El comando
|
|
command=$1; shift
|
|
|
|
# Chequear si el comando existe
|
|
if [ ! -x "${LVPN_LIBDIR}/lvpn-${command}" ]; then
|
|
fatal_error "%s no existe, tal vez te gustaría implementarlo :D" ${command}
|
|
fi
|
|
|
|
# Correr el comando
|
|
exec ${LVPN_LIBDIR}/lvpn-${command} "$@"
|
|
|
|
exit $?
|