1
0

gnunet.init 3.0 KB

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