Advertisement
Guest User

Untitled

a guest
Aug 10th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 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="tor"
  32. rcvar=tor_enable
  33. exit_code=0
  34.  
  35. load_rc_config ${name}
  36.  
  37. : ${tor_enable="NO"}
  38. : ${tor_instances=""}
  39. : ${tor_conf="/usr/local/etc/tor/torrc"}
  40. : ${tor_user="_tor"}
  41. : ${tor_group="_tor"}
  42. : ${tor_pidfile="/var/run/tor/tor.pid"}
  43. : ${tor_datadir="/var/db/tor"}
  44. : ${tor_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. tor_conf=${inst_def%%:*}
  56. inst_def=${inst_def#$tor_conf:}
  57. tor_user=${inst_def%%:*}
  58. inst_def=${inst_def#$tor_user:}
  59. tor_group=${inst_def%%:*}
  60. inst_def=${inst_def#$tor_group:}
  61. tor_pidfile=${inst_def%%:*}
  62. tor_datadir=${inst_def#$tor_pidfile:}
  63. if [ -z "${tor_conf}" -o -z "${tor_user}" -o -z "${tor_group}" -o -z "${tor_pidfile}" -o -z "${tor_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. tor_conf=${tor_conf}@${inst_name}
  70. tor_pidfile=${tor_pidfile}@${inst_name}
  71. tor_datadir=${tor_datadir}/instance@${inst_name}
  72. fi
  73. if ! [ -r ${tor_conf} ]; then
  74. warn "tor instance ${inst_name} config file ${tor_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 ${tor_datadir} ]; then
  79. mkdir -p ${tor_datadir} &&
  80. chown ${tor_user}:${tor_group} ${tor_datadir} &&
  81. chmod 0700 ${tor_datadir} &&
  82. echo "${name}: created the instance data directory ${tor_datadir}"
  83. fi
  84. fi
  85.  
  86. if [ -z "${instance}" -a -n "${tor_instances}" ]; then
  87. inst_only="$9"
  88. inst_done=0
  89. for i in ${tor_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/tor "$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 tor_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=${tor_conf}
  109. required_dirs=${tor_datadir}
  110. pidfile=${tor_pidfile}
  111. command="/usr/local/bin/${name}"
  112. command_args="-f ${tor_conf} --PidFile ${tor_pidfile} --RunAsDaemon 1 --DataDirectory ${tor_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