blob: 2a21f3cbceca03a135e2fbd2c87c7017f6bf0281 (
plain)
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
#!/bin/bash
busName=trash.chat.app
busDir="${XDG_RUNTIME_DIR}/app/${busName}"
function moeDect() {
if [[ -f /usr/share/moeOS-Docs/os-release ]]; then
osRel="/usr/share/moeOS-Docs/os-release"
else
osRel="/usr/lib/os-release"
fi
}
function sourceXDG() {
if [[ ! ${XDG_CONFIG_HOME} ]]; then
if [ -f "${HOME}"/.config/user-dirs.dirs ]; then
source "${HOME}"/.config/user-dirs.dirs
fi
if [ ! ${XDG_CONFIG_HOME} ]; then
export XDG_CONFIG_HOME="${HOME}"/.config
fi
echo "[Info] Guessing XDG Config Home @ ${XDG_CONFIG_HOME}"
else
source "${XDG_CONFIG_HOME}"/user-dirs.dirs
echo "[Info] XDG Config Home @ ${XDG_CONFIG_HOME}"
fi
if [ -f "${XDG_CONFIG_HOME}"/user-dirs.dirs ]; then
source "${XDG_CONFIG_HOME}"/user-dirs.dirs
fi
if [[ ! ${XDG_DATA_HOME} ]]; then
export XDG_DATA_HOME="${HOME}"/.local/share
fi
}
function manageDirs() {
if [ -d "${HOME}/Documents/TrashBox" ]; then
echo "[Warn] Old user data may be present, check ${HOME}/Documents/TrashBox"
fi
if [ -d "${XDG_DOCUMENTS_DIR}/WeChat_Data/文档" ]; then
mv "${XDG_DOCUMENTS_DIR}/WeChat_Data/文档" \
"${XDG_DOCUMENTS_DIR}/WeChat_Data/Documents"
fi
if [ -d "${XDG_DOCUMENTS_DIR}"/WeChat_Data ]; then
echo "[Info] Migrating user data..."
mv "${XDG_DOCUMENTS_DIR}"/WeChat_Data "${XDG_DATA_HOME}"/WeChat_Data
fi
if [ -d "${XDG_DOCUMENTS_DIR}"/xwechat_files ]; then
echo "[Info] Removing unused links..."
rm "${XDG_DOCUMENTS_DIR}"/xwechat_files
fi
createWrapIfNotExist "${XDG_DATA_HOME}"/WeChat_Data
}
function detectXauth() {
if [ ! ${XAUTHORITY} ]; then
echo '[Warn] No ${XAUTHORITY} detected! Do you have any X server running?'
export XAUTHORITYpath="/$(uuidgen)/$(uuidgen)"
if [[ "${LANG}" =~ 'zh_CN' ]]; then
zenity --title "未找到 XAUTHORITY" --icon=image-missing-symbolic --default-cancel --question --text="解锁 X 服务器以继续?"
else
zenity --title "XAUTHORITY not found" --icon=image-missing-symbolic --default-cancel --question --text="Unlock X Server to continue?"
fi
if [ $? = 0 ]; then
xhost +
fi
else
export XAUTHORITYpath="${XAUTHORITY}"
fi
if [[ ! ${DISPLAY} ]]; then
echo '[Warn] No ${DISPLAY} detected! Do you have any X server running?'
fi
}
function createWrapIfNotExist() {
if [ -d "$@" ]; then
return 0
else
mkdir -p "$@"
fi
}
function inputMethod() {
if [[ ${XMODIFIERS} =~ fcitx ]]; then
QT_IM_MODULE=fcitx
GTK_IM_MODULE=fcitx
elif [[ ${XMODIFIERS} =~ ibus ]]; then
QT_IM_MODULE=ibus
GTK_IM_MODULE=ibus
IBUS_USE_PORTAL=1
elif [[ ${XMODIFIERS} =~ gcin ]]; then
QT_IM_MODULE=ibus
GTK_IM_MODULE=gcin
LC_CTYPE=zh_TW.UTF-8
else
echo '[Warn] Input Method potentially broken! Please set $XMODIFIERS properly'
fi
}
function lnDir() {
# Deprecated function
if [ -d "${XDG_DATA_HOME}"/WeChat_Data/Documents/xwechat_files ]; then
ln -srf "${XDG_DATA_HOME}"/WeChat_Data/xwechat_files \
"${HOME}"/xwechat_files
fi
}
function importEnv() {
if [ -e "${XDG_DATA_HOME}"/WeChat_Data/wechat.env ]; then
echo "[Info] ${XDG_DATA_HOME}/WeChat_Data/wechat.env exists"
else
touch "${XDG_DATA_HOME}"/WeChat_Data/wechat.env
fi
if [[ $(cat "${XDG_DATA_HOME}"/WeChat_Data/wechat.env) ]]; then
return 0
else
echo "# Envs" >>"${XDG_DATA_HOME}"/WeChat_Data/wechat.env
echo "isWeChatEnvPresent=1" >>"${XDG_DATA_HOME}"/WeChat_Data/wechat.env
fi
}
function cameraDect() {
bwCamPar=""
for camera in $(ls /dev/video*); do
if [ -e ${camera} ]; then
bwCamPar="${bwCamPar} --dev-bind ${camera} ${camera}"
fi
done
if [[ ${bwCamPar} =~ dev-bind ]]; then
echo "[Info] Camera bound"
fi
}
function execApp() {
# Wayland is not available for now
# --ro-bind-try "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}" \
# "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}" \
if [[ ${wechatXserverPatch} = 1 ]]; then
xhost +
fi
if [ ! -S "${busDir}/bus" ]; then
echo "[Info] Waiting for D-Bus proxy..."
counter=0
while [ ! -S "${busDir}/bus" ]; do
counter=$(expr ${counter} + 1)
sleep 0.1s
done
echo "[Info] D-Bus proxy took $(expr ${counter} / 10)s to launch"
fi
touch "${XDG_DATA_HOME}"/WeChat_Data/.flatpak-info
cameraDect
importEnv
if [[ $(systemctl --user is-failed wechat-uos-qt.service) = failed ]]; then
echo "[Warning] WeChat failed last time"
systemctl --user reset-failed wechat-uos-qt.service
fi
if [[ $(systemctl --user is-active wechat-uos-qt.service) = active ]]; then
warnMulRunning wechat-uos-qt.service
fi
if [ ${XDG_SESSION_TYPE} = wayland ]; then
echo "[Info] Skipping Xhost operation"
else
xhost + #Unlock the XServer for X11 users
fi
systemd-run \
--user \
${sdOption} \
-u wechat-uos-qt \
-p CPUWeight=50 \
-p IOWeight=40 \
-p IPAccounting=yes \
-p UnsetEnvironment=XDG_CURRENT_DESKTOP \
-p UnsetEnvironment=WAYLAND_DISPLAY \
-p UnsetEnvironment=XDG_SESSION_TYPE \
-p PrivateIPC=yes \
-p DevicePolicy=strict \
-p EnvironmentFile=/usr/lib/wechat-uos-qt/envs \
-p EnvironmentFile="${XDG_DATA_HOME}"/WeChat_Data/wechat.env \
-p Environment=GTK_IM_MODULE="${GTK_IM_MODULE}" \
-p Environment=QT_IM_MODULE="${QT_IM_MODULE}" \
-p IPAddressDeny=localhost \
-p IPAddressDeny=link-local \
-p IPAddressDeny=multicast \
-p SystemCallFilter=~@clock \
-p SystemCallFilter=~@cpu-emulation \
-p SystemCallFilter=~@debug \
-p SystemCallFilter=~@module \
-p SystemCallFilter=~@obsolete \
-p SystemCallFilter=~@raw-io \
-p SystemCallFilter=~@reboot \
-p SystemCallFilter=~@swap \
-p SystemCallErrorNumber=EPERM \
-p ProcSubset=pid \
-p RestrictAddressFamilies=AF_UNIX \
-p RestrictAddressFamilies=AF_INET \
-p RestrictAddressFamilies=AF_INET6 \
-p NoNewPrivileges=yes \
-p RestrictNamespaces=~net \
-p RestrictNamespaces=~pid \
-p RestrictNamespaces=~uts \
-p RestrictNamespaces=~ipc \
-p ProtectControlGroups=yes \
-p KeyringMode=private \
-p ProtectClock=yes \
-p CapabilityBoundingSet= \
-p ProtectKernelModules=yes \
-p SystemCallArchitectures=native \
-p RestrictNamespaces=no \
-p RestrictSUIDSGID=yes \
-p LockPersonality=yes \
-p RestrictRealtime=yes \
-p ProtectSystem=strict \
-p ProtectProc=invisible \
-p ProtectHome=no \
-p PrivateUsers=yes \
-p UMask=077 \
-p RestrictAddressFamilies=~AF_NETLINK \
-p RestrictAddressFamilies=~AF_PACKET \
-p PrivateTmp=yes \
-p BindReadOnlyPaths=/usr/bin/true:/usr/bin/lsblk \
-p BindReadOnlyPaths=/opt/wechat-uos-qt/files:/usr/lib/license \
-p BindReadOnlyPaths=-/run/systemd/resolve/stub-resolv.conf \
-p Environment=PATH=/usr/bin \
-- \
bwrap \
--dev /dev \
--dev-bind /dev/dri /dev/dri \
--dev-bind /dev/shm /dev/shm \
--tmpfs /sys \
--ro-bind /sys/dev/char /sys/dev/char \
--ro-bind /sys/devices /sys/devices \
--proc /proc \
--dir /sandbox \
--bind /tmp /tmp \
--bind /usr /usr \
--ro-bind /etc /etc \
--ro-bind-try /lib /lib \
--ro-bind-try /lib64 /lib64 \
--ro-bind-try /bin /bin \
--ro-bind-try /sbin /sbin \
--ro-bind-try /opt /opt \
--bind "${busDir}/bus" "${XDG_RUNTIME_DIR}/bus" \
--ro-bind "${XDG_RUNTIME_DIR}/pulse" \
"${XDG_RUNTIME_DIR}/pulse" \
--bind "${XDG_DATA_HOME}"/WeChat_Data "${HOME}" \
--ro-bind-try "${XAUTHORITYpath}" "${XAUTHORITYpath}" \
--unshare-all \
--share-net \
--unshare-user \
--disable-userns \
--ro-bind /usr/lib/wechat-uos-qt/open \
/sandbox/dde-file-manager \
--ro-bind /usr/share/wechat-uos-qt/license/var/ /var/ \
--ro-bind /usr/share/wechat-uos-qt/license/etc/os-release \
"${osRel}" \
--ro-bind /usr/share/wechat-uos-qt/license/etc/lsb-release \
/etc/lsb-release \
--ro-bind /usr/lib/wechat-uos-qt/user-dirs.dirs \
"${XDG_CONFIG_HOME}"/user-dirs.dirs \
--ro-bind-try "${XDG_CONFIG_HOME}"/fontconfig \
"${XDG_CONFIG_HOME}"/fontconfig \
--ro-bind-try "${XDG_DATA_HOME}/fonts" \
"${XDG_DATA_HOME}/fonts" \
--ro-bind-try "${XDG_CONFIG_HOME}"/Trolltech.conf \
"${XDG_CONFIG_HOME}"/Trolltech.conf \
--ro-bind-try "${XDG_CONFIG_HOME}"/mimeapps.list \
"${XDG_CONFIG_HOME}"/mimeapps.list \
--ro-bind-try "${XDG_CONFIG_HOME}"/kdeglobals \
"${XDG_CONFIG_HOME}"/kdeglobals \
--ro-bind-try "${XDG_DATA_HOME}"/WeChat_Data/.flatpak-info \
"${XDG_RUNTIME_DIR}/.flatpak-info" \
--ro-bind-try "${XDG_DATA_HOME}"/WeChat_Data/.flatpak-info \
/.flatpak-info \
--ro-bind-try "/run/systemd/resolve/stub-resolv.conf" \
"/run/systemd/resolve/stub-resolv.conf" \
--dir "${XDG_DOCUMENTS_DIR}" \
${bwCamPar} \
--setenv XDG_DOCUMENTS_DIR "${XDG_DOCUMENTS_DIR}" \
--setenv XDG_DATA_HOME "${XDG_DATA_HOME}" \
-- \
"${launchTarget}"
}
function warnMulRunning() {
if [[ "${LANG}" =~ 'zh_CN' ]]; then
zenity --title "微信正在运行" --icon=utilities-system-monitor-symbolic --default-cancel --question --text="是否结束正在运行的进程?"
else
zenity --title "WeChat is running" --icon=utilities-system-monitor-symbolic --default-cancel --question --text="Do you wish to terminate the running session?"
fi
if [ $? = 0 ]; then
systemctl --user stop $@
else
echo "[Critical] User denied session termination"
exit 114
fi
}
function dbusProxy() {
if [[ $(systemctl --user is-failed wechat-dbus-proxy.service) = failed ]]; then
echo "[Warning] D-Bus proxy failed last time"
systemctl --user reset-failed wechat-dbus-proxy.service
fi
if [[ $(systemctl --user is-active wechat-dbus-proxy.service) = active ]]; then
echo "[Warning] Existing D-Bus proxy detected! Terminating..."
systemctl --user kill wechat-dbus-proxy.service
fi
rm "${busDir}" -r
mkdir "${busDir}" -p
echo "Starting D-Bus Proxy @ ${busDir}..."
systemd-run --user -u wechat-dbus-proxy \
env -i xdg-dbus-proxy \
"${DBUS_SESSION_BUS_ADDRESS}" \
"${busDir}/bus" \
--log \
--call=org.freedesktop.portal.Desktop=*=* \
--broadcast=org.freedesktop.portal.*=@/org/freedesktop/portal/*
}
function execAppUnsafe() {
killall wechat
systemd-run --user \
-p EnvironmentFile=/usr/lib/wechat-uos-qt/envs \
--tty \
bwrap \
--dev-bind / / \
--bind /opt/wechat-uos-qt/files \
/usr/lib/license \
--ro-bind /usr/share/wechat-uos-qt/license/var/ \
/var/ \
--ro-bind /usr/share/wechat-uos-qt/license/etc/os-release \
"${osRel}" \
--ro-bind /usr/share/wechat-uos-qt/license/etc/lsb-release \
/etc/lsb-release \
--setenv QT_QPA_PLATFORM xcb \
--setenv LD_LIBRARY_PATH /opt/wechat-uos-qt/files:/usr/lib/wechat-uos-qt/so:/usr/lib/wechat-uos-qt/so \
--setenv QT_AUTO_SCREEN_SCALE_FACTOR 1 \
--setenv PATH /sandbox:"${PATH}" \
--setenv QT_PLUGIN_PATH "/usr/lib/qt/plugins /opt/wechat-uos-qt/files/wechat" \
"${launchTarget}"
}
function disableSandbox() {
if [[ $@ =~ "f5aaebc6-0014-4d30-beba-72bce57e0650" ]] && [[ $@ =~ "--actions" ]]; then
if [[ "${LANG}" =~ 'zh_CN' ]]; then
zenity --title "稍等片刻..." --icon=security-medium-symbolic --default-cancel --question --text="允许微信读取 / 修改所有个人数据?"
else
zenity --title "Hold on..." --icon=security-medium-symbolic --default-cancel --question --text="Do you wish WeChat to access and modify all of your data?"
fi
if [[ $? = 0 ]]; then
export trashAppUnsafe=1
if [[ "${LANG}" =~ 'zh_CN' ]]; then
zenity --error --title "沙盒已禁用" --icon=security-low-symbolic --text "用户数据不再被保护"
else
zenity --error --title "Sandbox disabled" --icon=security-low-symbolic --text "User data is potentially compromised"
fi
else
echo "[Critical] Request canceled by user"
exit 1
fi
fi
if [[ ${wechatUnsafe} = 1 ]]; then
export trashAppUnsafe=1
fi
}
function openDataDir() {
if [[ $@ =~ "--actions" ]] && [[ $@ =~ "opendir" ]]; then
xdg-open "${XDG_DATA_HOME}"/WeChat_Data
exit $?
fi
}
function launch() {
detectXauth
inputMethod
moeDect
#lnDir
if [[ $@ =~ "--actions" ]] && [[ $@ =~ "debug-shell" ]]; then
launchTarget="/usr/bin/bash"
else
launchTarget="/opt/wechat-uos-qt/files/wechat"
fi
if [[ $@ =~ "--actions" ]] && [[ $@ =~ "disconnect-tty" ]]; then
sdOption="-P"
else
sdOption="-t"
fi
if [[ ${trashAppUnsafe} = 1 ]]; then
echo "Launching WeChat UOS (unsafe)..."
execAppUnsafe
else
dbusProxy
echo "Launching WeChat UOS..."
execApp
fi
}
function stopApp() {
systemctl --user stop wechat-dbus-proxy.service wechat-uos-qt.service
}
if [[ $@ = "--actions quit" ]]; then
stopApp $@
exit $?
fi
disableSandbox $@
sourceXDG
openDataDir $@
manageDirs
launch $@
|