remove ia64 keywords
[gentoo-zh.git] / net-im / tencent-qq / files / start.sh
blobfe3a720c81f7a19a447fd4e21bb711864aff5f33
1 #!/bin/bash
3 QQ_HOTUPDATE_VERSION="__CURRENT_VER__"
5 function command_exists() {
6 local command="$1"
7 command -v "${command}" >/dev/null 2>&1
10 function show_error_dialog() {
11 title="linuxqq-nt-bwrap"
12 if command_exists kdialog; then
13 kdialog --error "$1" --title "$title" --icon qq
14 elif command_exists zenity; then
15 zenity --error --title "$title" --icon-name qq --text "$1"
16 else
17 all_off="$(tput sgr0)"
18 bold="${all_off}$(tput bold)"
19 blue="${bold}$(tput setaf 4)"
20 yellow="${bold}$(tput setaf 3)"
21 printf "${blue}==>${yellow} ${bold} $1${all_off}\n"
25 # 进行必要文件的检查
26 if [ ! -e "/etc/localtime" ]; then
27 show_error_dialog "/etc/localtime 未找到。\n请先设置系统时区。"
28 exit 1
31 USER_RUN_DIR="/run/user/$(id -u)"
32 XAUTHORITY="${XAUTHORITY:-$HOME/.Xauthority}"
33 XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
34 FONTCONFIG_HOME="${XDG_CONFIG_HOME}/fontconfig"
35 QQ_APP_DIR="${XDG_CONFIG_HOME}/QQ"
36 if [ -z "${QQ_DOWNLOAD_DIR}" ]; then
37 if [ -z "${XDG_DOWNLOAD_DIR}" ]; then
38 XDG_DOWNLOAD_DIR="$(xdg-user-dir DOWNLOAD)"
40 QQ_DOWNLOAD_DIR="${XDG_DOWNLOAD_DIR:-$HOME/Downloads}"
43 # 从 flags 文件中加载参数
45 set -euo pipefail
46 flags_file="${XDG_CONFIG_HOME}/qq-electron-flags.conf"
47 declare -a flags
49 if [[ -f "${flags_file}" ]]; then
50 mapfile -t <"${flags_file}"
53 for line in "${MAPFILE[@]}"; do
54 if [[ ! "${line}" =~ ^[[:space:]]*#.* ]]; then
55 flags+=("${line}")
57 done
59 QQ_HOTUPDATE_DIR="${QQ_APP_DIR}/versions"
61 # 在「下载」目录不存在的时候,自动使用 ~/Downloads
62 # 避免挂载整个 home
63 if [ "${QQ_DOWNLOAD_DIR%*/}" == "${HOME}" ]; then
64 QQ_DOWNLOAD_DIR="${HOME}/Downloads"
67 # 安装当前版本
68 HOTUPDATE_VERSION_DIR="${QQ_HOTUPDATE_DIR}/${QQ_HOTUPDATE_VERSION}"
69 install -d "${QQ_HOTUPDATE_DIR}"
70 if [ ! -d "${HOTUPDATE_VERSION_DIR}" ] && [ ! -L "${HOTUPDATE_VERSION_DIR}" ]; then
71 ln -sfd "/opt/QQ/resources/app" "${HOTUPDATE_VERSION_DIR}"
74 # 处理旧版本
75 rm -rf "${QQ_HOTUPDATE_DIR}/"**".zip"
76 is_hotupdated_version=0 # 正在运行的版本是否经过热更新?
78 find "${QQ_HOTUPDATE_DIR}/"*[-_]* -maxdepth 1 -type "d,l" | while read path; do
79 this_version="$(basename "$path")"
80 if [ "$(/opt/QQ/workarounds/vercmp.sh "${this_version}" lt "${QQ_HOTUPDATE_VERSION//_/-}")" == "true" ]; then
81 # 这个版本小于当前版本,删除之
82 echo "rm $this_version"
83 rm -rf "$path"
84 else
85 is_hotupdated_version=1
87 done
89 if [ "$is_hotupdated_version" == "0" ]; then
90 cp "/opt/QQ/workarounds/config.json" "${QQ_HOTUPDATE_DIR}/config.json"
93 bwrap --new-session --cap-drop ALL --unshare-user-try --unshare-pid --unshare-cgroup-try \
94 --ro-bind /lib /lib \
95 --ro-bind /lib64 /lib64 \
96 --ro-bind /bin /bin \
97 --ro-bind /usr /usr \
98 --ro-bind /opt /opt \
99 --ro-bind /opt/QQ/workarounds/xdg-open.sh /usr/bin/xdg-open \
100 --ro-bind /usr/lib/snapd-xdg-open/xdg-open /snapd-xdg-open \
101 --ro-bind /usr/lib/flatpak-xdg-utils/xdg-open /flatpak-xdg-open \
102 --ro-bind /etc/machine-id /etc/machine-id \
103 --ro-bind /etc/ld.so.cache /etc/ld.so.cache \
104 --dev-bind /dev /dev \
105 --ro-bind /sys /sys \
106 --ro-bind /etc/passwd /etc/passwd \
107 --ro-bind /etc/nsswitch.conf /etc/nsswitch.conf \
108 --ro-bind-try /run/systemd/userdb /run/systemd/userdb \
109 --ro-bind /etc/resolv.conf /etc/resolv.conf \
110 --ro-bind /etc/localtime /etc/localtime \
111 --proc /proc \
112 --dev-bind /run/dbus /run/dbus \
113 --bind "${USER_RUN_DIR}" "${USER_RUN_DIR}" \
114 --ro-bind-try /etc/fonts /etc/fonts \
115 --dev-bind /tmp /tmp \
116 --bind-try "${HOME}/.pki" "${HOME}/.pki" \
117 --ro-bind-try "${XAUTHORITY}" "${XAUTHORITY}" \
118 --bind-try "${QQ_DOWNLOAD_DIR}" "${QQ_DOWNLOAD_DIR}" \
119 --setenv QQ_APP_DIR "${QQ_APP_DIR}" \
120 --bind "${QQ_APP_DIR}" "${QQ_APP_DIR}" \
121 --ro-bind-try "${FONTCONFIG_HOME}" "${FONTCONFIG_HOME}" \
122 --ro-bind-try "${HOME}/.icons" "${HOME}/.icons" \
123 --ro-bind-try "${HOME}/.local/share/.icons" "${HOME}/.local/share/.icons" \
124 --ro-bind-try "${XDG_CONFIG_HOME}/gtk-3.0" "${XDG_CONFIG_HOME}/gtk-3.0" \
125 --ro-bind /etc/nsswitch.conf /etc/nsswitch.conf \
126 --ro-bind-try /run/systemd/userdb/ /run/systemd/userdb/ \
127 --setenv IBUS_USE_PORTAL 1 \
128 --setenv QQNTIM_HOME "${QQ_APP_DIR}/QQNTim" \
129 --setenv LITELOADERQQNT_PROFILE "${QQ_APP_DIR}/LiteLoaderQQNT" \
130 /opt/QQ/qq "${flags[@]}" "$@"
132 # 移除无用崩溃报告和日志
133 # 如果需要向腾讯反馈 bug,请注释掉如下几行
134 rm -rf ${QQ_APP_DIR}/crash_files
135 touch ${QQ_APP_DIR}/crash_files
136 if [ -d "${QQ_APP_DIR}/log" ]; then
137 rm -rf "${QQ_APP_DIR}/log"
139 for nt_qq_userdata in "${QQ_APP_DIR}/nt_qq_"*; do
140 if [ -d "${nt_qq_userdata}/log" ]; then
141 rm -rf "${nt_qq_userdata}/log"
143 if [ -d "${nt_qq_userdata}/log-cache" ]; then
144 rm -rf "${nt_qq_userdata}/log-cache"
146 done
147 if [ -d "${QQ_APP_DIR}/Crashpad" ]; then
148 rm -rf "${QQ_APP_DIR}/Crashpad"