gnunet.initd 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2016 Gentoo Authors
  3. # Copyright 2016 - 2019 ng0, lynX
  4. # Distributed under the terms of the GNU General Public License v2
  5. # SPDX-License-Identifier: GPL2.0
  6. if [ -d /run ] ; then
  7. PIDFILE=${PIDFILE:-/run/gnunet/arm-service.pid}
  8. else
  9. PIDFILE=${PIDFILE:-/var/run/gnunet/arm-service.pid}
  10. fi
  11. depend() {
  12. # FIXME: refine?
  13. need net
  14. }
  15. GNUNET_PATH="/usr"
  16. GNUNET_HOME="/var/lib/gnunet"
  17. SUID_ROOT_HELPERS="exit nat-server nat-client transport-bluetooth transport-wlan vpn"
  18. chmodown_execbin() {
  19. if [ -x $1 ]; then
  20. if [ "$3" ]; then
  21. chown $3 $1 2>/dev/null && chmod $2 $1
  22. else
  23. chmod $2 $1
  24. fi
  25. fi
  26. }
  27. checkconfig() {
  28. if [ -n "$(find ${GNUNET_HOME}/.local/share/gnunet -maxdepth 1 -name gnunet.conf -perm +0044)" ] ; then
  29. eerror "${conf} must not be world or group readable. Try:"
  30. eerror " chmod 600 ${conf}"
  31. eerror " chown gnunet:gnunet ${conf}"
  32. return 1
  33. fi
  34. mkdir -p ${GNUNET_HOME}/.cache/gnunet
  35. # taken from dangole's lede config.. thx!
  36. local libexec="${GNUNET_PATH}/lib/gnunet/libexec" # why not /usr/libexec/gnunet ?
  37. # not reliable enough:
  38. #[ -e ${libexec}/.permfix ] && return
  39. for helper in $SUID_ROOT_HELPERS; do
  40. chmodown_execbin ${libexec}/gnunet-helper-$helper u+s
  41. done
  42. chmodown_execbin ${libexec}/gnunet-helper-dns 4750 root:gnunetdns
  43. chmodown_execbin ${libexec}/gnunet-service-dns 2750 gnunet:gnunetdns
  44. #touch ${libexec}/.permfix
  45. }
  46. start() {
  47. checkconfig || return 1
  48. local piddir=$(dirname ${PIDFILE})
  49. if [ ! -d ${piddir} ] ; then
  50. ebegin "Making ${piddir}"
  51. mkdir -p ${piddir}
  52. eend $?
  53. ebegin "Changing permissions of ${piddir}"
  54. chown gnunet:gnunet ${piddir}
  55. eend $?
  56. fi
  57. ebegin "Starting ${SVCNAME}"
  58. # shouldn't be necessary... but
  59. start-stop-daemon --start --user gnunet --name gnunet --pidfile ${PIDFILE} \
  60. --exec ${GNUNET_PATH}/lib/gnunet/libexec/gnunet-service-arm -- -d
  61. # flags to be passed to the process appear after the double-dash
  62. eend $?
  63. }
  64. stop() {
  65. ebegin "Stopping ${SVCNAME}"
  66. start-stop-daemon --stop --signal QUIT --pidfile ${PIDFILE}
  67. sleep 1
  68. killall -u gnunet
  69. sleep 1
  70. rm -rf /tmp/gnunet-gnunet-runtime >/dev/null 2>&1
  71. rm -rf /tmp/gnunet-system-runtime >/dev/null 2>&1
  72. eend $?
  73. }