You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.0 KiB

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