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

103 lines
2.3 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' \
2020-12-03 10:23:34 +00:00
'mode:string' \
2018-01-19 13:22:01 +00:00
'key:string' \
'host:host' \
'port:port' \
'dev:string' \
2020-12-03 10:23:34 +00:00
'timeout:uinteger:10000' \
2018-02-07 17:04:27 +00:00
'chacha20:bool:0' \
2018-01-19 13:22:01 +00:00
'proto:string'
}
start_instance() {
2020-12-03 10:23:34 +00:00
local enable key host port dev mptcp proto chacha20 mode multiqueue timeout
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
2020-04-22 17:11:03 +00:00
[ -n "${host}" ] || return 1
2018-01-19 13:22:01 +00:00
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.device=${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
2020-12-03 10:23:34 +00:00
[ "${mode}" = "listener" ] && procd_append_param command listener
2018-02-07 19:00:50 +00:00
[ "${mptcp}" = "1" ] && procd_append_param command mptcp
[ "${chacha20}" = "1" ] && procd_append_param command chacha20
2020-05-05 07:54:20 +00:00
[ "${multiqueue}" = "1" ] && procd_append_param command multiqueue
2018-02-07 19:00:50 +00:00
2018-02-08 09:52:25 +00:00
procd_append_param command \
2020-04-07 15:42:06 +00:00
retry count -1 const 500000 \
2020-12-03 10:23:34 +00:00
timeout ${timeout} \
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
}