diff --git a/scripts/destVersionForMac.sh b/scripts/destVersionForMac.sh
index c953c57..f58b502 100644
--- a/scripts/destVersionForMac.sh
+++ b/scripts/destVersionForMac.sh
@@ -2,125 +2,214 @@
set -eo pipefail
-temp_path="WeChatMac/temp"
-latest_path="WeChatMac/latest"
+# ====================================================
+# 配置变量
+# ====================================================
+TEMP_PATH="WeChatMac/temp"
+DOWNLOAD_LINK="${1:-https://dldir1.qq.com/weixin/mac/WeChatMac.dmg}"
-download_link="$1"
-if [ -z "$1" ]; then
- >&2 echo -e "Missing argument. Using default download link"
- download_link="https://dldir1.qq.com/weixin/mac/WeChatMac.dmg"
-fi
+# ====================================================
+# 函数定义
+# ====================================================
-function install_depends() {
- printf "#%.0s" {1..60}
- echo
- echo -e "## \033[1;33mInstalling 7zip, shasum, wget, curl, git\033[0m"
- printf "#%.0s" {1..60}
- echo
-
- apt install -y p7zip-full p7zip-rar libdigest-sha-perl wget curl git python3 python3-pip
- pip install lxml request
+# 打印分隔线
+print_separator() {
+ printf '%*s\n' 60 | tr ' ' '#'
}
-function login_gh() {
- printf "#%.0s" {1..60}
- echo
- echo -e "## \033[1;33mLogin to github to use github-cli...\033[0m"
- printf "#%.0s" {1..60}
- echo
- if [ -z $GHTOKEN ]; then
- >&2 echo -e "\033[1;31mMissing Github Token! Please get a BotToken from 'Github Settings->Developer settings->Personal access tokens' and set it in Repo Secrect\033[0m"
- exit 1
- fi
-
- echo $GHTOKEN > WeChatMac/temp/GHTOKEN
- gh auth login --with-token < WeChatMac/temp/GHTOKEN
- if [ "$?" -ne 0 ]; then
- >&2 echo -e "\033[1;31mLogin Failed, please check your network or token!\033[0m"
- clean_data 1
- fi
- rm -rfv WeChatMac/temp/GHTOKEN
+# 彩色输出函数
+echo_color() {
+ local color="$1"
+ shift
+ local message="$*"
+ case "$color" in
+ yellow)
+ echo -e "\033[1;33m$message\033[0m"
+ ;;
+ red)
+ echo -e "\033[1;31m$message\033[0m" >&2
+ ;;
+ green)
+ echo -e "\033[1;32m$message\033[0m"
+ ;;
+ *)
+ echo "$message"
+ ;;
+ esac
}
-function download_wechat() {
- printf "#%.0s" {1..60}
- echo
- echo -e "## \033[1;33mDownloading the newest WeChatMac...\033[0m"
- printf "#%.0s" {1..60}
- echo
+# 安装依赖项
+install_depends() {
+ print_separator
+ echo_color "yellow" "Installing dependencies: 7zip, wget, curl, git, gh, dmg2img, shasum"
+ print_separator
- wget -q "$download_link" -O ${temp_path}/WeChatMac.dmg
+ sudo apt update
+ sudo apt install -y p7zip-full p7zip-rar libdigest-sha-perl wget curl git gh dmg2img
+}
+
+# 下载 WeChat DMG
+download_wechat() {
+ print_separator
+ echo_color "yellow" "Downloading the newest WeChatMac..."
+ print_separator
+
+ mkdir -p "$TEMP_PATH"
+
+ wget -q "$DOWNLOAD_LINK" -O "${TEMP_PATH}/WeChatMac.dmg"
if [ "$?" -ne 0 ]; then
- >&2 echo -e "\033[1;31mDownload Failed, please check your network!\033[0m"
+ echo_color "red" "Download Failed, please check your network!"
clean_data 1
fi
}
-function get_version() {
- dest_version=`python3 scripts/getVersion.py`
+# 从 Info.plist 提取版本信息
+get_version() {
+ print_separator
+ echo_color "yellow" "Extracting version from Info.plist..."
+ print_separator
+
+ # 使用 dmg2img 将 DMG 转换为 IMG
+ dmg2img "${TEMP_PATH}/WeChatMac.dmg" "${TEMP_PATH}/WeChatMac.img"
+
+ # 使用 7z x 解压 IMG 文件,保留目录结构
+ 7z x "${TEMP_PATH}/WeChatMac.img" -o"${TEMP_PATH}" >/dev/null || {
+ echo_color "red" "Failed to extract IMG file."
+ clean_data 1
+ }
+
+ # 查找 Info.plist
+ # INFO_PLIST=$(find "${TEMP_PATH}" -type f -name "Info.plist" | head -n 1)
+ INFO_PLIST=${TEMP_PATH}/微信\ WeChat/WeChat.app/Contents/Info.plist
+
+ if [ -z "$INFO_PLIST" ] || [ ! -f "$INFO_PLIST" ]; then
+ echo_color "red" "Info.plist not found in the IMG!"
+ clean_data 1
+ fi
+
+ # 使用 grep 和 sed 提取版本号
+ VERSION=$(grep -A1 'CFBundleShortVersionString' "$INFO_PLIST" | grep '' | sed -E 's/.*([^<]+)<\/string>.*/\1/')
+
+ if [ -z "$VERSION" ]; then
+ VERSION=$(grep -A1 'CFBundleVersion' "$INFO_PLIST" | grep '' | sed -E 's/.*([^<]+)<\/string>.*/\1/')
+ fi
+
+ if [ -z "$VERSION" ]; then
+ echo_color "red" "Version information not found in Info.plist!"
+ clean_data 1
+ fi
+
+ echo "Version: $VERSION"
}
-
-# rename and replace
-function prepare_commit() {
- printf "#%.0s" {1..60}
- echo
- echo -e "## \033[1;33mPrepare to commit new version\033[0m"
- printf "#%.0s" {1..60}
- echo
-
- mkdir -p WeChatMac/$dest_version
- cp $temp_path/WeChatMac.dmg WeChatMac/$dest_version/WeChatMac-$dest_version.dmg
- echo "DestVersion: $dest_version" > WeChatMac/$dest_version/WeChatMac-$dest_version.dmg.sha256
- echo "Sha256: $now_sum256" >> WeChatMac/$dest_version/WeChatMac-$dest_version.dmg.sha256
- echo "UpdateTime: $(date -u '+%Y-%m-%d %H:%M:%S') (UTC)" >> WeChatMac/$dest_version/WeChatMac-$dest_version.dmg.sha256
- echo "DownloadFrom: $download_link" >> WeChatMac/$dest_version/WeChatMac-$dest_version.dmg.sha256
-
+# 计算 SHA256
+compute_sha256() {
+ local file_path="$1"
+ shasum -a 256 "$file_path" | awk '{print $1}'
}
-function clean_data() {
- printf "#%.0s" {1..60}
- echo
- echo -e "## \033[1;33mClean runtime and exit...\033[0m"
- printf "#%.0s" {1..60}
- echo
+# 准备提交(复制 DMG 并创建 .sha256 文件)
+prepare_commit() {
+ print_separator
+ echo_color "yellow" "Preparing to commit new version..."
+ print_separator
- rm -rfv WeChatMac/*
- exit $1
+ VERSION_DIR="WeChatMac/$VERSION"
+ mkdir -p "$VERSION_DIR"
+
+ cp "${TEMP_PATH}/WeChatMac.dmg" "$VERSION_DIR/WeChatMac-$VERSION.dmg"
+
+ NOW_SUM256=$(compute_sha256 "$VERSION_DIR/WeChatMac-$VERSION.dmg")
+
+ cat > "$VERSION_DIR/WeChatMac-$VERSION.dmg.sha256" <&2 echo -e "\n\033[1;32mThis is the newest Version!\033[0m\n"
+ # 提取版本信息
+ get_version
+
+ # 准备提交(复制 DMG 并创建 .sha256 文件)
+ prepare_commit
+
+ # 获取最新的 GitHub Release 信息
+ get_latest_release_info
+
+ # 比较 SHA256 值
+ if [ "$NOW_SUM256" = "$LATEST_SUM256" ] && [ -n "$LATEST_SUM256" ]; then
+ echo_color "green" "This is the newest Version!"
clean_data 0
fi
- ## if not the newest
- get_version
- prepare_commit
- # if dest_version is the same as latest_version
- if [ "$dest_version" = "$latest_version" ]; then
- version="$dest_version"_`date -u '+%Y%m%d'`
- echo -e $dest_version
- else
- version="$dest_version"
- fi
-
- gh release create v$version ./WeChatMac/$dest_version/WeChatMac-$dest_version.dmg -F ./WeChatMac/$dest_version/WeChatMac-$dest_version.dmg.sha256 -t "Wechat For Mac v$version"
- # gh auth logout --hostname github.com | echo "y"
+ # 创建新的 GitHub Release
+ create_release
+ # 清理临时数据并退出
clean_data 0
}
+# 执行主流程
main
-
diff --git a/scripts/destVersionRelease.sh b/scripts/destVersionRelease.sh
deleted file mode 100755
index bc4bede..0000000
--- a/scripts/destVersionRelease.sh
+++ /dev/null
@@ -1,127 +0,0 @@
-#!/usr/bin/env bash
-
-set -eo pipefail
-
-temp_path="WeChatSetup/temp"
-latest_path="WeChatSetup/latest"
-
-download_link="$1"
-if [ -z "$1" ]; then
- >&2 echo -e "Missing argument. Using default download link"
- download_link="https://dldir1.qq.com/weixin/Windows/WeChatSetup.exe"
-fi
-
-function install_depends() {
- printf "#%.0s" {1..60}
- echo
- echo -e "## \033[1;33mInstalling 7zip, shasum, wget, curl, git\033[0m"
- printf "#%.0s" {1..60}
- echo
-
- apt install -y p7zip-full p7zip-rar libdigest-sha-perl wget curl git
-}
-
-function login_gh() {
- printf "#%.0s" {1..60}
- echo
- echo -e "## \033[1;33mLogin to github to use github-cli...\033[0m"
- printf "#%.0s" {1..60}
- echo
- if [ -z $GHTOKEN ]; then
- >&2 echo -e "\033[1;31mMissing Github Token! Please get a BotToken from 'Github Settings->Developer settings->Personal access tokens' and set it in Repo Secrect\033[0m"
- exit 1
- fi
-
- echo $GHTOKEN > WeChatSetup/temp/GHTOKEN
- gh auth login --with-token < WeChatSetup/temp/GHTOKEN
- if [ "$?" -ne 0 ]; then
- >&2 echo -e "\033[1;31mLogin Failed, please check your network or token!\033[0m"
- clean_data 1
- fi
- rm -rfv WeChatSetup/temp/GHTOKEN
-}
-
-function download_wechat() {
- printf "#%.0s" {1..60}
- echo
- echo -e "## \033[1;33mDownloading the newest WechatSetup...\033[0m"
- printf "#%.0s" {1..60}
- echo
-
- wget "$download_link" -O ${temp_path}/WeChatSetup.exe
- if [ "$?" -ne 0 ]; then
- >&2 echo -e "\033[1;31mDownload Failed, please check your network!\033[0m"
- clean_data 1
- fi
-}
-
-function extract_version() {
- printf "#%.0s" {1..60}
- echo
- echo -e "## \033[1;33mExtract WechatSetup, get the dest version of wechat\033[0m"
- printf "#%.0s" {1..60}
- echo
-
- local outfile=`7z l ${temp_path}/WeChatSetup.exe | grep improve.xml | awk 'NR ==1 { print $NF }'`
- ## 7z x ${temp_path}/WeChatSetup.exe -o${temp_path}/temp "\$R5/Tencent/WeChat/improve.xml"
- 7z x ${temp_path}/WeChatSetup.exe -o${temp_path}/temp $outfile
- dest_version=`awk '/MinVersion/{ print $2 }' ${temp_path}/temp/$outfile | sed -e 's/^.*="//g' -e 's/".*$//g'`
-}
-
-
-# rename and replace
-function prepare_commit() {
- printf "#%.0s" {1..60}
- echo
- echo -e "## \033[1;33mPrepare to commit new version\033[0m"
- printf "#%.0s" {1..60}
- echo
-
- mkdir -p WeChatSetup/$dest_version
- cp $temp_path/WeChatSetup.exe WeChatSetup/$dest_version/WeChatSetup-$dest_version.exe
- echo "DestVersion: $dest_version" > WeChatSetup/$dest_version/WeChatSetup-$dest_version.exe.sha256
- echo "Sha256: $now_sum256" >> WeChatSetup/$dest_version/WeChatSetup-$dest_version.exe.sha256
- echo "UpdateTime: $(date -u '+%Y-%m-%d %H:%M:%S') (UTC)" >> WeChatSetup/$dest_version/WeChatSetup-$dest_version.exe.sha256
- echo "DownloadFrom: $download_link" >> WeChatSetup/$dest_version/WeChatSetup-$dest_version.exe.sha256
-
-}
-
-function clean_data() {
- printf "#%.0s" {1..60}
- echo
- echo -e "## \033[1;33mClean runtime and exit...\033[0m"
- printf "#%.0s" {1..60}
- echo
-
- rm -rfv WeChatSetup/*
- exit $1
-}
-
-function main() {
- # rm -rfv WeChatSetup/*
- mkdir -p ${temp_path}/temp
- login_gh
- ## https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-Readme.md
- # install_depends
- download_wechat
-
- now_sum256=`shasum -a 256 ${temp_path}/WeChatSetup.exe | awk '{print $1}'`
- local latest_sum256=`gh release view --json body --jq ".body" | awk '/Sha256/{ print $2 }'`
-
- if [ "$now_sum256" = "$latest_sum256" ]; then
- >&2 echo -e "\n\033[1;32mThis is the newest Version!\033[0m\n"
- clean_data 0
- fi
- ## if not the newest
- extract_version
- prepare_commit
-
- gh release create v$dest_version ./WeChatSetup/$dest_version/WeChatSetup-$dest_version.exe -F ./WeChatSetup/$dest_version/WeChatSetup-$dest_version.exe.sha256 -t "Wechat v$dest_version"
-
- gh auth logout --hostname github.com | echo "y"
-
- clean_data 0
-}
-
-main
-
diff --git a/scripts/destversion.sh b/scripts/destversion.sh
deleted file mode 100755
index f35cc09..0000000
--- a/scripts/destversion.sh
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/usr/bin/env bash
-# 已废弃
-
-set -eo pipefail
-
-temp_path="WeChatSetup/temp"
-latest_path="WeChatSetup/latest"
-
-function install_depends () {
- printf "#%.0s" {1..60}
- echo
- echo -e "## \033[1;33mInstalling 7zip, shasum, wget, curl, git\033[0m"
- printf "#%.0s" {1..60}
- echo
- apt install -y p7zip-full p7zip-rar libdigest-sha-perl wget curl git
-}
-
-function download_wechat() {
- printf "#%.0s" {1..60}
- echo
- echo -e "## \033[1;33mDownloading the newest WechatSetup...\033[0m"
- printf "#%.0s" {1..60}
- echo
- wget https://dldir1.qq.com/weixin/Windows/WeChatSetup.exe -O ${temp_path}/WeChatSetup.exe
- if [ "$?" -ne 0 ]; then
- >&2 echo -e "\033[1;31mDownload Failed, please check your network!\033[0m"
- exit 1
- fi
-}
-
-function extract_version() {
- printf "#%.0s" {1..60}
- echo
- echo -e "## \033[1;33mExtract WechatSetup, get the dest version of wechat\033[0m"
- printf "#%.0s" {1..60}
- echo
- mkdir -p ${temp_path}/temp
- local outfile=`7z l ${temp_path}/WeChatSetup.exe | grep improve.xml | awk 'NR ==1 { print $NF }'`
- # 7z x ${temp_path}/WeChatSetup.exe -o${temp_path}/temp "\$R5/Tencent/WeChat/improve.xml"
- 7z x ${temp_path}/WeChatSetup.exe -o${temp_path}/temp $outfile
- dest_version=`awk '/MinVersion/{ print $2 }' ${temp_path}/temp/$outfile | sed -e 's/^.*="//g' -e 's/".*$//g'`
- rm -rfv ${temp_path}/temp
-}
-
-
-# rename and replace
-function prepare_commit() {
- printf "#%.0s" {1..60}
- echo
- echo -e "## \033[1;33mPrepare to commit new version and clean runtime\033[0m"
- printf "#%.0s" {1..60}
- echo
- mkdir -p WeChatSetup/$dest_version
- cp $temp_path/WeChatSetup.exe WeChatSetup/$dest_version/WeChatSetup-$dest_version.exe
- echo "$now_sum256 WeChatSetup-$dest_version.exe" > WeChatSetup/$dest_version/WeChatSetup-$dest_version.exe.sha256
-
- cp $temp_path/WeChatSetup.exe WeChatSetup/latest/WeChatSetup-latest.exe
- echo "$now_sum256 WeChatSetup-latest.exe" > WeChatSetup/latest/WeChatSetup-latest.exe.sha256
-
- # clean runtime
- rm -rfv ${temp_path}/*
-}
-
-
-function main() {
- install_depends
- download_wechat
-
- now_sum256=`shasum -a 256 ${temp_path}/WeChatSetup.exe | awk '{print $1}'`
- local latest_sum256=`cat ${latest_path}/WeChatSetup-latest.exe.sha256 | awk '{print $1}'`
-
- if [ "$now_sum256" = "$latest_sum256" ]; then
- >&2 echo -e "\n\033[1;32mThis is the newest Version! Clean runtime and exit...\033[0m\n"
- rm -rfv ${temp_path}/*
- exit 0
- fi
- ## if not the newest
- extract_version
- prepare_commit
-
- git add . && git commit -m "Add new dest version: $dest_version" && git push origin master
-}
-
-main
-
diff --git a/scripts/getVersion.py b/scripts/getVersion.py
deleted file mode 100644
index 2cbbeb0..0000000
--- a/scripts/getVersion.py
+++ /dev/null
@@ -1,15 +0,0 @@
-import lxml
-import lxml.etree
-import requests
-
-
-url = "https://mac.weixin.qq.com/?t=mac&lang=zh_CN"
-header = {
- 'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
-
-}
-r = requests.get(url,headers=header).text
-tree = lxml.etree.HTML(r)
-version = tree.xpath("/html/body/div/div[2]/div/div[1]/a[1]/div/p[2]/text()[1]")
-print(version[0])
-