-
Notifications
You must be signed in to change notification settings - Fork 0
/
insta-onion.sh
65 lines (49 loc) · 1.97 KB
/
insta-onion.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
set -euo pipefail
if [ $# -lt 2 ]; then
echo ' $ sudo bash insta-onion.sh <onion_service_name> <local_http_port_your_app_is_listening_on>'
echo
echo 'or'
echo
echo ' # bash insta-onion.sh <onion_service_name> <local_http_port_your_app_is_listening_on>'
echo
echo 'Note: onion_service_name will be used to create a folder at /var/lib/tor/<onion_service_name>'
exit 1
fi
export onion_service_name="${1:-onion_service_`date -I`}"
export local_http_port="${2:-8000}"
export distro="$(lsb_release -is)"
if [[ ("$distro" != 'Debian') && ("$distro" != 'Ubuntu') ]]; then
echo "For now, this script only works on Debian and Ubuntu. Sorry!";
exit 1
fi
if [[ "$(lsb_release -cs)" == "trusty" ]]; then
echo "$(lsb_release -ds) is too old! Consider upgrading."
exit 1
fi
sudo apt-get update && sudo apt-get install -y curl gnupg2
curl https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --import
gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -
echo "deb http://deb.torproject.org/torproject.org $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/tor.list
sudo apt-get update
sudo apt-get install -y tor
export onion_dir="/var/lib/tor/$onion_service_name"
sudo mkdir "$onion_dir"
sudo chown debian-tor:debian-tor "$onion_dir"
sudo chmod 0700 "$onion_dir"
echo 'Appending to /etc/tor/torrc ...'
echo "" | sudo tee -a /etc/tor/torrc
echo "HiddenServiceDir $onion_dir" | sudo tee -a /etc/tor/torrc
echo "HiddenServicePort 80 127.0.0.1:$local_http_port" | sudo tee -a /etc/tor/torrc
sudo service tor restart
sleep 2
if [[ -f "$onion_dir"/hostname ]]; then
echo
echo 'Congratulations! Your onion service now exists at '$(cat "$onion_dir"/hostname)
exit 0
fi
echo -n '
...Now just wait a few minutes for your Onion service to be created!'
echo ' Once it has, you can view your new, randomly-generated .onion address by running
$ sudo cat '"$onion_dir"/hostname'
'