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.

106 lines
3.0 KiB

  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. extra_command "restart_transport" "Restart transport"
  10. prepare_config() {
  11. local had_exit_service=0;
  12. if [ ! -e "$GNUNET_HOME" ]; then
  13. mkdir -p $GNUNET_HOME
  14. chown gnunet:gnunet $GNUNET_HOME
  15. chmod 0750 $GNUNET_HOME
  16. fi
  17. touch $CONFIGFILE
  18. chown gnunet:gnunet $CONFIGFILE
  19. chmod 0640 $CONFIGFILE
  20. gnunet-config -c $CONFIGFILE -w -s PATHS -o GNUNET_HOME -V $GNUNET_HOME
  21. # minimal persistency in /etc/gnunet
  22. [ ! -d /etc/gnunet ] && {
  23. mkdir -p /etc/gnunet
  24. chown gnunet:gnunet /etc/gnunet
  25. }
  26. # defaults paths for persistent files
  27. gnunet-config -c $CONFIGFILE -w -s PATHS -o GNUNET_CONFIG_HOME -V /etc/gnunet
  28. gnunet-config -c $CONFIGFILE -w -s PEER -o PRIVATE_KEY -V /etc/gnunet/private_key.ecc
  29. gnunet-config -c $CONFIGFILE -w -s identity -o EGODIR -V /etc/gnunet/identity/egos
  30. gnunet-config -c $CONFIGFILE -w -s revocation -o DATABASE -V /etc/gnunet/revocation.dat
  31. gnunet-config -c $CONFIGFILE -w -s nse -o PROOFFILE -V /etc/gnunet/proof.dat
  32. # enable all installed transport plugins
  33. transport_plugins=$(gnunet-config -c $CONFIGFILE -s transport -o PLUGINS)
  34. for transplug in /usr/lib/gnunet/libgnunet_plugin_transport_*.so; do
  35. transplug=$( echo $transplug |
  36. sed -ne 's!^.*_transport_\(.*\)\.so$!\1!p' )
  37. [ -n "$( echo $transport_plugins | grep $transplug )" ] ||
  38. transport_plugins="$transport_plugins $transplug"
  39. done
  40. gnunet-config -c $CONFIGFILE -w -s transport -o PLUGINS -V "$transport_plugins"
  41. # do not touch sysctl, iptables and routing
  42. gnunet-config -c $CONFIGFILE -w -s dns -o SKIP_ROUTING_SETUP -V YES
  43. gnunet-config -c $CONFIGFILE -w -s exit -o EXIT_IFNAME -V ''
  44. # apply config from UCI
  45. _gnunet_section=""
  46. config_cb()
  47. {
  48. # $1 "Type"
  49. # $2 "Name"
  50. local __TYPE="$1"
  51. local __NAME="${2/_/-}"
  52. [ "${__TYPE}" = "gnunet-config" ] && _gnunet_section="${__NAME}"
  53. [ "${__TYPE}" = "gnunet-exit-service" ] && {
  54. had_exit_service=1
  55. _gnunet_section="${__NAME}.gnunet."
  56. }
  57. }
  58. option_cb() {
  59. # $1 name of variable
  60. # $2 value
  61. local __OPT="$1"
  62. local __VAL="$2"
  63. gnunet-config -c $CONFIGFILE -w -s ${_gnunet_section} -o ${__OPT} -V "${__VAL}"
  64. }
  65. config_load gnunet
  66. [ "$had_exit_service" -eq 1 ] && gnunet-config -c $CONFIGFILE -w -s exit -o FORCESTART -V YES
  67. return 0
  68. }
  69. restart_transport() {
  70. gnunet-arm -c $CONFIGFILE -k transport
  71. gnunet-arm -c $CONFIGFILE -i transport
  72. }
  73. start_service() {
  74. prepare_config
  75. procd_open_instance
  76. procd_set_param user gnunet
  77. # procd_set_param env GNUNET_LOG="dht;;;;info"
  78. procd_set_param stderr 1
  79. procd_set_param command $PROG -c $CONFIGFILE
  80. [ "$LOGFILE" ] && procd_append_param command -l $LOGFILE
  81. procd_set_param respawn
  82. procd_close_instance
  83. }
  84. service_triggers()
  85. {
  86. procd_add_reload_trigger "gnunet"
  87. procd_add_raw_trigger "interface.*.up" 3000 /etc/init.d/gnunet restart_transport
  88. }