gnunet.init (3110B)
1 #!/bin/sh /etc/rc.common 2 # Copyright (C) 2015 OpenWrt.org 3 4 START=90 5 6 USE_PROCD=1 7 PROG=/usr/lib/gnunet/libexec/gnunet-service-arm 8 9 GNUNET_HOME=/var/run/gnunet 10 # LOGFILE=$GNUNET_HOME/gnunet.log 11 CONFIGFILE=$GNUNET_HOME/gnunet.conf 12 SUID_ROOT_HELPERS="exit nat-server nat-client transport-bluetooth transport-wlan vpn" 13 14 chmodown_execbin() { 15 execname=/usr/lib/gnunet/libexec/gnunet-$1 16 if [ -x $execname ]; then 17 if [ "$3" ]; then 18 chown $3 $execname 2>/dev/null && chmod $2 $execname 19 else 20 chmod $2 $execname 21 fi 22 fi 23 } 24 25 fix_libexec_permissions() { 26 [ -e /usr/share/gnunet/.permfix ] && return 27 for helper in $SUID_ROOT_HELPERS; do 28 chmodown_execbin helper-$helper u+s 29 done 30 chmodown_execbin helper-dns 4750 root:gnunetdns 31 chmodown_execbin service-dns 2750 gnunet:gnunetdns 32 33 touch /usr/share/gnunet/.permfix 34 } 35 36 prepare_config() { 37 if [ ! -e "$GNUNET_HOME" ]; then 38 mkdir -p $GNUNET_HOME 39 chown gnunet:gnunet $GNUNET_HOME 40 chmod 0750 $GNUNET_HOME 41 fi 42 touch $CONFIGFILE 43 chown gnunet:gnunet $CONFIGFILE 44 chmod 0640 $CONFIGFILE 45 gnunet-config -c $CONFIGFILE -w -s PATHS -o GNUNET_HOME -V $GNUNET_HOME 46 47 # minimal persistency in /etc/gnunet 48 [ ! -d /etc/gnunet ] && { 49 mkdir -p /etc/gnunet 50 chown gnunet:gnunet /etc/gnunet 51 } 52 53 # defaults paths for persistent files 54 gnunet-config -c $CONFIGFILE -w -s PATHS -o GNUNET_CONFIG_HOME -V /etc/gnunet 55 gnunet-config -c $CONFIGFILE -w -s PEER -o PRIVATE_KEY -V /etc/gnunet/private_key.ecc 56 gnunet-config -c $CONFIGFILE -w -s identity -o EGODIR -V /etc/gnunet/identity/egos 57 gnunet-config -c $CONFIGFILE -w -s revocation -o DATABASE -V /etc/gnunet/revocation.dat 58 gnunet-config -c $CONFIGFILE -w -s nse -o PROOFFILE -V /etc/gnunet/proof.dat 59 60 # enable all installed transport plugins 61 transport_plugins=$(gnunet-config -c $CONFIGFILE -s transport -o PLUGINS) 62 for transplug in /usr/lib/gnunet/libgnunet_plugin_transport_*.so; do 63 transplug=$( echo $transplug | 64 sed -ne 's!^.*_transport_\(.*\)\.so$!\1!p' ) 65 [ -n "$( echo $transport_plugins | grep $transplug )" ] || 66 transport_plugins="$transport_plugins $transplug" 67 done 68 gnunet-config -c $CONFIGFILE -w -s transport -o PLUGINS -V "$transport_plugins" 69 70 # do not touch sysctl, iptables and routing 71 gnunet-config -c $CONFIGFILE -w -s dns -o SKIP_ROUTING_SETUP -V YES 72 gnunet-config -c $CONFIGFILE -w -s exit -o EXIT_IFNAME -V '' 73 74 # apply config from UCI 75 _gnunet_section="" 76 config_cb() 77 { 78 # $1 "Type" 79 # $2 "Name" 80 local __TYPE="$1" 81 local __NAME="${2/_/-}" 82 [ "${__TYPE}" = "gnunet-config" ] && _gnunet_section="${__NAME}" 83 [ "${__TYPE}" = "gnunet-exit-service" ] && _gnunet_section="${__NAME}.gnunet." 84 } 85 option_cb() { 86 # $1 name of variable 87 # $2 value 88 local __OPT="$1" 89 local __VAL="$2" 90 gnunet-config -c $CONFIGFILE -w -s ${_gnunet_section} -o ${__OPT} -V "${__VAL}" 91 } 92 config_load gnunet 93 94 return 0 95 } 96 97 start_service() { 98 fix_libexec_permissions 99 prepare_config 100 101 procd_open_instance 102 procd_set_param user gnunet 103 procd_set_param command $PROG -c $CONFIGFILE 104 [ "$LOGFILE" ] && procd_append_param command -l $LOGFILE 105 procd_set_param respawn 106 procd_close_instance 107 }