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.

124 lines
3.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=80
  3. USE_PROCD=1
  4. PIDFILE=/var/run/privoxy.pid
  5. CFGFILE=/var/etc/privoxy.conf
  6. CFGTEMP=/var/etc/privoxy.conf.tmp
  7. _uci2conf() {
  8. local _LOGDIR="/var/log" # set default
  9. local _LOGFILE="privoxy.log" # set default
  10. # redefined callback for options when calling config_load
  11. option_cb()
  12. {
  13. # $1 name of variable
  14. # $2 value
  15. local __OPT="$1"
  16. local __VAL="$2"
  17. case $__OPT in
  18. logdir) # logdir handled later
  19. _LOGDIR="$__VAL" ;;
  20. logfile) # logfile handled later
  21. _LOGFILE="$__VAL" ;;
  22. *)
  23. # detect list options (LENGTH) and ignore
  24. echo $__OPT | grep -i "_LENGTH" >/dev/null 2>&1 && return
  25. # detect list options (ITEM) and ignore
  26. echo $__OPT | grep -i "_ITEM" >/dev/null 2>&1 && __OPT=$(echo $__OPT | sed -e "s#_ITEM.##g")
  27. # filter debug_*
  28. echo $__OPT | grep -i "debug_" >/dev/null 2>&1 && {
  29. [ $__VAL -eq 0 ] && return # not set ignore
  30. __VAL=$(echo $__OPT | sed -e "s#debug_##g")
  31. __OPT="debug"
  32. }
  33. # uci only accept "_" but we need "-"
  34. local __OPT=$(echo $__OPT | sed -e "s#_#-#g")
  35. # write to config
  36. echo -e "$__OPT\t$__VAL" >> $CFGTEMP
  37. ;;
  38. esac
  39. }
  40. mkdir -m0755 -p /var/etc
  41. echo "" > $CFGTEMP # create tmp config file
  42. chmod 644 $CFGTEMP # garantee that privoxy can read
  43. chgrp privoxy $CFGTEMP
  44. echo '### AUTO-GENERATED CONFIGURATION' >> $CFGTEMP
  45. echo '### USED BY PRIVOXY' >> $CFGTEMP
  46. echo '### DO NOT EDIT' >> $CFGTEMP
  47. echo '### SEE /etc/config/privoxy INSTEAD' >> $CFGTEMP
  48. echo '' >> $CFGTEMP
  49. config_load privoxy # calling above option_cb()
  50. # write logdir/logfile to config
  51. echo -e "logdir\t$_LOGDIR" >> $CFGTEMP
  52. echo -e "logfile\t$_LOGFILE" >> $CFGTEMP
  53. # create logfile and set permissions
  54. touch $_LOGDIR/$_LOGFILE
  55. chmod 664 $_LOGDIR/$_LOGFILE
  56. chown privoxy:privoxy $_LOGDIR/$_LOGFILE
  57. # move temp to final privoxy readable configuration
  58. mv -f $CFGTEMP $CFGFILE
  59. }
  60. # privoxy should auto-reload it's configuration
  61. # but it only reload on next connect to one of the listen_address
  62. # if we create a new listen_address privoxy never reload
  63. reload_service() {
  64. # so we restart here because rc.common reload_service only start without stopping
  65. restart "$@"
  66. # the following should normally work but see above
  67. # _uci2conf # convert uci config
  68. }
  69. service_triggers() {
  70. procd_add_reload_trigger "privoxy"
  71. }
  72. start_service() {
  73. # redefined callback for sections when calling config_load
  74. config_cb() {
  75. # $1 type of config section
  76. # $2 name of section
  77. [ "$1" = "interface" ] && \
  78. procd_add_interface_trigger interface.* $2 /etc/init.d/privoxy restart
  79. }
  80. _uci2conf # convert uci config
  81. procd_open_instance
  82. procd_set_param command /usr/sbin/privoxy
  83. procd_append_param command --no-daemon # for procd run in foreground
  84. procd_append_param command --pidfile $PIDFILE # set pid file
  85. procd_append_param command --user privoxy.privoxy # set user
  86. procd_append_param command $CFGFILE # config file
  87. procd_set_param file $CFGFILE # set configration file
  88. procd_open_trigger # we need a restart on interface events not a reload
  89. config_load network # load network configuration and set trigger(s) in config_cb() above
  90. procd_close_trigger
  91. procd_close_instance
  92. }
  93. service_running() {
  94. logger_trick() {
  95. sleep 1 # give privoxy time to completely come up
  96. logger -p daemon.notice -t "privoxy[$(cat $PIDFILE)]" "Service started successfully"
  97. }
  98. logger_trick &
  99. }
  100. stop_service() {
  101. logger -p daemon.notice -t "privoxy[$(cat $PIDFILE)]" "Service shutdown"
  102. }