1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-12 18:41:51 +00:00
openmptcprouter-feeds/glorytun/init

100 lines
2.1 KiB
Text
Raw Normal View History

2018-01-19 13:22:01 +00:00
#!/bin/sh /etc/rc.common
# vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 :
# Copyright (C) 2015 ovh.com
# Copyright (C) 2017 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
START=90
STOP=10
USE_PROCD=1
PROG_NAME=glorytun
PROG=/usr/sbin/${PROG_NAME}
_log() {
logger -p daemon.info -t ${PROG_NAME} "$@"
}
_err() {
logger -p daemon.err -t ${PROG_NAME} "$@"
}
validate_section() {
uci_validate_section glorytun glorytun "${1}" \
'enable:bool:0' \
'mptcp:bool:0' \
'listener:bool:0' \
'key:string' \
'host:host' \
'port:port' \
'dev:string' \
2018-02-07 17:04:27 +00:00
'chacha20:bool:0' \
2018-01-19 13:22:01 +00:00
'proto:string'
}
start_instance() {
2018-02-07 17:04:27 +00:00
local enable key host port dev listener mptcp proto chacha20
2018-01-19 13:22:01 +00:00
validate_section "${1}" || {
_err "validation failed"
return 1
}
[ "${enable}" = "1" ] || return 1
2018-02-07 14:20:38 +00:00
[ "${proto}" = "tcp" ] || return 1
2018-09-13 18:32:07 +00:00
[ -n "${key}" ] || {
_err "Key empty"
return 1
}
2018-06-06 15:52:22 +00:00
[ "${key}" != "secretkey" ] || return 1
2018-01-19 13:22:01 +00:00
[ -n "${port}" ] || return 1
[ -n "${dev}" ] || return 1
echo "${key}" > /tmp/${PROG_NAME}-${1}.key
2018-09-13 18:32:07 +00:00
[ -f "/tmp/${PROG_NAME}-${1}.key" ] || {
_err "can't create key file"
return 1
}
2018-01-19 13:22:01 +00:00
key=""
2018-06-06 15:52:22 +00:00
if [ "$(uci -q get network.omrvpn)" != "" ]; then
uci -q set network.omrvpn.ifname=${dev}
uci -q commit network
2018-06-06 15:52:22 +00:00
fi
2018-01-19 13:22:01 +00:00
_log "starting ${PROG_NAME} ${1} instance $*"
procd_open_instance
procd_set_param command ${PROG} \
keyfile /tmp/${PROG_NAME}-${1}.key \
${port:+port "$port"} \
${host:+host "$host"} \
2018-02-08 09:52:25 +00:00
${dev:+dev "$dev"}
2018-02-07 19:00:50 +00:00
[ "${listener}" = "1" ] && procd_append_param command listener
[ "${mptcp}" = "1" ] && procd_append_param command mptcp
[ "${chacha20}" = "1" ] && procd_append_param command chacha20
2018-02-08 09:52:25 +00:00
procd_append_param command \
retry count -1 const 5000000 \
2020-03-04 14:58:06 +00:00
timeout 100000 \
2019-06-14 18:42:41 +00:00
keepalive count 5 idle 20 interval 2 \
buffer-size 32768
2018-01-19 13:22:01 +00:00
procd_set_param respawn 0 30 0
procd_set_param file /tmp/${PROG_NAME}-${1}.key
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
start_service() {
config_load glorytun
config_foreach start_instance glorytun
}
service_triggers() {
procd_add_reload_trigger glorytun network
}