本文使用 Fcitx 4 + 搜狗拼音 4.2.1.145。管理员准备 RPM、系统依赖和 ETX Profile;每位普通用户在自己的桌面终端中执行一次:
1
bash /tools/OSS/sogou/4.2.1.145/bin/sogou-fcitx-init.sh
然后 Terminate 当前 ETX 桌面,再新建一个会话。后续启动同一家目录的 XFCE 桌面时,会自动启动 Fcitx 和搜狗。关闭 ETX 客户端窗口通常只是断开连接,不能代替终止并新建会话。
本方案使用普通 XFCE Terminal,不需要 Sogou modulefile、专用 terminal server,也不需要在 Xstart 中调用搜狗的 session init。新桌面的应用环境由 Xstart 统一设置;输入法由个人 XFCE 自动启动项启动。
本文的初始化命令针对下面准备的 -14 站点 RPM。2026-11-05 检查时,实验环境的 /tools/OSS/sogou/4.2.1.145 仍是以前部署的内容,该目录下尚无 bin/sogou-fcitx-init.sh;仅构建 -14 RPM 不会自动将它部署到共享目录。132 的 EL9 输入验证使用了现有目录和隔离测试配置,没有覆盖这份 NFS 共享目录。
环境和交付文件
| 项目 | 本文采用的配置 |
|---|---|
| RPM 目标平台 | EL8 x86_64;本次在 122 的 Rocky Linux 8.10 构建、测试 |
| 输入法 | 系统 Fcitx 4 + 搜狗拼音 4.2.1.145 |
| RPM | sogoupinyin-site-4.2.1.145-14.el8.x86_64.rpm |
| 默认安装前缀 | /tools/OSS/sogou/4.2.1.145 |
| 生产环境前缀示例 | /sdata/tools/opensrc/sogou/4.2.1.145 |
| 用户初始化入口 | <安装前缀>/bin/sogou-fcitx-init.sh |
| 桌面环境 | ETX、XFCE、X11、en_US.UTF-8 |
| 家目录 | 可以通过 NFS 共享;各节点仍需安装匹配的运行依赖 |
搜狗官方发布的是 Ubuntu DEB;本文根据该文件制作站点自用 RPM,并非搜狗官方的 RHEL RPM。搜狗 Linux 安装指南提供官方安装信息。本文软件包面向 EL8;132 当前是 Rocky Linux 9.7,若要在其本机桌面启动输入法,应准备兼容 EL9 的 Fcitx 和搜狗运行环境。仅在 132 启动远端应用、通过 XIM 使用 122 的桌面输入法,不要求在 132 再运行搜狗。
交付文件:
本次 RPM 和构建文件包保存在内部共享目录:
1
2
/tools/OSS/sogou/packages/sogoupinyin-site-4.2.1.145-14.el8.x86_64.rpm
/tools/OSS/sogou/packages/sogoupinyin-site-4.2.1.145-14-build-files.tar.gz
RPM 的 SHA-256:
1
436e58fab5713af2a656ff9e441c3ed130862803a251d08918f8cf4091a96c93
一、管理员从官方 DEB 构建 RPM
1. 准备构建工具和输入文件
在 EL8 x86_64 构建机准备工具:
1
sudo dnf install rpm-build binutils tar xz patchelf
构建不需要先安装旧的站点搜狗包,也不需要在构建机复制一套系统 Fcitx 目录。准备自行从搜狗官网下载的 sogoupinyin_4.2.1.145_amd64.deb;本文使用的 DEB SHA-256 是:
1
3111af17a6abddd80b856aa9c1f579a137d69f3d735ead936ddb6e5f08b59f3b
构建包目录结构:
1
2
3
4
sogou-site/
├── build.sh
├── sogoupinyin-site.spec
└── sogou-fcitx-init.sh
2. 一次构建
使用普通构建用户执行:
1
2
3
tar -xzf sogoupinyin-site-4.2.1.145-14-build-files.tar.gz
cd sogou-site
bash ./build.sh /path/to/sogoupinyin_4.2.1.145_amd64.deb
输出:
1
dist/sogoupinyin-site-4.2.1.145-14.el8.x86_64.rpm
build.sh 校验 DEB 哈希和脚本语法,建立临时 rpmbuild 目录,然后调用 rpmbuild -ba。DEB 只在 spec 的 %prep 中解包一次;构建过程不执行 DEB 的安装脚本。原始 DEB 不包含在构建文件包内,需单独准备。
3. 包内保留什么
| 路径 | 用途 |
|---|---|
bin/sogou-fcitx-init.sh |
唯一的站点用户初始化入口 |
files/ |
搜狗程序及资源 |
usr/lib/fcitx/fcitx-sogoupinyin.so |
搜狗拼音插件 |
usr/share/fcitx/ |
插件、输入法描述和图标 |
usr/share/icons/ |
搜狗图标 |
spec 将 DEB 的 /opt/sogoupinyin/files 整理到安装前缀的 files/,使用系统 Qt 和 Fcitx 库,保留程序需要的 libgsettings-qt.so.1。主插件设置 RPATH,使其在用户启动器提供的 /opt/sogoupinyin 映射中找到搜狗库。
包内不复制系统 Fcitx 可执行文件,不生成系统 Fcitx 文件的软链接树,不包含独立的 XFCE init、自动启动模板、modulefile 或终端 helper。手写识别插件未包含在此拼音输入方案中。
完整 spec 和初始化脚本放在文末,构建文件包中的内容与其一致。
二、管理员安装依赖和 RPM
先启用站点认可的 EL8 软件仓库(含所需的 EPEL 8 包),在每台运行本机桌面输入法的节点安装依赖:
1
2
3
4
5
sudo dnf install \
fcitx fcitx-libs fcitx-data fcitx-gtk2 fcitx-gtk3 fcitx-qt5 \
qt5-qtsvg qt5-qtdeclarative bubblewrap coreutils procps-ng util-linux \
bash gawk grep sed dbus-daemon psmisc glibc-langpack-en \
google-noto-sans-cjk-ttc-fonts libcurl libpng12 openal-soft openblas
bubblewrap 必须允许普通用户运行。XFCE 桌面及其终端由站点的桌面环境部署提供。
安装到默认的完整版本目录:
1
2
sudo rpm -Uvh --prefix /tools/OSS/sogou/4.2.1.145 \
/tools/OSS/sogou/packages/sogoupinyin-site-4.2.1.145-14.el8.x86_64.rpm
生产环境安装示例:
1
2
sudo rpm -Uvh --prefix /sdata/tools/opensrc/sogou/4.2.1.145 \
/path/to/sogoupinyin-site-4.2.1.145-14.el8.x86_64.rpm
--prefix 指定的是完整版本目录。初始化脚本根据自身位置识别安装根目录,因此无需修改脚本内的 /tools 路径。RPM 安装不代替用户运行初始化,也不以 root 身份写入用户家目录。
如果系统重装后 RPM 数据库已丢失,而 NFS 中仍有旧版本目录,RPM 无法自动识别、清理其中未登记的旧文件。应安排共享使用者退出,备份旧目录,在干净的目标目录部署。不同操作系统版本应使用兼容的运行环境和版本目录。
三、管理员配置 ETX Profile 的 Xstart
在 ETX Profile 中设置以下 Xstart Command:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash
env -i /bin/sh -c "
export LANG=en_US.UTF-8;
export PATH=$PATH;
export XAUTHORITY=$XAUTHORITY;
export DISPLAY=$DISPLAY;
export HOME=$HOME;
export LOGNAME=$LOGNAME;
export USER=$USER;
export XMODIFIERS=@@im=fcitx;
export QT_IM_MODULE=fcitx;
export GTK_IM_MODULE=fcitx;
exec /usr/bin/xfce4-session
"
这里的 @@ 是本文 ETX Xstart 配置中用于得到字面量 @ 的写法。桌面进程实际获得的必须是 XMODIFIERS=@im=fcitx。在普通 Linux 脚本或终端中直接设置时应使用单个 @。
三个变量在 XFCE 启动前设置,因此桌面右键 Open Terminal Here 打开的终端,以及 Firefox 等桌面应用都能继承它们。无需在 .cshrc 里设置,也无需在 Xstart 中调用用户初始化脚本。
四、普通用户只初始化一次
1. 执行脚本,然后新建桌面
用户在 ETX 桌面本机的终端中执行;不要先 SSH/bsub 到另一台机器:
1
bash /tools/OSS/sogou/4.2.1.145/bin/sogou-fcitx-init.sh
生产环境对应:
1
bash /sdata/tools/opensrc/sogou/4.2.1.145/bin/sogou-fcitx-init.sh
初始化前请结束该用户其他正在使用同一家目录的输入法桌面,保留当前桌面用于配置,避免其他会话随后写回旧的 profile。脚本会停止当前 DISPLAY 上的 Fcitx,再修改配置;不会按用户名结束所有桌面的输入法进程。
脚本完成后,Terminate 当前 ETX session,再启动一个新的 session。用户以后只需正常新建桌面,不必重复执行脚本。如果只配置、暂不启动当前桌面的输入法,可以添加 --no-start。
2. 脚本准备的个人文件
| 文件 | 用途 |
|---|---|
~/.config/fcitx/addon/fcitx-sogoupinyin.conf |
指向共享安装目录的插件描述 |
~/.config/fcitx/inputmethod/sogoupinyin.conf |
指向搜狗输入法描述 |
~/.config/fcitx/lib/fcitx-sogoupinyin.so |
指向搜狗主插件 |
~/.config/fcitx/profile |
保留已有输入法条目,加入并启用 sogoupinyin |
~/.local/bin/fcitx-sogou |
Fcitx 启动器,提供搜狗所需的私有 /opt/sogoupinyin 映射 |
~/.config/autostart/fcitx.desktop |
XFCE 自动启动项 |
~/.cache/fcitx-sogou.log |
输入法启动日志 |
表中配置和缓存目录支持对应的 XDG_CONFIG_HOME、XDG_CACHE_HOME;未设置时采用表中的默认目录。本文 Xstart 的 env -i 不传入这些 XDG 覆盖变量,通常使用默认目录。
为防止普通 Fcitx 被其他启动项抢先启动,脚本会在用户目录中覆盖已有的 imsettings/Fcitx/旧搜狗自动启动入口,并保留原配置备份。系统的 /etc/xdg/autostart 不会被修改。本流程由个人 fcitx.desktop 负责启动,不再需要另外执行 imsettings-switch fcitx。
本方案通过 Fcitx 的个人插件目录加载搜狗,继续使用系统 Fcitx 的其他组件,不需要用户维护 FCITXDIR;生成的启动器会清除残留的 FCITXDIR。bubblewrap 提供的路径映射只属于输入法进程,不会在系统全局创建 /opt/sogoupinyin 链接。
搜狗自己的个人配置和词库,例如 ~/.config/sogoupinyin,由搜狗首次运行时生成;它们与 ~/.config/fcitx/profile 是不同层次的配置。脚本不会删除或共享用户个人词库。
家目录通过 NFS 共享时,用户初始化一次即可供读取相同配置的 XFCE 会话使用;每台桌面节点仍须能访问安装目录,并具有匹配的 Fcitx、库、locale 和字体。
3. 验证和常用命令
在新桌面的终端检查:
1
printenv GTK_IM_MODULE QT_IM_MODULE XMODIFIERS
期望依次输出:
1
2
3
fcitx
fcitx
@im=fcitx
查看当前桌面的状态:
1
bash /tools/OSS/sogou/4.2.1.145/bin/sogou-fcitx-init.sh status
再在终端、Firefox 等应用中切换到搜狗,输入拼音、查看候选词并提交中文。插件注册成功与实际能够输入中文是两个验证环节。
其他维护命令:
1
2
3
4
5
# Stop input-method processes belonging to the current DISPLAY.
bash /tools/OSS/sogou/4.2.1.145/bin/sogou-fcitx-init.sh stop
# Remove managed user setup and restore saved startup/profile files.
bash /tools/OSS/sogou/4.2.1.145/bin/sogou-fcitx-init.sh uninstall
uninstall 不卸载共享 RPM,也不删除搜狗个人词库。恢复自动启动配置后,需要重新新建桌面。
4. 本次验证范围
本包在 122 的 Rocky Linux 8.10 上,以非 root 用户、隔离家目录、Xvfb 和真实 xfce4-session 验证了:
- 安装到不同于默认目录的完整 RPM 前缀,脚本仍能自动找到资源。
- 空家目录初始化、新建 XFCE 后自动启动 Fcitx 和搜狗。
- 保留已有的其他输入法条目,重复初始化不破坏首次备份。
- 在 GTK 输入框输入
zhongwen、选择候选词,最终提交内容为中文。 - 初始化、停止、卸载不会结束同一用户另一个 DISPLAY 上的 Fcitx。
- 卸载用户配置后恢复原有
profile和自动启动项。
这些是隔离 XFCE 的实测结果;安装到正式路径后仍应在实际 ETX 新会话中验证桌面应用。本文没有把 EL8 RPM 作为 EL9 桌面的兼容验证结果。
五、从桌面 SSH 到远端使用 VS Code
1. 先区分远端 shell 和远端图形程序
在 122 的终端输入中文后通过 SSH 送到 132 的 shell,输入法窗口仍属于 122 上的终端。132 的 shell 需要合适的 UTF-8 locale,但不需要仅为了接收这些字符而启动自己的搜狗或 Fcitx。
从 132 启动并显示到 122 的 VS Code 是远端图形程序。它需要可用的 X11 显示连接和授权;单独传递输入法变量不能建立 X11 连接。本环境中,远端 VS Code 通过 XIM 使用 122 桌面的 Fcitx:
1
env GTK_IM_MODULE=xim QT_IM_MODULE=xim XMODIFIERS=@im=fcitx code
需要先确保远端 code 可执行文件已在 PATH。若 VS Code 复用先前实例,可能继续使用旧环境;应在保存工作后关闭相关旧实例,或用隔离的用户数据目录验证。
2. SSH 传递 XMODIFIERS
本环境在 122 的 /etc/ssh/ssh_config 增加:
1
SendEnv XMODIFIERS
在需要接收该变量的远端 /etc/ssh/sshd_config 增加:
1
AcceptEnv XMODIFIERS
应与现有配置合并,服务端修改后先运行 sshd -t,再按站点方式重新加载 SSH 服务。建立新的 SSH 连接后检查 DISPLAY 和 XMODIFIERS;如果依赖 SSH X11 forwarding,需要同时启用并验证转发及授权。桌面选用 Fcitx 时,预期 XMODIFIERS=@im=fcitx。
3. VS Code modulefile 的 SSH 与 LSF 判断
如果希望通过 VS Code 的 modulefile 自动设置远端 XIM,本环境使用过以下 alias。这里是 VS Code modulefile,不是 Sogou modulefile:
1
set-alias code {sh -c 'if test -n "$LSB_JOBID" && test -n "$GTK_IM_MODULE" && test -n "$QT_IM_MODULE" && test -n "$XMODIFIERS"; then export GTK_IM_MODULE=xim QT_IM_MODULE=xim; elif test -n "$SSH_CONNECTION"; then case "$XMODIFIERS" in @im=fcitx|@im=ibus) export GTK_IM_MODULE=xim QT_IM_MODULE=xim;; esac; fi; exec code "$@"' sh}
SSH 分支按 XMODIFIERS 判断;LSF 分支要求 LSB_JOBID、GTK_IM_MODULE、QT_IM_MODULE、XMODIFIERS 均非空,并保留 XMODIFIERS。是否将变量、显示连接和 X11 授权传入 LSF 作业取决于站点配置;执行 code 的远端 shell 也必须加载该 VS Code modulefile。上述 alias 未处理 Slurm 的 SLURM_JOB_ID。本例已测试 alias 的模拟分支,真实 LSF 图形作业仍需在站点验证。
六、此前调试记录
1. 远端 VS Code 选词后崩溃
此前从 122 SSH 到 132:远端 shell 中文正常,VS Code 也能显示搜狗候选词,但提交候选词时桌面 Fcitx 退出、VS Code 卡住。崩溃堆栈包含 fcitx-xim.so 和 XFree;当时桌面使用 C.utf8。
在 122 的隔离 Xlib 对照测试中,C.utf8 的 XSupportsLocale() 返回 0,中文转换返回 -2;en_US.UTF-8 分别返回 1 和 0。这支持 locale 与该故障有关,但不足以证明它是唯一原因。改用 en_US.UTF-8 并新建 ETX 会话后,用户验证了 132 上的 VS Code 可以通过搜狗输入中文。本方案由 ETX Profile 的 Xstart 设置桌面的 LANG=en_US.UTF-8,输入法启动器也使用 en_US.UTF-8。
2. 132 节点的后续配置
以下是 132 的历史操作记录,不代表本次重装后的当前配置,也不是从 122 远端启动 VS Code 的必需安装步骤:
- ETX 客户端曾因
rd-172-31-0-132.lab.icinfra.ltd的客户端解析路径异常,提示无法协商 Proxy Manager。针对当时客户端可直连的环境,在 ETX 节点的 Alternative node addresses → For client 设置172.31.0.132后,132 桌面可以打开;这没有修复 DNS 本身。 - 域账号的登录 shell 是
/bin/csh,但新系统缺少tcsh,终端回退到sh。安装tcsh并检查/bin/csh后,验证了该用户可以执行/bin/csh;新终端实际采用的 shell 还应在新会话中确认。 - 为 132 的 Rocky Linux 9.7 本机桌面曾单独构建 Fcitx 4 和 EL9 搜狗 RPM,材料位于
/opt/sogou-build-el9/。早期隔离测试发现过fcitx-sogoupinyinhxmABI 错误;后续用户反馈 132 桌面终端可以使用搜狗。应以该节点当前实际安装和新会话测试为准,不能用 122 的 EL8 RPM 代替 EL9 构建。
通过 122 的桌面输入法、以 XIM 在 132 启动远端 VS Code,与在 132 本机桌面安装输入法是两条不同的使用路径。
七、在 EL9 上重建 Fcitx 4 RPM
Rocky Linux 9 的常用仓库没有本文需要的 Fcitx 4 套件。不要将 EL8 的 Fcitx 二进制 RPM 强行安装到 EL9:两者的系统库和 Qt 私有接口可能不同。下面使用 EPEL 8 的 Fcitx 4 源码 RPM,在 EL9 构建环境重新编译,再在 EL9 安装产物。源码来自 Fedora EPEL:
| 源码 RPM | 用途 |
|---|---|
fcitx-4.2.9.7-3.el8.src.rpm |
Fcitx 4 主程序、数据、GTK 模块和开发文件 |
fcitx-qt5-1.2.4-5.el8.src.rpm |
Fcitx 的 Qt 5 输入法模块 |
这里将编译器和大量开发依赖限制在 Rocky Linux 9 容器中。安装在 132 上的是构建出的 EL9 二进制 RPM,不是容器,也不是 EL8 二进制 RPM;搜狗程序仍使用已存在的共享安装目录。下面的命令由构建节点的管理员执行,容器必须能访问已启用的 Rocky BaseOS、AppStream、CRB 和 EPEL 仓库。
1. 下载并验证源码
在 EL9 x86_64 构建机上安装 Podman、curl、GnuPG 和 RPM 工具。本文 132 的工作目录是 /var/tmp/fcitx4-el9-rebuild-20261105;以下命令以 root 执行:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
dnf install -y podman curl gnupg2 rpm
build=/var/tmp/fcitx4-el9-rebuild-20261105
mkdir -p "$build"/{srpms,rpmdb,rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}}
for name in fcitx-4.2.9.7-3.el8.src.rpm fcitx-qt5-1.2.4-5.el8.src.rpm; do
curl -fL -o "$build/srpms/$name" \
"https://mirrors.huaweicloud.com/epel/8/Everything/SRPMS/Packages/f/$name"
done
curl -fL -o "$build/RPM-GPG-KEY-EPEL-8" \
https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-8
# Inspect the key before trusting it in the isolated verification database.
gpg --show-keys --with-fingerprint "$build/RPM-GPG-KEY-EPEL-8"
rpm --dbpath "$build/rpmdb" --initdb
rpm --dbpath "$build/rpmdb" --import "$build/RPM-GPG-KEY-EPEL-8"
rpm --dbpath "$build/rpmdb" -Kv "$build"/srpms/*.src.rpm
sha256sum "$build"/srpms/*.src.rpm
本次 EPEL 8 公钥指纹为 94E2 79EB 8D8F 25B2 1810 ADF1 21EA 45AB 2F86 D6A1,两个源码包的签名均应显示 OK。源码哈希分别为:
1
2
ddaae752f652d6bd1b6586066b1fa10defc12e4ab3f1e0bac83732604145ddaf fcitx-4.2.9.7-3.el8.src.rpm
b5b85f2250890f901acc036212f1e3027a98c3bcb1f88062ebd064fc326e45f8 fcitx-qt5-1.2.4-5.el8.src.rpm
校验通过后解出 spec 和源码。注意,这里的 rpm -i 安装的是源码包的构建文件,并不将 Fcitx 二进制程序安装到系统中:
1
2
3
for src in "$build"/srpms/*.src.rpm; do
rpm --dbpath "$build/rpmdb" -i --define "_topdir $build/rpmbuild" "$src"
done
2. 在隔离容器中构建
创建构建脚本:
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
cat > "$build/build-in-container.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
topdir=/work/rpmbuild
fcitx_spec="$topdir/SPECS/fcitx.spec"
qt_spec="$topdir/SPECS/fcitx-qt5.spec"
dnf -y install epel-release dnf-plugins-core
dnf config-manager --set-enabled crb
dnf -y install rpm-build
# Disable the obsolete Qt4 branch on EL9, just as for EL8.
sed -i 's/%if 0%{?el8}/%if 0%{?rhel} >= 8/' "$fcitx_spec"
# The EL8 spec enters its own build directory. Use direct CMake invocation
# to avoid the changed working-directory behavior of the EL9 %cmake macro.
sed -i 's|%cmake \.\.|cmake -DCMAKE_INSTALL_PREFIX=%{_prefix} -DLIB_INSTALL_DIR=%{_libdir} -DSYSCONF_INSTALL_DIR=%{_sysconfdir} ..|' "$fcitx_spec"
sed -i 's|%cmake \.\.|cmake -DCMAKE_INSTALL_PREFIX=%{_prefix} -DLIB_INSTALL_DIR=%{_libdir} ..|' "$qt_spec"
if ! compgen -G "$topdir/RPMS/x86_64/fcitx-4*.rpm" >/dev/null; then
dnf -y install enchant-devel
dnf -y builddep "$fcitx_spec"
rpmbuild -bb --define "_topdir $topdir" --define 'debug_package %{nil}' "$fcitx_spec"
fi
# fcitx-qt5 needs fcitx-devel. Install it only inside this container.
dnf -y install "$topdir"/RPMS/x86_64/fcitx-{4*,libs-4*,devel-4*,gtk2-4*,gtk3-4*}.rpm \
"$topdir"/RPMS/noarch/fcitx-data-4*.rpm
dnf -y builddep "$qt_spec"
rpmbuild -bb --define "_topdir $topdir" --define 'debug_package %{nil}' "$qt_spec"
find "$topdir/RPMS" -type f -name '*.rpm' -print | sort
EOF
启动构建;日志和 RPM 保留在宿主机工作目录。建议在站点构建仓库中固定镜像摘要及依赖版本。本次使用的镜像摘要为 sha256:d644d203142cd5b54ad2a83a203e1dee68af2229f8fe32f52a30c6e1d3c3a9e0:
1
2
3
4
5
set -o pipefail
image='docker.io/library/rockylinux@sha256:d644d203142cd5b54ad2a83a203e1dee68af2229f8fe32f52a30c6e1d3c3a9e0'
podman pull "$image"
podman run --rm --network host -v "$build:/work:Z" "$image" \
bash /work/build-in-container.sh 2>&1 | tee "$build/build.log"
set -o pipefail 使构建失败时整个管道返回非零状态。容器中安装的 fcitx-devel 只是 Qt 模块的编译依赖,不需要部署到桌面节点。脚本会复用同一工作目录中已生成的 Fcitx 主程序 RPM;重新构建不同源码时应使用新的空工作目录。构建日志和目录中的 RPM 应一并留存,站点需要签名时应按自己的 RPM 签名流程签名。
3. 安装并验证
本次构建产物、源码包、调整后的 spec、构建脚本、日志和 SHA-256 校验文件保存在共享目录:
1
2
3
4
5
6
7
8
/tools/OSS/sogou/packages/fcitx4-el9-20261105/
├── RPMS/noarch/
├── RPMS/x86_64/
├── SRPMS/
├── SPECS/
├── logs/
├── build-in-container.sh
└── SHA256SUMS
如需复制到其他 EL9 节点,也准备了整个目录的压缩包及校验文件:
1
2
/tools/OSS/sogou/packages/fcitx4-el9-20261105.tar.gz
/tools/OSS/sogou/packages/fcitx4-el9-20261105.tar.gz.sha256
将两个文件一起复制,在目标目录执行 sha256sum -c fcitx4-el9-20261105.tar.gz.sha256,通过后解压;安装命令中的 pkg 改为解压后的目录。
这些二进制 RPM 是站点构建结果,并未使用 Fedora 的签名密钥签名。将目录复制到目标 EL9 节点,确认来源、哈希和架构后,由管理员用 dnf 解析和安装运行依赖;不要使用 --nodeps。本次实验环境安装示例:
1
2
3
4
5
6
7
8
9
10
11
12
pkg=/tools/OSS/sogou/packages/fcitx4-el9-20261105
(cd "$pkg" && sha256sum -c SHA256SUMS)
dnf install -y \
"$pkg"/RPMS/noarch/fcitx-data-4*.rpm \
"$pkg"/RPMS/x86_64/fcitx-4*.rpm \
"$pkg"/RPMS/x86_64/fcitx-libs-4*.rpm \
"$pkg"/RPMS/x86_64/fcitx-gtk2-4*.rpm \
"$pkg"/RPMS/x86_64/fcitx-gtk3-4*.rpm \
"$pkg"/RPMS/x86_64/fcitx-qt5-[0-9]*.rpm
rpm -q fcitx fcitx-libs fcitx-data fcitx-gtk2 fcitx-gtk3 fcitx-qt5
fcitx --version
Fcitx 本体不是搜狗程序。目标节点还须有可访问的搜狗安装目录、适用于本机的 Qt/其他运行库、bubblewrap、UTF-8 locale 和字体;按照第三、四节设置新桌面及用户初始化,再实际输入拼音、选择候选并确认中文提交。fcitx-remote -m sogoupinyin 返回 fcitx-sogoupinyin 只能证明插件被识别,不能代替提交测试。
2026-11-05 在重装后的 Rocky Linux 9.7 节点 132 安装了上述六个运行包,rpm -V 无输出;搜狗服务、监护进程和主插件的直接动态库检查未发现缺失。使用现有共享搜狗程序和独立的 Xvfb、D-Bus 会话,在 GTK 测试输入框中分别通过 GTK_IM_MODULE=fcitx 和 GTK_IM_MODULE=xim 输入 nihao、选词,均实际提交了“你好”。
随后,在 132 已有的 ETX 桌面会话中手动启动 Fcitx 和搜狗,用户确认普通终端可以输入和提交中文。这次没有终止并新建 ETX 会话,因此不把当前终端的结果视为新会话自动启动或其他应用输入的验证。
附录:完整构建文件
以下文件与构建包一致。主流程可以直接使用下载包,不必逐段复制。
构建入口 build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env bash
set -euo pipefail
[[ $# == 1 ]] || { echo "Usage: $0 /path/to/sogoupinyin_4.2.1.145_amd64.deb" >&2; exit 2; }
source_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)
deb=$(readlink -f -- "$1")
[[ -f $deb ]] || { echo "DEB not found: $1" >&2; exit 1; }
expected=3111af17a6abddd80b856aa9c1f579a137d69f3d735ead936ddb6e5f08b59f3b
actual=$(sha256sum "$deb"); actual=${actual%% *}
[[ $actual == "$expected" ]] || { echo "Unexpected official DEB checksum: $actual" >&2; exit 1; }
for cmd in rpmbuild ar tar xz patchelf; do command -v "$cmd" >/dev/null; done
bash -n "$source_dir/sogou-fcitx-init.sh"
top=$(mktemp -d "${TMPDIR:-/var/tmp}/sogou-site-build.XXXXXXXX")
mkdir -p "$top"/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
cp -- "$deb" "$top/SOURCES/sogoupinyin-official.deb"
cp -- "$source_dir/sogou-fcitx-init.sh" "$top/SOURCES/"
cp -- "$source_dir/sogoupinyin-site.spec" "$top/SPECS/"
rpmbuild -ba --define "_topdir $top" --define 'dist .el8' "$top/SPECS/sogoupinyin-site.spec"
mkdir -p "$source_dir/dist"
cp -- "$top/RPMS/x86_64/sogoupinyin-site-4.2.1.145-14.el8.x86_64.rpm" "$source_dir/dist/"
sha256sum "$source_dir/dist/"*.rpm
printf 'Build directory: %s\n' "$top"
RPM spec
Name: sogoupinyin-site
Version: 4.2.1.145
Release: 14%{?dist}
Summary: Sogou Pinyin for Fcitx 4 with one-time per-user XFCE setup
License: Proprietary
URL: https://pinyin.sogou.com/linux/
Source0: sogoupinyin-official.deb
Source1: sogou-fcitx-init.sh
BuildArch: x86_64
BuildRequires: binutils, tar, xz, patchelf
Requires: fcitx >= 4.2.9, fcitx-libs, fcitx-data, fcitx-gtk2, fcitx-gtk3, fcitx-qt5
Requires: qt5-qtsvg, qt5-qtdeclarative, bubblewrap, coreutils, procps-ng, util-linux
Requires: bash, gawk, grep, sed, dbus-daemon, psmisc
Requires: glibc-langpack-en, google-noto-sans-cjk-ttc-fonts
Requires: libcurl, libpng12, openal-soft, openblas
AutoReqProv: no
%global debug_package %{nil}
%global __os_install_post %{nil}
%global site_root /tools/OSS/sogou/%{version}
Prefix: %{site_root}
%description
Vendor Debian payload repackaged for an EL8 x86_64 X11 desktop. System Fcitx 4
and Qt libraries are used. Each desktop user runs bin/sogou-fcitx-init.sh once,
then starts a new XFCE session. No modulefile or session init wrapper is used.
%prep
%setup -q -c -T
mkdir payload
ar p %{SOURCE0} data.tar.xz | tar -xJ -C payload
%build
%install
site="%{buildroot}%{site_root}"
mkdir -p "$site/bin" "$site/files" "$site/usr/lib/fcitx" \
"$site/usr/share/fcitx/addon" "$site/usr/share/fcitx/inputmethod"
cp -a payload/opt/sogoupinyin/files/. "$site/files/"
# These removals only affect the temporary RPM build root.
rm -rf "$site/files/lib/qt5"
rm -f "$site/files/lib/libcurl.so.4" "$site/files/lib/libpng12.so.0" \
"$site/files/lib/libFcitxQt5DBusAddons.so.1" "$site/files/lib/libopenal.so.1" \
"$site/files/lib/libopenblas.so.0" "$site/files/bin/qt.conf"
cp -a payload/opt/sogoupinyin/files/lib/qt5/lib/libgsettings-qt.so.1 "$site/files/lib/"
cp -a payload/usr/lib/x86_64-linux-gnu/fcitx/fcitx-sogoupinyin.so "$site/usr/lib/fcitx/"
patchelf --force-rpath --set-rpath '$ORIGIN/../../../files/lib:/opt/sogoupinyin/files/lib' \
"$site/usr/lib/fcitx/fcitx-sogoupinyin.so"
cp -a payload/usr/share/fcitx/addon/fcitx-sogoupinyin.conf "$site/usr/share/fcitx/addon/"
cp -a payload/usr/share/fcitx/inputmethod/sogoupinyin.conf "$site/usr/share/fcitx/inputmethod/"
if [ -d payload/usr/share/fcitx/imicon ]; then
cp -a payload/usr/share/fcitx/imicon "$site/usr/share/fcitx/"
fi
if [ -d payload/usr/share/icons ]; then
cp -a payload/usr/share/icons "$site/usr/share/"
fi
install -m 0755 %{SOURCE1} "$site/bin/sogou-fcitx-init.sh"
chmod -R a+rX "$site"
%files
%defattr(-,root,root,-)
%{site_root}
用户初始化脚本 sogou-fcitx-init.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
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
#!/usr/bin/env bash
# One-time, non-root Fcitx 4 + Sogou setup for an ETX/XFCE desktop.
# Usage: sogou-fcitx-init.sh [init|status|stop|uninstall] [--no-start] [--root DIR]
# The ETX profile must set the desktop's GTK_IM_MODULE, QT_IM_MODULE and XMODIFIERS.
set -eu
umask 077
SELF=$(readlink -f -- "$0")
ROOT=${SOGOU_ROOT:-$(dirname -- "$(dirname -- "$SELF")")}
CMD=init
START=1
UID_NUM=$(id -u)
CONFIG=${XDG_CONFIG_HOME:-$HOME/.config}
CACHE=${XDG_CACHE_HOME:-$HOME/.cache}
CFG=$CONFIG/fcitx
AUTOSTART=$CONFIG/autostart/fcitx.desktop
LAUNCHER=$HOME/.local/bin/fcitx-sogou
LOG=$CACHE/fcitx-sogou.log
MARKER='X-Sogou-Site-Managed=true'
SERVICE_RE='(^|/)sogoupinyin-(service|watchdog)( |$)'
FAILS=0
say() { printf '%s\n' "$*"; }
ok() { printf '[ OK ] %s\n' "$*"; }
warn() { printf '[WARN] %s\n' "$*" >&2; }
bad() { printf '[FAIL] %s\n' "$*" >&2; FAILS=$((FAILS + 1)); }
die() { printf 'ERROR: %s\n' "$*" >&2; exit 1; }
while (($#)); do
case $1 in
init|status|stop|uninstall) CMD=$1 ;;
--no-start) START=0 ;;
--root) shift; ROOT=${1:?--root requires a directory} ;;
-h|--help) sed -n '2,4s/^# //p' "$SELF"; exit 0 ;;
*) die "Unknown argument: $1" ;;
esac
shift
done
[[ $UID_NUM != 0 ]] || die 'Run this script as the desktop user, not root.'
[[ $ROOT == /* && -d $ROOT ]] || die "Installation directory is unavailable: $ROOT"
ROOT=$(cd -- "$ROOT" && pwd -P)
export LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8
on_display() {
local entry proc_display=''
[[ -r /proc/$1/environ && -n ${DISPLAY:-} ]] || return 1
while IFS= read -r -d '' entry; do
case $entry in DISPLAY=*) proc_display=${entry#DISPLAY=} ;; esac
done < "/proc/$1/environ"
[[ ${proc_display%.0} == "${DISPLAY%.0}" ]]
}
current_pids() {
local pid
while IFS= read -r pid; do
if on_display "$pid"; then printf '%s\n' "$pid"; fi
done < <(pgrep -u "$UID_NUM" -x fcitx || true)
}
stop_current() {
[[ -n ${DISPLAY:-} ]] || die 'DISPLAY is required to stop the current input method.'
local pid attempt
for pid in $(current_pids); do kill -TERM "$pid" 2>/dev/null || true; done
for attempt in {1..30}; do
[[ -z $(current_pids) ]] && break
sleep 0.1
done
[[ -z $(current_pids) ]] || die 'Fcitx did not stop; configuration was left unchanged.'
while IFS= read -r pid; do
if on_display "$pid"; then kill -TERM "$pid" 2>/dev/null || true; fi
done < <(pgrep -u "$UID_NUM" -f "$SERVICE_RE" || true)
}
preflight() {
local cmd relative output
[[ -n ${DISPLAY:-} && -n ${DBUS_SESSION_BUS_ADDRESS:-} ]] ||
die 'Run init inside the ETX desktop, with DISPLAY and its D-Bus session.'
for cmd in fcitx fcitx-remote bwrap pgrep setsid timeout flock awk ldd; do
command -v "$cmd" >/dev/null || die "Missing system command: $cmd"
done
case $(fcitx --version 2>/dev/null) in *4.*) ;; *) die 'Fcitx 4 is required.' ;; esac
for relative in usr/lib/fcitx/fcitx-sogoupinyin.so \
usr/share/fcitx/addon/fcitx-sogoupinyin.conf \
usr/share/fcitx/inputmethod/sogoupinyin.conf files/bin/sogoupinyin-service; do
[[ -r $ROOT/$relative ]] || die "Missing installation file: $ROOT/$relative"
done
locale -a | grep -Eiq '^en_US\.(utf8|utf-8)$' || die 'Install the en_US.UTF-8 locale first.'
bwrap --bind / / --dev /dev --tmpfs /opt --ro-bind "$ROOT" /opt/sogoupinyin \
/usr/bin/test -x /opt/sogoupinyin/files/bin/sogoupinyin-service ||
die 'Bubblewrap cannot create the Sogou path mapping for this user.'
for relative in usr/lib/fcitx/fcitx-sogoupinyin.so files/bin/sogoupinyin-service; do
output=$(bwrap --bind / / --dev /dev --tmpfs /opt --ro-bind "$ROOT" /opt/sogoupinyin \
/usr/bin/ldd "/opt/sogoupinyin/$relative" 2>&1) || die "Cannot inspect $relative: $output"
if grep -q 'not found' <<< "$output"; then
printf '%s\n' "$output" >&2
die "An administrator must install missing libraries for $relative."
fi
done
ok "Preflight passed; installation=$ROOT"
}
backup_once() {
[[ ! -e $1.before-sogou && ! -L $1.before-sogou && ! -e $1.absent-before-sogou ]] || return 0
if [[ -e $1 || -L $1 ]]; then cp -a -- "$1" "$1.before-sogou";
else : > "$1.absent-before-sogou"; fi
}
disable_competing_autostart() {
local name file
for name in imsettings-start.desktop infra-fcitx.desktop \
fcitx-autostart.desktop sogou-xfce-autostart.desktop; do
file=$CONFIG/autostart/$name
if [[ -e $file || -f /etc/xdg/autostart/$name ]]; then
if ! grep -qF "$MARKER" "$file" 2>/dev/null; then backup_once "$file"; fi
cat > "$file.new" <<EOF
[Desktop Entry]
Type=Application
Name=Input Method Autostart Override
Hidden=true
$MARKER
EOF
mv -f -- "$file.new" "$file"
fi
done
}
update_profile() {
local temp
backup_once "$CFG/profile"
temp=$(mktemp "$CFG/.profile.sogou.XXXXXXXX")
awk '
function finish() {
if (!name) print "IMName=sogoupinyin"
if (!list) print "EnabledIMList=fcitx-keyboard-us:True,sogoupinyin:True"
}
/^\[/ {
if (inside) finish()
inside=($0 ~ /^\[Profile\][[:space:]]*$/)
if (inside) { seen=1; name=0; list=0 }
}
inside && /^IMName=/ { print "IMName=sogoupinyin"; name=1; next }
inside && /^EnabledIMList=/ {
value=substr($0,index($0,"=")+1); n=split(value,items,",")
result=""; found=0
for (i=1;i<=n;i++) {
if (items[i] ~ /^sogoupinyin:/) { items[i]="sogoupinyin:True"; found=1 }
if (items[i] != "") result=result (result == "" ? "" : ",") items[i]
}
if (!found) result=result (result == "" ? "" : ",") "sogoupinyin:True"
print "EnabledIMList=" result; list=1; next
}
{ print }
END {
if (inside) finish()
if (!seen) { print "[Profile]"; name=0; list=0; finish() }
}' "${1:-/dev/null}" > "$temp"
chmod 600 "$temp"
mv -f -- "$temp" "$CFG/profile"
}
install_files() {
mkdir -p "$CFG/addon" "$CFG/inputmethod" "$CFG/lib" \
"$HOME/.local/bin" "$CACHE" "$CONFIG/autostart"
exec 9>"$CFG/.sogou-init.lock"
flock -w 10 9 || die 'Another setup is running for this home directory.'
stop_current
local destination source profile_source=/dev/null
for destination in addon/fcitx-sogoupinyin.conf inputmethod/sogoupinyin.conf lib/fcitx-sogoupinyin.so; do
case $destination in
addon/*|inputmethod/*) source=$ROOT/usr/share/fcitx/$destination ;;
lib/*) source=$ROOT/usr/lib/fcitx/${destination##*/} ;;
esac
backup_once "$CFG/$destination"
ln -sfn -- "$source" "$CFG/$destination"
done
[[ ! -f $CFG/profile ]] || profile_source=$CFG/profile
update_profile "$profile_source"
backup_once "$LAUNCHER"
{
printf '#!/usr/bin/env bash\n# Managed by sogou-fcitx-init.sh.\nroot=%q\n' "$ROOT"
cat <<'EOF'
set -eu
export LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8
export GTK_IM_MODULE=fcitx QT_IM_MODULE=fcitx XMODIFIERS=@im=fcitx
# The user addon links extend the system Fcitx installation; no alternate prefix is needed.
unset FCITXDIR
export XDG_DATA_DIRS="$root/usr/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
log_dir=${XDG_CACHE_HOME:-$HOME/.cache}
mkdir -p "$log_dir"
exec /usr/bin/bwrap --bind / / --dev /dev --tmpfs /opt \
--ro-bind "$root" /opt/sogoupinyin \
--ro-bind /usr/bin/true /usr/bin/killall \
/usr/bin/fcitx -D -s 0 >>"$log_dir/fcitx-sogou.log" 2>&1
EOF
} > "$LAUNCHER.new"
chmod 755 "$LAUNCHER.new"
mv -f -- "$LAUNCHER.new" "$LAUNCHER"
backup_once "$AUTOSTART"
# Desktop Exec quoting is distinct from shell quoting; normal Unix account paths suffice.
[[ $LAUNCHER != *[\"\$\`%\\]* && $LAUNCHER != *$'\n'* ]] || die 'Unsupported characters in the home path.'
cat > "$AUTOSTART.new" <<EOF
[Desktop Entry]
Type=Application
Name=Fcitx + Sogou Pinyin
Exec=/bin/bash "$LAUNCHER"
OnlyShowIn=XFCE;
Terminal=false
$MARKER
EOF
mv -f -- "$AUTOSTART.new" "$AUTOSTART"
disable_competing_autostart
flock -u 9
exec 9>&-
ok 'User addon links, profile and XFCE autostart are installed.'
}
start_now() {
nohup setsid "$LAUNCHER" >/dev/null 2>&1 </dev/null &
local attempt
for attempt in {1..30}; do
if [[ $(timeout 2 fcitx-remote -m sogoupinyin 2>/dev/null || true) == fcitx-sogoupinyin ]]; then
timeout 3 fcitx-remote -s sogoupinyin || true
return
fi
sleep 0.3
done
die "Sogou did not register with Fcitx; inspect $LOG"
}
status() {
local name expected relative
say "DISPLAY=${DISPLAY:-<unset>}"
for name in GTK_IM_MODULE QT_IM_MODULE XMODIFIERS; do
expected=fcitx
[[ $name != XMODIFIERS ]] || expected=@im=fcitx
if [[ ${!name:-} == "$expected" ]]; then ok "$name=$expected";
else bad "$name=${!name:-<unset>}; expected $expected in the desktop environment"; fi
done
for relative in addon/fcitx-sogoupinyin.conf inputmethod/sogoupinyin.conf lib/fcitx-sogoupinyin.so; do
if [[ -L $CFG/$relative && -e $CFG/$relative ]]; then ok "$CFG/$relative";
else bad "Missing or broken link: $CFG/$relative"; fi
done
if grep -Eq '(^|,)sogoupinyin:True(,|$)' < <(sed -n 's/^EnabledIMList=//p' "$CFG/profile" 2>/dev/null); then
ok 'The user profile enables Sogou.'
else bad 'The user profile does not enable Sogou.'; fi
if [[ ${1:-} != noproc ]]; then
if [[ -n $(current_pids) && $(timeout 3 fcitx-remote -m sogoupinyin 2>/dev/null || true) == fcitx-sogoupinyin ]]; then
ok 'Fcitx registered Sogou on this display.'
else bad 'Fcitx/Sogou is not ready on this display.'; fi
fi
say "Log: $LOG"
say 'Confirm input by typing Pinyin and committing a candidate in a desktop application.'
}
restore_or_remove() {
if [[ -e $1.before-sogou || -L $1.before-sogou ]]; then mv -f -- "$1.before-sogou" "$1";
else rm -f -- "$1"; fi
rm -f -- "$1.absent-before-sogou"
}
uninstall() {
stop_current
local relative file
for relative in addon/fcitx-sogoupinyin.conf inputmethod/sogoupinyin.conf lib/fcitx-sogoupinyin.so; do
file=$CFG/$relative
if [[ -L $file && $(readlink "$file") == "$ROOT/"* ]]; then restore_or_remove "$file"; fi
done
if grep -qF '# Managed by sogou-fcitx-init.sh.' "$LAUNCHER" 2>/dev/null; then restore_or_remove "$LAUNCHER"; fi
for file in "$AUTOSTART" "$CONFIG/autostart/imsettings-start.desktop" \
"$CONFIG/autostart/infra-fcitx.desktop" "$CONFIG/autostart/fcitx-autostart.desktop" \
"$CONFIG/autostart/sogou-xfce-autostart.desktop"; do
if grep -qF "$MARKER" "$file" 2>/dev/null; then restore_or_remove "$file"; fi
done
if [[ -f $CFG/profile.before-sogou ]]; then
cp -p -- "$CFG/profile" "$CFG/profile.before-uninstall.$(date +%Y%m%d%H%M%S)"
mv -f -- "$CFG/profile.before-sogou" "$CFG/profile"
else
sed -i 's/sogoupinyin:True/sogoupinyin:False/g' "$CFG/profile"
fi
rm -f -- "$CFG/profile.absent-before-sogou"
ok 'User setup removed. Restart the desktop to apply restored startup settings.'
}
case $CMD in
init)
preflight
install_files
if [[ $START == 1 ]]; then start_now; status; else status noproc; fi
say 'Setup complete. Terminate this ETX desktop and create a new session.'
say 'The ETX profile uses @@im=fcitx where ETX requires escaping; the resulting environment must contain @im=fcitx.'
((FAILS == 0)) ;;
status) status; ((FAILS == 0)) ;;
stop) stop_current; ok "Stopped input-method processes on DISPLAY=${DISPLAY:-<unset>}." ;;
uninstall) uninstall ;;
esac