deb-packs/wechat/package.sh

183 lines
4.2 KiB
Bash
Raw Permalink Normal View History

2024-03-11 14:33:47 +08:00
#!/bin/bash
app_name="wechat"
tmp_dir="/tmp/${app_name}_tmp"
2024-11-06 09:50:28 +08:00
version="4.0.0.23"
2024-11-06 17:50:59 +08:00
release="${version}-5"
2024-03-11 14:33:47 +08:00
2024-03-14 12:04:16 +08:00
deb_url="https://pro-store-packages.uniontech.com/appstore/pool/appstore/c/com.tencent.wechat/com.tencent.wechat_${version}_amd64.deb"
2024-03-11 14:33:47 +08:00
# 创建临时目录, 用于下载官方包
if [ -d $tmp_dir ]; then
rm -rf $tmp_dir
fi
if [ -d "./unpack" ]; then
sudo rm -rf ./unpack
fi
if [ -f "./${app_name}_${version}.deb" ]; then
rm "./${app_name}_${version}.deb"
fi
mkdir $tmp_dir
# 创建临时待打包目录
echo "创建待打包目录..."
mkdir -p "./unpack/DEBIAN"
mkdir -p "./unpack/usr/bin"
mkdir -p "./unpack/usr/lib/license"
mkdir -p "./unpack/usr/share/wechat-uos"
2024-03-14 12:04:16 +08:00
mkdir -p "./unpack/usr/share/applications"
mkdir -p "./unpack/usr/share/icons"
mkdir -p "./unpack/opt/apps"
2024-03-11 14:33:47 +08:00
2024-11-06 17:50:59 +08:00
app_dir="./unpack/opt/apps"
2024-03-11 14:33:47 +08:00
echo "下载官方原包..."
2024-03-15 16:21:03 +08:00
wget $deb_url -O "${tmp_dir}/${app_name}.deb"
2024-11-06 17:50:59 +08:00
# cp ./wechat.deb "${tmp_dir}/${app_name}.deb"
2024-03-11 14:33:47 +08:00
echo "下载完成, 解包中..."
dpkg-deb -R "${tmp_dir}/${app_name}.deb" "${tmp_dir}/${app_name}"
2024-03-14 12:04:16 +08:00
2024-03-11 14:33:47 +08:00
echo "解包完成, 复制到待打包目录..."
2024-11-06 17:55:14 +08:00
cp -rv "${tmp_dir}/${app_name}/opt/apps/com.tencent.wechat/files" $app_dir/com.tencent.wechat
cp -rv "${tmp_dir}/${app_name}/opt/apps/com.tencent.wechat/entries/icons/hicolor" "./unpack/usr/share/icons/"
2024-03-11 14:33:47 +08:00
rm -rf $tmp_dir
2024-11-06 17:50:59 +08:00
# echo "复制uos环境文件..."
2024-11-06 17:55:14 +08:00
cp -rv ./license/etc ./unpack/usr/share/wechat-uos/
cp -rv ./license/var ./unpack/usr/share/wechat-uos/
2024-11-06 17:58:59 +08:00
mv -v $app_dir/com.tencent.wechat/libuosdevicea.so ./unpack/usr/lib/license/libuosdevicea.so
2024-11-06 17:50:59 +08:00
echo """
#!/bin/bash
echo "你在想屁吃~~"
exit 1
""" > $app_dir/com.tencent.wechat/crashpad_handler
chmod +x $app_dir/com.tencent.wechat/crashpad_handler
2024-03-11 14:33:47 +08:00
2024-11-06 17:55:14 +08:00
rm -vf $app_dir/com.tencent.wechat/libcrashpad_client.so
2024-03-11 14:33:47 +08:00
echo "复制完成, 创建可执行文件及程序桌面入口文件..."
echo """
[Desktop Entry]
Name=WeChat
Name[zh_CN]=微信
Exec=wechat %u
2024-03-14 12:04:16 +08:00
Icon=com.tencent.wechat
2024-03-11 14:33:47 +08:00
Categories=Utility;Network;InstantMessaging;Chat;
Terminal=false
Type=Application
StartupWMClass=WeChat
X-GNOME-SingleWindow=true
SingleMainWindow=true
2024-03-14 12:04:16 +08:00
""" > "./unpack/usr/share/applications/com.tencent.wechat.desktop"
2024-03-11 14:33:47 +08:00
echo """
#!/bin/bash
# wechat only support xcb
BWRAP_ENV_APPEND=\"--setenv QT_QPA_PLATFORM xcb \"
if [ -z \${QT_IM_MODULE} ]; then
BWRAP_ENV_APPEND=\"\${BWRAP_ENV_APPEND} --setenv QT_IM_MODULE fcitx\"
fi
case \"\$XDG_CURRENT_DESKTOP\" in
KDE)
SCALE_FACTOR=\$(kreadconfig6 --group KScreen --key ScaleFactor --default 1.0)
BWRAP_ENV_APPEND=\"\${BWRAP_ENV_APPEND} --setenv QT_SCALE_FACTOR \${SCALE_FACTOR}\"
;;
*)
BWRAP_ENV_APPEND=\"\${BWRAP_ENV_APPEND} --setenv QT_AUTO_SCREEN_SCALE_FACTOR \${QT_AUTO_SCREEN_SCALE_FACTOR:-1}\"
;;
esac
if [ -z \${GTK_USE_PORTAL} ]; then
BWRAP_ENV_APPEND=\"\${BWRAP_ENV_APPEND} --setenv GTK_USE_PORTAL 1\"
fi
exec bwrap \\
--dev-bind / / \\
--ro-bind /usr/share/wechat-uos/var/ /var/ \\
--ro-bind /usr/share/wechat-uos/etc/os-release /etc/os-release \\
--ro-bind /usr/share/wechat-uos/etc/lsb-release /etc/lsb-release \\
\${BWRAP_ENV_APPEND} \\
2024-03-14 12:04:16 +08:00
/opt/apps/com.tencent.wechat/wechat \$@
2024-03-11 14:33:47 +08:00
""" > ./unpack/usr/bin/wechat
chmod +x ./unpack/usr/bin/wechat
echo "修正完成, 计算文件md5..."
cd ./unpack
# opt目录中有文件名中带有空格, ;xargs需要处理一下
find opt/ -type f | xargs -I {} md5sum {} > DEBIAN/md5sums
find usr/ -type f | xargs md5sum >> DEBIAN/md5sums
IFS=$'\t' read -ra size <<< "$(du -d 0)"
echo """
Package: ${app_name}
2024-03-14 12:04:16 +08:00
Version: ${release}
2024-03-11 14:33:47 +08:00
Architecture: amd64
Maintainer: Yutent <yutent.io@gmail.com>
Installed-Size: ${size[0]}
Depends: bubblewrap, libssl1.1
Section: non-free/chat
Priority: optional
Homepage: https://weixin.qq.com
Description: linux wechat
""" > DEBIAN/control
echo """
#!/bin/bash -e
set -e
if [ ! -f /etc/lsb-release ]; then
touch /etc/lsb-release
fi
""" > DEBIAN/postinst
echo """
#!/bin/bash -e
set -e
if [ -f /etc/lsb-release ]; then
_cont=\"\$(cat /etc/lsb-release)\"
if [ \$_cont == \"\" ]; then
rm -f /etc/lsb-release
fi
fi
""" > DEBIAN/prerm
chmod +x DEBIAN/postinst
chmod +x DEBIAN/prerm
echo '计算文件md5完成, 打包中...'
cd ..
sudo chown -R root:root unpack
dpkg-deb -b ./unpack "./${app_name}_${version}.deb"
sudo rm -rf ./unpack
echo "打包完成 :)"