summarylogtreecommitdiffstats
path: root/wps-bwrap
blob: cc5671f8d90541fcb4d22c58ae30623f022cb6f0 (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
#!/bin/bash

# 根据扩展名选择对应的 WPS 程序
file=$1
case $file in
    *.doc | *.docx) exe=/usr/bin/wps ;;
    *.xls | *.xlsx) exe=/usr/bin/et ;;
    *.ppt | *.pptx) exe=/usr/bin/wpp ;;
    *.pdf) exe=/usr/bin/wpspdf ;;
    *) exe=/usr/bin/wps ;;
esac

binds=()
for dir in fontconfig gtk-2.0 gtk-3.0 gtk-4.0 kingsoft Kingsoft; do
    if [ ! -d ~/.config/"$dir" ]; then mkdir ~/.config/"$dir"; fi
    binds+=(--bind ~/.config/"$dir" ~/.config/"$dir")
done
binds+=(--bind ~/.config/mimeapps.list ~/.config/mimeapps.list)
binds+=(--bind ~/.local/share/Kingsoft ~/.local/share/Kingsoft)
DOC_DIR=$(xdg-user-dir DOCUMENTS)
binds+=(--bind $DOC_DIR $DOC_DIR)

# bind mount 需要操作的文件
if [[ -f "$file" ]]; then
    path="$(realpath "$file")"
    binds+=(--bind "$path" "$path")
fi

exec bwrap --unshare-all --share-net --die-with-parent \
    --ro-bind / / \
    --tmpfs /sys --tmpfs /home --tmpfs /tmp --tmpfs /run --proc /proc --dev /dev \
    --ro-bind "$XDG_RUNTIME_DIR" "$XDG_RUNTIME_DIR" \
    --ro-bind /tmp/.X11-unix /tmp/.X11-unix \
    "${binds[@]}" \
    "$exe" "$@"