Repository navigation
Expand file tree
/
Copy pathcompile
More file actions
119 lines (96 loc) · 3.21 KB
/
Copy pathcompile
File metadata and controls
119 lines (96 loc) · 3.21 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
## VARIABLES
RUN_COMMAND=run_tor
TOR_VER=0.3.2.9
TOR_SRC_NAME=tor-${TOR_VER}.tar.gz
TOR_DIST_URL=https://dist.torproject.org/
## --
set -x
indent() {
sed -u 's/^/ /'
}
BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3
TOR_SIG_NAME=${TOR_SRC_NAME}.asc
TOR_SRC_URL=${TOR_DIST_URL}${TOR_SRC_NAME}
TOR_SRC_SIG_URL=${TOR_DIST_URL}${TOR_SIG_NAME}
################################################################################
# Try use cache
################################################################################
mkdir -p $CACHE_DIR
grep -wq "${TOR_SRC_NAME}" $CACHE_DIR/tor_version.txt
if [ $? -eq 0 ] ; then # Reusing cache
TOR_IS_CACHED=1
else
TOR_IS_CACHED=0
fi
################################################################################
# GET SOURCES
################################################################################
if [ $TOR_IS_CACHED -eq 0 ] ; then
echo "Downloading ${TOR_SRC_URL}"
wget -q $TOR_SRC_URL
if [ $? - ne 0]; then
echo "FAILED to obtain ${TOR_SRC_URL}" | indent
exit 1
fi
echo "Downloading ${TOR_SRC_SIG_URL}"
wget -q $TOR_SRC_SIG_URL
if [ $? -ne 0 ]; then
echo "FAILED to obtain signature ${TOR_SRC_SIG_URL}" | indent
exit 1
fi
fi
################################################################################
# VERIFY INTEGRITY
################################################################################
if [ $TOR_IS_CACHED -eq 0 ] ; then
gpg --keyserver pool.sks-keyservers.net --recv-keys 0x4E2C6E8793298290
gpg --keyserver pool.sks-keyservers.net --recv-keys 0x6AFEE6D49E92B601
gpg --verify ${TOR_SIG_NAME} ${TOR_SRC_NAME} | grep -c "Good signature"
if [ $? -lt 1 ]; then
echo "FAILED to verify the signature" | indent
exit 1
fi
fi
################################################################################
# COMPILE
################################################################################
if [ $TOR_IS_CACHED -eq 0 ] ; then
tar -zxf ${TOR_SRC_NAME}
cd tor-${TOR_VER}
./configure --prefix=$CACHE_DIR/tor
if [ $? -ne 0 ]; then
echo "FAILED to configure for compliation" | indent
exit 1
fi
make install
if [ $? -ne 0 ]; then
echo "FAILED to run make install" | indent
exit 1
fi
fi
################################################################################
# INSTALL
################################################################################
# Cached instalation to real build dir
cp -r $CACHE_DIR/tor ${BUILD_DIR}
# Saves the version just compiled
echo "${TOR_SRC_NAME}" > $CACHE_DIR/tor_version.txt
cat > ${BUILD_DIR}/tor/bin/${RUN_COMMAND} <<EOF
#!/usr/bin/env bash
mkdir -p "${HOME}/hidden_service"
echo "Setting up hidden service"
cat > ${HOME}/hidden_service/private_key <<EPK
\${HIDDEN_PRIVATE_KEY}
EPK
echo \${HIDDEN_DOT_ONION} > ${HOME}/hidden_service/hostname
echo "HiddenServiceDir ${HOME}/hidden_service/" > $HOME/tor/etc/tor/torrc
echo "HiddenServicePort 80 127.0.0.1:\${PORT}" >> $HOME/tor/etc/tor/torrc
# Use -f to be safe here.
$HOME/tor/bin/tor -f $HOME/tor/etc/tor/torrc &
exec \$*
EOF
chmod a+x ${BUILD_DIR}/tor/bin/${RUN_COMMAND}
echo "Installed Tor successfully" | indent