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