-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathentrypoint.sh
145 lines (126 loc) · 4.37 KB
/
entrypoint.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/sh
#
# Copyright (C) 2020-2024 diva.exchange
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Author/Maintainer: DIVA.EXCHANGE Association, https://diva.exchange
#
# -e Exit immediately if a simple command exits with a non-zero status
set -e
ENABLE_HTTPPROXY=${ENABLE_HTTPPROXY:-0}
if [[ ${ENABLE_HTTPPROXY} == 1 ]]
then
ENABLE_HTTPPROXY=true
else
ENABLE_HTTPPROXY=false
fi
PORT_HTTPPROXY=${PORT_HTTPPROXY:-4444}
ENABLE_SOCKSPROXY=${ENABLE_SOCKSPROXY:-0}
if [[ ${ENABLE_SOCKSPROXY} == 1 ]]
then
ENABLE_SOCKSPROXY=true
else
ENABLE_SOCKSPROXY=false
fi
PORT_SOCKSPROXY=${PORT_SOCKSPROXY:-4445}
ENABLE_SAM=${ENABLE_SAM:-0}
if [[ ${ENABLE_SAM} == 1 ]]
then
ENABLE_SAM=true
else
ENABLE_SAM=false
fi
PORT_SAM=${PORT_SAM:-7656}
ENABLE_FLOODFILL=${ENABLE_FLOODFILL:-0}
if [[ ${ENABLE_FLOODFILL} == 1 ]]
then
ENABLE_FLOODFILL=true
BANDWIDTH=${BANDWIDTH:-X}
else
ENABLE_FLOODFILL=false
BANDWIDTH=${BANDWIDTH:-L}
fi
TRANSIT_SHARE=${TRANSIT_SHARE:-100}
ENABLE_UPNP=${ENABLE_UPNP:-0}
if [[ ${ENABLE_UPNP} == 1 ]]
then
ENABLE_UPNP=true
else
ENABLE_UPNP=false
fi
ENABLE_HIDDEN=${ENABLE_HIDDEN:-0}
if [[ ${ENABLE_HIDDEN} == 1 ]]
then
ENABLE_HIDDEN=true
else
ENABLE_HIDDEN=false
fi
ENABLE_TUNNELS=${ENABLE_TUNNELS:-0}
IP_BRIDGE=${IP_BRIDGE:-`ip route | awk '/default/ { print $3; }'`}
# If IP_CONTAINER is not set in the environment, then get it from the host
if [ -z "$IP_CONTAINER" ]; then
IP_CONTAINER=`ip route get 1 | awk '{ print $NF; exit; }'`
echo "Binding to $IP_CONTAINER"
fi
# copy the i2pd directory to the home directory without overwriting the existing files
cp -nr /i2pd/* /home/i2pd/
# copy docker volumes separately
cp -nr /i2pd/conf/* /home/i2pd/conf/
cp -nr /i2pd/data/* /home/i2pd/data/
if [[ ${ENABLE_TUNNELS} == 1 ]]
then
TUNNELS_DIR_SOURCE=${TUNNELS_DIR_SOURCE:-/home/i2pd/tunnels.source.conf.d}
[[ ! -d ${TUNNELS_DIR_SOURCE} ]] && mkdir -p ${TUNNELS_DIR_SOURCE}
echo "Using tunnels source ${TUNNELS_DIR_SOURCE}"
TUNNELS_DIR=/home/i2pd/tunnels.conf.d
rm -f ${TUNNELS_DIR}/*.conf
if [[ `ls ${TUNNELS_DIR_SOURCE}/*.conf >/dev/null 2>&1 ; echo $?` -eq 0 ]]
then
cp ${TUNNELS_DIR_SOURCE}/*.conf ${TUNNELS_DIR}/
chown i2pd:i2pd ${TUNNELS_DIR}/*.conf
chmod 0644 ${TUNNELS_DIR}/*.conf
fi
# replace environment variables in the tunnels config files
for pathFile in `ls -1 ${TUNNELS_DIR}/*.conf 2>/dev/null`
do
eval "echo \"$(cat ${pathFile})\"" >${pathFile}
done
else
TUNNELS_DIR=/home/i2pd/tunnels.null
fi
LOGLEVEL=${LOGLEVEL:-info}
# create a copy of the i2pd config file
cp /home/i2pd/conf/i2pd.conf /tmp/i2pd.conf
# replace variables in the i2pd config files
sed -i 's!\$IP_CONTAINER!'"${IP_CONTAINER}"'!g' /tmp/i2pd.conf
sed -i 's!\$IP_BRIDGE!'"${IP_BRIDGE}"'!g' /tmp/i2pd.conf
sed -i 's!\$TUNNELS_DIR!'"${TUNNELS_DIR}"'!g' /tmp/i2pd.conf
sed -i 's!\$LOGLEVEL!'"${LOGLEVEL}"'!g' /tmp/i2pd.conf
sed -i 's!\$ENABLE_HTTPPROXY!'"${ENABLE_HTTPPROXY}"'!g' /tmp/i2pd.conf
sed -i 's!\$PORT_HTTPPROXY!'"${PORT_HTTPPROXY}"'!g' /tmp/i2pd.conf
sed -i 's!\$ENABLE_SOCKSPROXY!'"${ENABLE_SOCKSPROXY}"'!g' /tmp/i2pd.conf
sed -i 's!\$PORT_SOCKSPROXY!'"${PORT_SOCKSPROXY}"'!g' /tmp/i2pd.conf
sed -i 's!\$ENABLE_SAM!'"${ENABLE_SAM}"'!g' /tmp/i2pd.conf
sed -i 's!\$PORT_SAM!'"${PORT_SAM}"'!g' /tmp/i2pd.conf
sed -i 's!\$ENABLE_FLOODFILL!'"${ENABLE_FLOODFILL}"'!g' /tmp/i2pd.conf
sed -i 's!\$BANDWIDTH!'"${BANDWIDTH}"'!g' /tmp/i2pd.conf
sed -i 's!\$TRANSIT_SHARE!'"${TRANSIT_SHARE}"'!g' /tmp/i2pd.conf
sed -i 's!\$ENABLE_UPNP!'"${ENABLE_UPNP}"'!g' /tmp/i2pd.conf
sed -i 's!\$ENABLE_HIDDEN!'"${ENABLE_HIDDEN}"'!g' /tmp/i2pd.conf
# overwrite resolv.conf - using specific DNS servers only to initially access reseed servers
cat </home/i2pd/network/resolv.conf >/etc/resolv.conf
su - i2pd
# see configs: /conf/i2pd.conf
/i2pd/bin/i2pd --datadir=/home/i2pd/data --conf=/tmp/i2pd.conf