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.

108 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. 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. if [ ! -e "$GNUNET_HOME" ]; then
  32. mkdir -p $GNUNET_HOME
  33. chown gnunet:gnunet $GNUNET_HOME
  34. chmod 0750 $GNUNET_HOME
  35. fi
  36. touch $CONFIGFILE
  37. chown gnunet:gnunet $CONFIGFILE
  38. chmod 0640 $CONFIGFILE
  39. gnunet-config -c $CONFIGFILE -w -s PATHS -o GNUNET_HOME -V $GNUNET_HOME
  40. # minimal persistency in /etc/gnunet
  41. [ ! -d /etc/gnunet ] && {
  42. mkdir -p /etc/gnunet
  43. chown gnunet:gnunet /etc/gnunet
  44. }
  45. # defaults paths for persistent files
  46. gnunet-config -c $CONFIGFILE -w -s PATHS -o GNUNET_CONFIG_HOME -V /etc/gnunet
  47. gnunet-config -c $CONFIGFILE -w -s PEER -o PRIVATE_KEY -V /etc/gnunet/private_key.ecc
  48. gnunet-config -c $CONFIGFILE -w -s identity -o EGODIR -V /etc/gnunet/identity/egos
  49. gnunet-config -c $CONFIGFILE -w -s revocation -o DATABASE -V /etc/gnunet/revocation.dat
  50. gnunet-config -c $CONFIGFILE -w -s nse -o PROOFFILE -V /etc/gnunet/proof.dat
  51. # enable all installed transport plugins
  52. transport_plugins=$(gnunet-config -c $CONFIGFILE -s transport -o PLUGINS)
  53. for transplug in /usr/lib/gnunet/libgnunet_plugin_transport_*.so; do
  54. transplug=$( echo $transplug |
  55. sed -ne 's!^.*_transport_\(.*\)\.so$!\1!p' )
  56. [ -n "$( echo $transport_plugins | grep $transplug )" ] ||
  57. transport_plugins="$transport_plugins $transplug"
  58. done
  59. gnunet-config -c $CONFIGFILE -w -s transport -o PLUGINS -V "$transport_plugins"
  60. # do not touch sysctl, iptables and routing
  61. gnunet-config -c $CONFIGFILE -w -s dns -o SKIP_ROUTING_SETUP -V YES
  62. gnunet-config -c $CONFIGFILE -w -s exit -o EXIT_IFNAME -V ''
  63. # apply config from UCI
  64. _gnunet_section=""
  65. config_cb()
  66. {
  67. # $1 "Type"
  68. # $2 "Name"
  69. local __TYPE="$1"
  70. local __NAME="${2/_/-}"
  71. [ "${__TYPE}" = "gnunet-config" ] && _gnunet_section="${__NAME}"
  72. [ "${__TYPE}" = "gnunet-exit-service" ] && _gnunet_section="${__NAME}.gnunet."
  73. }
  74. option_cb() {
  75. # $1 name of variable
  76. # $2 value
  77. local __OPT="$1"
  78. local __VAL="$2"
  79. gnunet-config -c $CONFIGFILE -w -s ${_gnunet_section} -o ${__OPT} -V "${__VAL}"
  80. }
  81. config_load gnunet
  82. return 0
  83. }
  84. start_service() {
  85. fix_libexec_permissions
  86. prepare_config
  87. procd_open_instance
  88. procd_set_param user gnunet
  89. procd_set_param command $PROG -c $CONFIGFILE
  90. [ "$LOGFILE" ] && procd_append_param command -l $LOGFILE
  91. procd_set_param respawn
  92. procd_close_instance
  93. }