-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
186 lines (161 loc) · 5.3 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
set -e
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Run 'sudo ./install.sh'"
exit 1
fi
echo "##### Checking service ports availability"
if [[ `netstat -ntap |grep -c :9500` -eq 0 ]]; then
echo "Port 9500 available, OK"
else
echo "! Error: a process is already using port 9500"
exit 1
fi
if [[ `netstat -ntap |grep -c :9501` -eq 0 ]]; then
echo "Port 9501 available, OK"
else
echo "! Error: a process is already using port 9501"
exit 1
fi
if [[ `netstat -ntap |grep -c :9502` -eq 0 ]]; then
echo "Port 9502 available, OK"
else
echo "! Error: a process is already using port 9502"
exit 1
fi
if [[ `netstat -ntap |grep -c :9503` -eq 0 ]]; then
echo "Port 9503 available, OK"
else
echo "! Error: a process is already using port 9503"
exit 1
fi
echo "##### Installing system dependencies"
echo "# Updating repositories"
apt update
echo "# Installing PHP, Python3 Pip, Stunnel & OpenSSL"
apt install php python3 python3-pip stunnel4 openssl -y
echo "# Installing Python3 evdev module"
yes | pip3 install evdev
echo "# Installing Python3 python-uinput module"
yes | pip3 install python-uinput
echo "##### Install configuration files"
echo "# Generating self-signed SSL certificate and key for Stunnel"
openssl req -new -x509 -nodes -out /opt/ws-keyboard/ssl/cert.pem -keyout /opt/ws-keyboard/ssl/key.pem -days 3650 -subj "/C=RO/ST=Bucharest/L=Bucharest/O=WssKeyboard.none/CN=WssKeyboard.none"
echo "# Creating wsk-php service for client UI"
tee /etc/systemd/system/wsk-php.service >/dev/null <<'EOF'
[Unit]
Description=WebSocket Keyboard PHP Server
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/php -S 127.0.0.1:9501 -t /opt/ws-keyboard/web /opt/ws-keyboard/web/router.php
StandardOutput=inherit
StandardInput=inherit
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
echo "# Creating wsk-python3 service for WebSocket and relaying keyboard events"
tee /etc/systemd/system/wsk-python3.service >/dev/null <<'EOF'
[Unit]
Description=WebSocket Keyboard Python3 Server
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/python3 /opt/ws-keyboard/local/server.py --host 127.0.0.1 --port 9503
StandardOutput=inherit
StandardInput=inherit
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
echo "# Creating wsk-stunnel service for SSL connections"
tee /etc/systemd/system/wsk-stunnel.service >/dev/null <<'EOF'
[Unit]
Description=WebSocket Keyboard Stunnel Server
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/stunnel /opt/ws-keyboard/local/stunnel.conf
StandardOutput=inherit
StandardInput=inherit
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
echo "# Creating wsk-stunnel configuration file"
tee /opt/ws-keyboard/local/ws-keyboard-stunnel.conf >/dev/null <<'EOF'
; Certificate/key is needed in server mode and optional in client mode
cert = /opt/ws-keyboard/ssl/cert.pem
key = /opt/ws-keyboard/ssl/key.pem
; Protocol version (all, SSLv2, SSLv3, TLSv1)
sslVersion = all
; PID is created inside the chroot jail
pid = /run/wsk-stunnel.pid
; Some performance tunings
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
; Some debugging stuff useful for troubleshooting
;debug = 7
output = /var/log/wsk-stunnel.log
; Service-level configuration
[wsPhpServer]
accept = 0.0.0.0:9500
connect = 127.0.0.1:9501
[wsPythonServer]
accept = 0.0.0.0:9502
connect = 127.0.0.1:9503
EOF
echo "#### Adding evdev and uinput modules to /etc/modules"
if grep -q "uinput" /etc/modules; then
echo
else
echo "uinput" >> /etc/modules
fi
if grep -q "evdev" /etc/modules; then
echo
else
echo "evdev" >> /etc/modules
fi
echo "# Fixing permissions"
chown -R ${SUDO_USER}:${SUDO_USER} /opt/ws-keyboard
echo "##### Enabling and starting services"
systemctl daemon-reload
systemctl enable wsk-php.service
systemctl enable wsk-python3.service
systemctl enable wsk-stunnel.service
systemctl start wsk-php.service
systemctl start wsk-python3.service
systemctl start wsk-stunnel.service
echo "# Sleeping for 5 seconds while waiting for services"
sleep 5
echo "##### Checking service ports"
if [[ `netstat -ntap |grep stunnel |grep -c :9500` -eq 1 ]]; then
echo "- Service wsk-stunnel confirmed on port 9500"
else
echo "! Error: could not find service wsk-stunnel on port 9500"
fi
if [[ `netstat -ntap |grep php |grep -c :9501` -eq 1 ]]; then
echo "- Service wsk-php confirmed on port 9501"
else
echo "! Error: could not find service wsk-php on port 9501"
fi
if [[ `netstat -ntap |grep stunnel |grep -c :9502` -eq 1 ]]; then
echo "- Service wsk-stunnel confirmed on port 9502"
else
echo "! Error: could not find service wsk-stunnel on port 9502"
fi
if [[ `netstat -ntap |grep python3 |grep -c :9503` -eq 1 ]]; then
echo "- Service wsk-python3 confirmed on port 9503"
else
echo "! Error: could not find service wsk-python3 on port 9503"
fi
LOCAL_IP_ADDRESS=$(ip -4 route |grep default |head -n1 |awk -F 'src ' '{print $NF}' |awk '{print $1}')
echo ""
echo "DONE:"
echo "- If all service ports above have been confirmed, installation was successfully completed;"
echo "- Visit both 'https://${LOCAL_IP_ADDRESS}:9500/' and 'https://${LOCAL_IP_ADDRESS}:9502/' and add browser exceptions for the self-signed SSL certificate;"
echo "- Access 'https://${LOCAL_IP_ADDRESS}:9500/' click 'Connect' and start sending keyboard events to the linux active display."