Advertisement
Guest User

Untitled

a guest
Aug 10th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # $FreeBSD: branches/2017Q2/security/tor/files/tor.in 425595 2016-11-07 06:24:37Z jbeich $
  4. #
  5. # PROVIDE: tor
  6. # REQUIRE: DAEMON FILESYSTEMS
  7. # BEFORE: LOGIN
  8. #
  9. # Add the following lines to /etc/rc.conf to enable tor.
  10. # All these options will overide any settings in your local torrc as
  11. # they are command line options.
  12. #
  13. # tor_enable (bool): Set it to "YES" to enable tor. Default: NO
  14. # tor_instances (str): List of instances. Default: ""
  15. # tor_conf (str): Points to your torrc file.
  16. # Default: /usr/local/etc/tor/torrc
  17. # tor_user (str): Tor daemon user. Default: _tor
  18. # tor_group (str): Tor group. Default: _tor
  19. # tor_pidfile (str): Tor pid file. Default: /var/run/tor/tor.pid
  20. # tor_datadir (str): Tor datadir. Default: /var/db/tor
  21. # tor_disable_default_instance (str): Doesn't run the default instance.
  22. # Only valid when tor_instances is used.
  23. # Default: NO
  24. #
  25. # The instance definition that tor_instances expects:
  26. # inst_name{:inst_conf:inst_user:inst_group:inst_pidfile:inst_data_dir}
  27. #
  28.  
  29. . /etc/rc.subr
  30.  
  31. name="tor5"
  32. rcvar=tor5_enable
  33. exit_code=0
  34.  
  35. load_rc_config ${name}
  36.  
  37. : ${tor5_enable="NO"}
  38. : ${tor5_instances=""}
  39. : ${tor5_conf="/usr/local/etc/tor/torrc"}
  40. : ${tor5_user="_tor"}
  41. : ${tor5_group="_tor"}
  42. : ${tor5_pidfile="/var/run/tor/tor5.pid"}
  43. : ${tor5_datadir="/var/db/tor5"}
  44. : ${tor5_disable_default_instance="NO"}
  45.  
  46. instance=${slave_instance}
  47. if [ -n "${instance}" ]; then
  48. inst_def=${instance}
  49. inst_name=${inst_def%%:*}
  50. [ "${inst_name}" != "main" ] || err 1 "${name} instance can't be named 'main'"
  51. inst_def=${inst_def#$inst_name}
  52. if [ -n "$inst_def" ]; then
  53. # extended instance: parameters are set explicitly
  54. inst_def=${inst_def#:}
  55. tor5_conf=${inst_def%%:*}
  56. inst_def=${inst_def#$tor_conf:}
  57. tor_user=${inst_def%%:*}
  58. inst_def=${inst_def#$tor_user:}
  59. tor5_group=${inst_def%%:*}
  60. inst_def=${inst_def#$tor_group:}
  61. tor5_pidfile=${inst_def%%:*}
  62. tor5_datadir=${inst_def#$tor_pidfile:}
  63. if [ -z "${tor5_conf}" -o -z "${tor5_user}" -o -z "${tor5_group}" -o -z "${tor5_pidfile}" -o -z "${tor5_datadir}" ]; then
  64. warn "invalid tor instance ${inst_name} settings: ${instance}"
  65. exit 1
  66. fi
  67. else
  68. # regular instance: default parameters are used
  69. tor5_conf=${tor5_conf}@${inst_name}
  70. tor5_pidfile=${tor5_pidfile}@${inst_name}
  71. tor5_datadir=${tor5_datadir}/instance@${inst_name}
  72. fi
  73. if ! [ -r ${tor5_conf} ]; then
  74. warn "tor instance ${inst_name} config file ${tor5_conf} doesn't exist or isn't readable"
  75. warn "you can copy the sample config /usr/local/etc/tor/torrc.sample and modify it"
  76. exit 1
  77. fi
  78. if ! [ -d ${tor5_datadir} ]; then
  79. mkdir -p ${tor5_datadir} &&
  80. chown ${tor5_user}:${tor5_group} ${tor5_datadir} &&
  81. chmod 0700 ${tor5_datadir} &&
  82. echo "${name}: created the instance data directory ${tor5_datadir}"
  83. fi
  84. fi
  85.  
  86. if [ -z "${instance}" -a -n "${tor5_instances}" ]; then
  87. inst_only="$9"
  88. inst_done=0
  89. for i in ${tor5_instances}; do
  90. inst_name=${i%%:*}
  91. if [ -z "${inst_only}" -o "${inst_name}" = "${inst_only}" ]; then
  92. echo -n "${name} instance ${inst_name}: "
  93. if ! slave_instance=${i} /usr/local/etc/rc.d/tor5 "$1"; then
  94. exit_code=1
  95. fi
  96. inst_done=$((inst_done+1))
  97. fi
  98. done
  99. if [ -z "${inst_only}" -o "${inst_only}" = "main" ]; then
  100. checkyesno tor5_disable_default_instance && return $exit_code
  101. echo -n "${name} main instance: "
  102. elif [ -n "${inst_only}" ]; then
  103. [ $inst_done -gt 0 ] || err 1 "${name} instance '$inst_only' isn't defined"
  104. return $exit_code
  105. fi
  106. fi
  107.  
  108. required_files=${tor5_conf}
  109. required_dirs=${tor5_datadir}
  110. pidfile=${tor5_pidfile}
  111. command="/usr/local/bin/${name}"
  112. command_args="-f ${tor5_conf} --PidFile ${tor5_pidfile} --RunAsDaemon 1 --DataDirectory ${tor5_datadir}"
  113. extra_commands="reload"
  114.  
  115. if ! run_rc_command "$1"; then
  116. exit_code=1
  117. fi
  118.  
  119. return $exit_code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement