aboutsummaryrefslogtreecommitdiff
path: root/net/gnunet/files/gnunet.init
blob: 90971d8eb6f231fe236978e0ce53f5a496df3beb (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/sh /etc/rc.common
# Copyright (C) 2015 OpenWrt.org

START=90

USE_PROCD=1
PROG=/usr/lib/gnunet/libexec/gnunet-service-arm

GNUNET_HOME=/var/run/gnunet
# LOGFILE=$GNUNET_HOME/gnunet.log
CONFIGFILE=$GNUNET_HOME/gnunet.conf
EXTRA_COMMANDS="restart_transport"

prepare_config() {
	local had_exit_service=0;

	if [ ! -e "$GNUNET_HOME" ]; then
		mkdir -p $GNUNET_HOME
		chown gnunet:gnunet $GNUNET_HOME
		chmod 0750 $GNUNET_HOME
	fi
	touch $CONFIGFILE
	chown gnunet:gnunet $CONFIGFILE
	chmod 0640 $CONFIGFILE
	gnunet-config -c $CONFIGFILE -w -s PATHS -o GNUNET_HOME -V $GNUNET_HOME

	# minimal persistency in /etc/gnunet
	[ ! -d /etc/gnunet ] && {
		mkdir -p /etc/gnunet
		chown gnunet:gnunet /etc/gnunet
	}

	# defaults paths for persistent files
	gnunet-config -c $CONFIGFILE -w -s PATHS -o GNUNET_CONFIG_HOME -V /etc/gnunet
	gnunet-config -c $CONFIGFILE -w -s PEER -o PRIVATE_KEY -V /etc/gnunet/private_key.ecc
	gnunet-config -c $CONFIGFILE -w -s identity -o EGODIR -V /etc/gnunet/identity/egos
	gnunet-config -c $CONFIGFILE -w -s revocation -o DATABASE -V /etc/gnunet/revocation.dat
	gnunet-config -c $CONFIGFILE -w -s nse -o PROOFFILE -V /etc/gnunet/proof.dat

	# enable all installed transport plugins
	transport_plugins=$(gnunet-config -c $CONFIGFILE -s transport -o PLUGINS)
	for transplug in /usr/lib/gnunet/libgnunet_plugin_transport_*.so; do
		transplug=$( echo $transplug |
			sed -ne 's!^.*_transport_\(.*\)\.so$!\1!p' )
		[ -n "$( echo $transport_plugins | grep $transplug )" ] ||
			transport_plugins="$transport_plugins $transplug"
	done
	gnunet-config -c $CONFIGFILE -w -s transport -o PLUGINS -V "$transport_plugins"

	# do not touch sysctl, iptables and routing
	gnunet-config -c $CONFIGFILE -w -s dns -o SKIP_ROUTING_SETUP -V YES
	gnunet-config -c $CONFIGFILE -w -s exit -o EXIT_IFNAME -V ''

	# apply config from UCI
	_gnunet_section=""
	config_cb()
	{
		# $1    "Type"
		# $2    "Name"
		local __TYPE="$1"
		local __NAME="${2/_/-}"
		[ "${__TYPE}" = "gnunet-config" ] && _gnunet_section="${__NAME}"
		[ "${__TYPE}" = "gnunet-exit-service" ] && {
			had_exit_service=1
			_gnunet_section="${__NAME}.gnunet."
		}
	}
	option_cb() {
		# $1    name of variable
		# $2    value
		local __OPT="$1"
		local __VAL="$2"
		gnunet-config -c $CONFIGFILE -w -s ${_gnunet_section} -o ${__OPT} -V "${__VAL}"
	}

	config_load gnunet

	[ "$had_exit_service" -eq 1 ] && gnunet-config -c $CONFIGFILE -w -s exit -o FORCESTART -V YES

	return 0
}

restart_transport() {
	gnunet-arm -c $CONFIGFILE -k transport
	gnunet-arm -c $CONFIGFILE -i transport
}

start_service() {
	prepare_config

	procd_open_instance
	procd_set_param user gnunet
#	procd_set_param env GNUNET_LOG="dht;;;;info"
	procd_set_param stderr 1
	procd_set_param command $PROG -c $CONFIGFILE
	[ "$LOGFILE" ] && procd_append_param command -l $LOGFILE
	procd_set_param respawn
	procd_close_instance
}

service_triggers()
{
	procd_add_reload_trigger "gnunet"
	procd_add_raw_trigger "interface.*.up" 3000 /etc/init.d/gnunet restart_transport
}