Skip to content

Commit

Permalink
Update repack_appimage.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzdyl authored Sep 26, 2024
1 parent 312f5dc commit 12e0412
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions repack_appimage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@
function patch_index_js() {
local path=$1
local file_name="ml_install.js" # 这里的文件名可以随意设置

echo "正在创建 $path/$file_name..."

# 写入 require(String.raw`*`) 到 *.js 文件
echo "require("$install_dir/LiteLoader");" > "$path/$file_name"
echo "已创建 $path/$file_name,内容为 require("$install_dir/LiteLoader")"
echo "require(String.raw\`$install_dir/LiteLoader\`);" > "$path/$file_name"
echo "已创建 $path/$file_name,内容为 require(String.raw\`$install_dir/LiteLoader\`)"

# 检查 package.json 文件是否存在
local package_json="$path/../package.json"
if [ -f "$package_json" ]; then
echo "正在修改 $package_json 的 main 字段..."

# 修改 package.json 中的 main 字段为 ./app_launcher/launcher.js
$sudo_cmd sed -i '' 's|"main":.*|"main": "./app_launcher/'"$file_name"'",|' "$package_json"
sed -i 's|"main":.*|"main": "./app_launcher/'"$file_name"'",|' "$package_json" || {
echo "修改 $package_json 的 main 字段时发生错误"
exit 1
}

echo "已将 $package_json 中的 main 字段修改为 ./app_launcher/$file_name"
else
echo "未找到 $path/../package.json,跳过修改"
echo "未找到 $package_json,跳过修改"
fi
}

Expand All @@ -42,12 +45,16 @@ else
echo "未找到指定的 QQ.AppImage 文件"
exit 1
fi

echo "处理原AppImage"
chmod +x $appimage_path
$appimage_path --appimage-extract >/dev/null
chmod +x "$appimage_path"
$appimage_path --appimage-extract >/dev/null || {
echo "解压 AppImage 失败"
exit 1
}
rm "$appimage_path"

cd $qq_path/squashfs-root
cd "$qq_path/squashfs-root" || { echo "进入目录失败"; exit 1; }
target_dir="$qq_path/squashfs-root"
install_dir="$target_dir/resources/app/app_launcher"
config_file="$target_dir/AppRun"
Expand All @@ -63,7 +70,7 @@ else
echo "已添加 LITELOADERQQNT_PROFILE: $plugin_dir"
fi

cd /tmp
cd /tmp || { echo "进入 /tmp 目录失败"; exit 1; }
echo "正在拉取最新版本的仓库..."
rm -rf LiteLoader
git clone https://github.com/LiteLoaderQQNT/LiteLoaderQQNT.git LiteLoader
Expand All @@ -79,12 +86,14 @@ echo "正在修补index.js... $install_dir"

patch_index_js "$install_dir"

chmod -R 0777 "$install_dir"

chmod -R 0777 $install_dir

cd "$target_dir/.."
cd "$target_dir/.." || { echo "进入目标目录失败"; exit 1; }
echo "正在重打包"
mksquashfs squashfs-root tmp.squashfs -root-owned -noappend >/dev/null
mksquashfs squashfs-root tmp.squashfs -root-owned -noappend >/dev/null || {
echo "打包失败"
exit 1
}
cat runtime-x86_64 >> QQ.AppImage
cat tmp.squashfs >> QQ.AppImage
chmod a+x QQ.AppImage
Expand All @@ -94,7 +103,7 @@ echo "清理临时文件"
# 清理临时文件
rm -rf /tmp/LiteLoader
rm -rf tmp.squashfs
rm -r $target_dir
rm -r "$target_dir"

# 错误处理.
if [ $? -ne 0 ]; then
Expand Down

0 comments on commit 12e0412

Please sign in to comment.