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.

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