run-browser.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/env bash
  2. # Runs a browser bundle that can run TOR, I2P, XD torrenting client and shut
  3. # everything down automatically when browser closes.
  4. # License: CC0
  5. # Usage:
  6. # - Keep this script in a directory
  7. # - Make sure to have firefox, tor, i2pd, XD installed or built from source
  8. # Instructions: linux/i2p-browser-bundle/README.md
  9. # - Launch it, install FoxyProxy plugin, import the
  10. # `FoxyProxy Standard presets.json` in this directory. Enable the rules by
  11. # clicking the toolbar icon -> Use Enabled Proxies By Patterns and Order
  12. # - Don't forget to apply settings changes and check suggested addons from:
  13. # - https://privacytools.io/browsers/#webrtc
  14. # - https://privacytools.io/browsers/#addons
  15. # - https://privacytools.io/browsers/#about_config
  16. cd `dirname $0`
  17. echo "== Running I2P Bundle from $(pwd)..."
  18. # Ports
  19. # If you change these you may have to change them on FoxyProxy later on (check
  20. # both edit and patterns)
  21. tor_socks_port=9450
  22. i2pd_http_port=4455
  23. i2pd_socks_port=4449
  24. i2pd_webconsole_port=6060
  25. xd_webui_port=1776
  26. echo "== Attempting to run the browser..."
  27. echo "Once it runs you will be able to access:"
  28. echo "- i2pd panel: http://127.0.0.1:$i2pd_webconsole_port/"
  29. echo "- XD webui: http://127.0.0.1:$xd_webui_port/"
  30. echo "- Be sure to have FoxyProxy addon configured with the accompanied json file to access things properly"
  31. # Runs i2pd
  32. ulimit -n 4096
  33. if [ -f i2pd/i2pd ]; then
  34. # Setting data dir and ports as we have in FoxyProxy.
  35. # --loglevel is set to none because i2pd logs never gave me any clue to
  36. # what's wrong. Remove it to get logs back.
  37. # SAM is enabled for XD to work.
  38. i2pd/i2pd --datadir i2pd-data --loglevel=none --http.port=$i2pd_webconsole_port --httpproxy.enabled=1 --httpproxy.port=$i2pd_http_port --socksproxy.port=$i2pd_socks_port --sam.enabled=1 &
  39. else
  40. i2pd --datadir i2pd-data --loglevel=none --http.port=$i2pd_webconsole_port --httpproxy.enabled=1 --httpproxy.port=$i2pd_http_port --socksproxy.port=$i2pd_socks_port --sam.enabled=1 &
  41. fi
  42. i2pd_pid=$!
  43. # Runs XD BitTorrent client
  44. [ ! -d XD-data ] && mkdir XD-data
  45. cd XD-data
  46. if [ -f ../XD/XD ]; then
  47. ../XD/XD torrents.ini &
  48. else
  49. XD torrents.ini &
  50. fi
  51. xd_pid=$!
  52. cd ..
  53. # Runs tor
  54. mkdir tor-data
  55. if [ -f tor/tor ]; then
  56. tor/tor --SocksPort $tor_socks_port --DataDirectory tor-data --User '' &
  57. else
  58. tor --SocksPort $tor_socks_port --DataDirectory tor-data --User '' &
  59. fi
  60. tor_pid=$!
  61. # Quick and simple way to kill a process by its pid number
  62. # $1: pid
  63. # $2: binary name
  64. _killpid () {
  65. # Send QUIT signal (-3) first
  66. kill -3 $1 || echo "$2, pid $1 not running, so skipping kill call"
  67. # Give it 7 seconds then silently hard kill the pid if still running
  68. sleep 7 && kill -9 $1 &>/dev/null
  69. }
  70. # Change the command to anything you wish, but keep the ";" at the end because
  71. # it helps to shut everything down once the browser closes.
  72. firefox --no-remote --profile "$PWD/tor-firefox-profile" "http://127.0.0.1:$i2pd_webconsole_port" "http://127.0.0.1:$xd_webui_port";
  73. echo "== Killing XD, i2pd and tor...";
  74. _killpid "$xd_pid" 'XD' &
  75. _killpid "$i2pd_pid" 'i2pd' &
  76. _killpid "$tor_pid" 'tor' &