mirror of
				https://github.com/Ysurac/openmptcprouter-feeds.git
				synced 2025-03-09 15:40:03 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			87 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			87 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
#!/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-udp
 | 
						|
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'      \
 | 
						|
		'key:string'         \
 | 
						|
		'host:host'          \
 | 
						|
		'port:port'          \
 | 
						|
		'proto:string'       \
 | 
						|
		'bind:string'        \
 | 
						|
		'bindport:port'      \
 | 
						|
		'mtu:uinteger:1500'  \
 | 
						|
		'mtuauto:bool:0'     \
 | 
						|
		'chacha20:bool:0'    \
 | 
						|
		'dev:string'
 | 
						|
}
 | 
						|
 | 
						|
start_instance() {
 | 
						|
	local enable key host port dev listener proto bind bindport mtu mtuauto chacha20
 | 
						|
 | 
						|
	validate_section "${1}" || {
 | 
						|
		_err "validation failed"
 | 
						|
		return 1
 | 
						|
	}
 | 
						|
 | 
						|
	[ "${enable}" = "1" ] || return 1
 | 
						|
	[ "${proto}" = "udp" ] || return 1
 | 
						|
 | 
						|
	[ -n "${key}" ] || return 1
 | 
						|
	[ -n "${port}" ] || return 1
 | 
						|
	[ -n "${dev}" ] || return 1
 | 
						|
 | 
						|
	echo "${key}" > /tmp/${PROG_NAME}-${1}.key
 | 
						|
	key=""
 | 
						|
 | 
						|
	_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"} \
 | 
						|
		${dev:+dev "$dev"} \
 | 
						|
		${mtu:+mtu "$mtu"} \
 | 
						|
		${bind:+bind "$bind"} \
 | 
						|
		${bindport:+bind-port "$port"} \
 | 
						|
		v4only
 | 
						|
 | 
						|
	[ "${mtuauto}" = "1" ] && procd_append_param command mtu-auto
 | 
						|
	[ "${chacha20}" = "1" ] && procd_append_param command chacha20
 | 
						|
 | 
						|
	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
 | 
						|
}
 |