-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.sh
162 lines (132 loc) · 4.81 KB
/
install.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/data/data/com.termux/files/usr/bin/bash
set -e
domain_name="$1"
staging="$2"
size="$(stty -a < "$(tty)" | grep -Po '(?<=columns )\d+')"
lines(){
eval "printf -- '-%.0s' {1..$size}"
}
# Check for arguments
if [ -z "$domain_name" ]; then
echo "specify your domain name: "
read -r domain_name <&1
if test -z "$domain_name" ; then
echo "No domain name specified"
exit
fi
if test -z "$staging" ; then
echo "would you like to use certbot's staging environment ?"
echo "https://letsencrypt.org/docs/staging-environment/"
echo "Use certbot stagin ? N/y: "
read -r staging <&1
fi
if [[ $(echo "$staging" | tr '[:upper:]' '[:lower:]') = y* ]] ; then
echo "Using staging"
stage_flag="--test-cert"
fi
fi
#################### Synapse ####################
#
# Update and dependencies installation.
yes | pkg update -y
pkg innstall -y build-essential binutils python rust libffi sqlite openssl libjpeg-turbo
pip install virtualenv
# Configuring cargo, see https://github.com/termux/termux-packages/issues/12260
mkdir ~/.cargo
cat << EOF > ~/.cargo/config.toml
[profile.dev]
lto = false
[profile.release]
lto = false
[profile.test]
lto =false
[profile.bench]
lto = false
EOF
# Required for rust to build python cryptography package
CARGO_BUILD_TARGET="$(rustc --print target-list | grep android | grep "$(uname -m | cut -d7 -f1)" )"
export CARGO_BUILD_TARGET
# Creating synapse directory and initializing it with a virtenv
mkdir -p "$PREFIX/opt/synapse"
virtualenv -p python3 "$PREFIX/opt/synapse/env"
# Installing what's needed (included in official docs
pip="$PREFIX/opt/synapse/env/bin/pip"
$pip install --upgrade pip
$pip install --upgrade setuptools
$pip install matrix-synapse
# Configuring synapse
cd "$PREFIX/opt/synapse"
./env/bin/python -m synapse.app.homeserver \
--server-name "$domain_name" \
--config-path homeserver.yaml \
--generate-config \
--report-stats=no
echo 'suppress_key_server_warning: true' >> homeserver.yaml
echo 'serve_server_wellknown: true' >> homeserver.yaml
# Setting up synctl
cat << EOF > "$PREFIX/bin/synctl"
#!$PREFIX/bin/bash
cd \$PREFIX/opt/synapse
source ./env/bin/activate
./env/bin/synctl "\$@"
EOF
chmod +x "$PREFIX/bin/synctl"
################# nginx-certbot #################
################# *Installation #################
pkg install -y nginx termux-services
python -m venv "$PREFIX/opt/certbot"
pip="$PREFIX/opt/certbot/bin/pip"
$pip install --upgrade pip
$pip install certbot certbot-nginx
if ! test -f "$PREFIX/bin/certbot" ; then
ln -s "$PREFIX/opt/certbot/bin/certbot" "$PREFIX/bin/certbot"
fi
cp "$PREFIX/etc/nginx/nginx.conf" "$PREFIX/etc/nginx/nginx.conf.orig"
curl "https://raw.githubusercontent.com/medanisjbara/synapse-termux/main/nginx.conf" > "$PREFIX/etc/nginx/nginx.conf"
mkdir -p "$PREFIX/etc/nginx/sites-available" "$PREFIX/etc/nginx/sites-enabled"
cat << EOF > "$PREFIX/etc/nginx/sites-available/matrix"
server {
server_name $domain_name;
location / {
proxy_pass http://localhost:8008;
}
location ~* ^(\/_matrix|\/_synapse\/client) {
proxy_pass http://localhost:8008;
proxy_set_header X-Forwarded-For \$remote_addr;
client_max_body_size 50M ;
}
}
EOF
if ! test -L "$PREFIX/etc/nginx/sites-enabled/matrix" ; then
ln -s "$PREFIX/etc/nginx/sites-available/matrix" "$PREFIX/etc/nginx/sites-enabled"
fi
lines
echo "Running nginx test"
if nginx -t ; then
echo "Test passed"
else
lines
echo "Test didn't pass, please solve this error and/report the issue to https://github.com/medanisjbara/synapse-termux"
exit
fi
# Sourcing services daemon
# shellcheck source=/dev/null
source "$PREFIX/etc/profile.d/start-services.sh"
sv up nginx
lines
echo "Preparations have been made correctly. To be able to get the ssl_certificate please forward the port 8080 on LAN to port 80 on WAN, And While you're at it, consider forwarding port 8443 on LAN to port 443 on WAN since you will need it later."
echo "You can find this in your router settings"
echo -n "After doing so, press enter to continue."
read -r <&1
lines
certbot --work-dir "$PREFIX"/var/lib/letsencrypt --logs-dir "$PREFIX"/var/log/letsencrypt --config-dir "$PREFIX"/etc/letsencrypt --nginx-server-root "$PREFIX"/etc/nginx --http-01-port 8080 --https-port 8443 "$stage_flag" -v --nginx -d "$domain_name" <&1
if ! grep -q ssl_certificate "$PREFIX/etc/nginx/sites-available/matrix" ; then
echo "Seems like certbot worked but didn't change your config file. Please visit the following link"
echo "https://github.com/medanisjbara/synapse-termux/blob/main/GUIDE.md#certbot-didnt-setup-the-config"
fi
sed 's/ 80;/ 8080;/g' "$PREFIX/etc/nginx/sites-available/matrix" -i
sed 's/ 443;/ 8443;/g' "$PREFIX/etc/nginx/sites-available/matrix" -i
synctl start
echo
echo "Installation completed without errors. Your matrix server is running."
echo "Happy Chatting !!"