-
Notifications
You must be signed in to change notification settings - Fork 0
/
lvpn
executable file
·65 lines (51 loc) · 1.64 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
#!/usr/bin/env bash
# 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_BIN="${LVPN_BIN:-${LVPN_DIR}/bin}"
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_LIBDIR LVPN_HOSTS LVPN_BIN \
KEYSIZE TEXTDOMAINDIR TEXTDOMAIN \
LVPN_SUBNET LVPN_SUBNET6 TINCD_FLAGS PORT
. "${LVPN_LIBDIR}/common"
list_commands() {
pushd "${LVPN_LIBDIR}" &>/dev/null
echo lvpn-* | tr " " "\n" | 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 $?