forked from sudoaza/librevpn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lvpn
executable file
·91 lines (75 loc) · 2.47 KB
/
lvpn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
#
# lvpn
#
# Copyright (c) 2011-2013 LibreVPN <[email protected]>
#
# 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 $?