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.

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