install_tor.sh 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/bash
  2. # Based on Adafruit Learning Technologies Onion Pi project
  3. # More info: http://learn.adafruit.com/onion-pi
  4. if (( $EUID != 0 )); then
  5. echo "This must be run as root. Type in 'sudo bash $0' to run it as root."
  6. exit 1
  7. fi
  8. echo "$(tput setaf 2)
  9. ..
  10. ,:
  11. . ::
  12. .: :2.
  13. .:, 1L
  14. .v: Z, ..::,
  15. :k:N.Lv:
  16. 22ukL
  17. JSYk.$(tput bold ; tput setaf 7)
  18. ,B@B@i
  19. BO@@B@.
  20. :B@L@Bv:@7
  21. .PB@iBB@ .@Mi
  22. .P@B@iE@@r . 7B@i
  23. 5@@B@:NB@1$(tput setaf 5) r ri:$(tput bold ; tput setaf 7)7@M
  24. .@B@BG.OB@B$(tput setaf 5) ,.. .i, $(tput bold ; tput setaf 7)MB,
  25. @B@BO.B@@B$(tput setaf 5) i7777, $(tput bold ; tput setaf 7)MB.
  26. PB@B@.OB@BE$(tput setaf 5) LririL,.L. $(tput bold ; tput setaf 7)@P
  27. B@B@5iB@B@i$(tput setaf 5) :77r7L, L7 $(tput bold ; tput setaf 7)O@
  28. @B1B27@B@B,$(tput setaf 5) . .:ii. r7 $(tput bold ; tput setaf 7)BB
  29. O@.@M:B@B@:$(tput setaf 5) v7: ::. $(tput bold ; tput setaf 7)BM
  30. :Br7@L5B@BO$(tput setaf 5) irL: :v7L. $(tput bold ; tput setaf 7)P@,
  31. 7@,Y@UqB@B7$(tput setaf 5) ir ,L;r: $(tput bold ; tput setaf 7)u@7
  32. r@LiBMBB@Bu$(tput setaf 5) rr:.$(tput bold ; tput setaf 7):B@i
  33. FNL1NB@@@@: ;OBX
  34. rLu2ZB@B@@XqG7$(tput sgr0 ; tput setaf 2)
  35. . rJuv::
  36. $(tput setaf 2)ONION PI
  37. $(tput bold ; tput setaf 5)by adafruit. Mainly fixed by Ajani for https://raspberry-pi.fr$(tput sgr0)
  38. "
  39. echo "$(tput setaf 6)This script will auto-setup an Onion Pi Tor proxy for you.$(tput sgr0)"
  40. read -p "$(tput bold ; tput setaf 2)Press [Enter] to begin, [Ctrl-C] to abort...$(tput sgr0)"
  41. echo "$(tput setaf 6)Installing Tor...$(tput sgr0)"
  42. apt-get install tor -y
  43. echo "$(tput setaf 6)Configuring Tor...$(tput sgr0)"
  44. cp /etc/tor/torrc /etc/tor/torrc.bak
  45. echo "Log notice file /var/log/tor/notices.log
  46. VirtualAddrNetwork 10.192.0.0/10
  47. AutomapHostsSuffixes .onion,.exit
  48. AutomapHostsOnResolve 1
  49. TransPort 192.168.4.1:9040
  50. DNSPort 192.168.4.1:53" >> /etc/tor/torrc
  51. echo "$(tput setaf 6)Flushing old IP tables...$(tput sgr0)"
  52. iptables -F
  53. iptables -t nat -F
  54. echo "$(tput setaf 6)Establishing $(tput bold)ssh$(tput sgr0 ; tput setaf 6) exception on port 22...$(tput sgr0)"
  55. iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 22 -j REDIRECT --to-ports 22
  56. echo "$(tput setaf 6)Rerouting DNS traffic...$(tput sgr0)"
  57. iptables -t nat -A PREROUTING -i wlan0 -p udp --dport 53 -j REDIRECT --to-ports 53
  58. echo "$(tput setaf 6)Rerouting TCP traffic...$(tput sgr0)"
  59. iptables -t nat -A PREROUTING -i wlan0 -p tcp --syn -j REDIRECT --to-ports 9040
  60. echo "$(tput setaf 6)Saving IP tables...$(tput sgr0)"
  61. sh -c "iptables-save > /etc/iptables.ipv4.nat"
  62. echo "$(tput setaf 6)Setting up logging in /var/log/tor/notices.log...$(tput sgr0)"
  63. touch /var/log/tor/notices.log
  64. chown debian-tor /var/log/tor/notices.log
  65. chmod 644 /var/log/tor/notices.log
  66. echo "$(tput setaf 6)Starting Tor...$(tput sgr0)"
  67. service tor start
  68. echo "$(tput setaf 6)Setting Tor to start at boot...$(tput sgr0)"
  69. update-rc.d tor enable
  70. echo "$(tput setaf 6)Force Tor to wait 1 minute before running in order to wait for wlan0 interface...$(tput sgr0)"
  71. mkdir /etc/systemd/system/tor@default.service.d/
  72. touch /etc/systemd/system/tor@default.service.d/wait_for_network.conf
  73. printf '[Service]\nExecStartPre=/bin/sleep 60' > /etc/systemd/system/tor@default.service.d/wait_for_network.conf
  74. sudo systemctl daemon-reload
  75. echo "$(tput setaf 6)Setup complete!
  76. $(tput bold)Verify by visiting: $(tput setaf 3)https://check.torproject.org/$(tput sgr0)
  77. $(tput setaf 6)Rebooting$(tput sgr0)..."
  78. reboot
  79. exit 0