diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d00285a..bd8083d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,14 +1,11 @@ name: Release - on: push: branches: - main workflow_dispatch: - env: - VERSION: '6.3.0' - + VERSION: '7.0.0' jobs: build: runs-on: ubuntu-latest @@ -23,7 +20,7 @@ jobs: rm -rf README_EN.md rm -rf .git rm -rf .github - + - name: Create Release id: create_release uses: actions/create-release@v1 @@ -37,32 +34,19 @@ jobs: body: | ## 更新内容 ### 新的功能 - 01. 现在 `super` 原始大小选项仅在提取过一次 `super` 后才会显示。 - 02. 重构 Rom 包的相关功能已重写,现在在打包 Odin Rom 时会询问是否拥有独立基带分区文件,这两种取决于你的设备。 - 03. 7z、boot editor 版本更新 - 04. 移除 vbmeta 校验的功能已添加到一键修改。 - 05. 简易识别调整,对于三星 Rom,解压后它的逻辑还会保留 `optics.img` 以及 `vbmeta` 相关文件以与一键修改匹配。 - 06. 提取所有逻辑变化,仅在仅有 img 存在时才会显示。 - 07. 带回解码,编码功能。 - 08. apktool 版本更新到2.10.0 - 09. 一键修改工具添加了英文翻译支持 - 10. Erofs 打包工具更新,打包速度巨大提升,至少20倍,例如原本打包100秒,现在只需5秒 + 01. super 打包前,如果你已经打包了子分区,现在会询问你是否要移动到 super 文件夹,这样无需手动移动。 + 02. 构建刷机包现在如果 Repacked 目录有打包的分区,会显示“轻松移动”,使用后会将它们快速移动到指定目录 Ready-to-flash/images。 + 03. 英文翻译得到标准优化,采用新方法翻译。 + ## Release Notes ### New Features - 01. The `super` original size option now only appears after extracting `super` once. - 02. The ROM package-related functions have been rewritten. When packaging Odin ROM, it will ask if you have a separate baseband partition file, depending on your device. - 03. Updated versions of 7z and boot editor. - 04. The feature to remove vbmeta verification has been added to the one-click modification. - 05. Simplified identification adjustments. For Samsung ROMs, after extraction, the logic will retain `optics.img` and `vbmeta` related files to match the one-click modification. - 06. Extraction logic changes, only showing when only img exists. - 07. Reintroduced decoding and encoding functions. - 08. Updated apktool version to 2.10.0 - 09. Added English translation support to the one-click modification tool. - 10. The Erofs packaging tool has been updated, and the packaging speed has been greatly improved, at least 20 times. For example, packaging originally took 100 seconds, but now it only takes 5 seconds. + 01. Before packaging the super, if you have already packaged subpartitions, it will now ask if you want to move them to the super folder, eliminating the need for manual moving. + 02. When building the flash package, if there are packaged partitions in the Repacked directory, "Easy Move" will now appear, allowing you to quickly move them to the specified directory Ready-to-flash/images. + 03. English translation has been standardized and optimized using a new method. - name: Archive project run: zip -r UY-Sct_${{ env.VERSION }}.zip . - + - name: Upload Release Asset id: upload_release_asset uses: actions/upload-release-asset@v1 diff --git a/resources/module_codes/cn/make_super.sh b/resources/module_codes/cn/make_super.sh index e65dba2..37ff5bf 100644 --- a/resources/module_codes/cn/make_super.sh +++ b/resources/module_codes/cn/make_super.sh @@ -235,145 +235,169 @@ function create_super_img { } function package_super_image { - echo -e "\n" - mkdir -p "$WORK_DIR/$current_workspace/Extracted-files/super" - - # 获取所有镜像文件 - img_files=("$WORK_DIR/$current_workspace/Extracted-files/super/"*.img) - real_img_files=() - for file in "${img_files[@]}"; do - if [ -e "$file" ]; then - real_img_files+=("$file") - fi - done - - # 检查是否有足够的镜像文件 - if [ ${#real_img_files[@]} -lt 2 ]; then - echo " SUPER 目录需要至少应包含两个镜像文件。" - read -n 1 -s -r -p " 按任意键返回工作域菜单..." - return - fi - - # 检查是否有被禁止的文件 - forbidden_files=() - for file in "${real_img_files[@]}"; do - filename=$(basename "$file") - if ! grep -q -x "$filename" "$TOOL_DIR/super_search"; then - forbidden_files+=("$file") - fi - done - - # 如果有被禁止的文件,显示错误信息并返回 - if [ ${#forbidden_files[@]} -gt 0 ]; then - echo -e " 禁止打包的分区文件:\n" - for file in "${forbidden_files[@]}"; do - echo -e " \e[33m$(basename "$file")\e[0m\n" - done - read -n 1 -s -r -p " 按任意键返回工作域菜单..." - return - fi - - # 询问用户是否要打包 - while true; do - # 列出目标目录下的所有子文件,每个文件前面都有一个编号 - echo -e " SUPER 待打包子分区:\n" - for i in "${!img_files[@]}"; do - file_name=$(basename "${img_files[$i]}") - printf " \e[96m[%02d] %s\e[0m\n\n" $((i+1)) "$file_name" - done - - echo -e "\n [Y] 打包 SUPER " "[N] 返回工作域菜单\n" - echo -n " 选择你想要执行的功能:" - read is_pack - clear - - # 处理用户的选择 - case "$is_pack" in - Y|y) - # 用户选择了打包,询问分区类型和打包方式 - while true; do - echo -e "\n [1] OnlyA 动态分区 " "[2] AB 动态分区 " "[3] VAB 动态分区\n" - echo -e " [Q] 返回工作域菜单\n" - echo -n " 请选择你的分区类型:" - read partition_type - - if [ "${partition_type,,}" = "q" ]; then # 将用户输入转换为小写 - echo " 已取消选择分区类型,返回工作域菜单。" - return - fi - clear - - # 处理用户选择的分区类型 - case "$partition_type" in - 1|2|3) - # 用户选择了有效的分区类型,询问打包方式 - while true; do - echo -e "\n [1] 稀疏 " "[2] 非稀疏\n" - echo -e " [Q] 返回工作域菜单\n" - echo -n " 请选择打包方式:" - read is_sparse - - if [ "${is_sparse,,}" = "q" ]; then - echo " 已取消选择,返回工作域菜单。" - return - fi - - # 处理用户选择的打包方式 - case "$is_sparse" in - 1|2) - break - ;; - *) - clear - echo -e "\n 无效的选择,请重新输入。" - ;; - esac - done - break - ;; - *) - clear - echo -e "\n 无效的选择,请重新输入。" - # 如果用户输入无效,继续循环 - ;; - esac - done - break - ;; - N|n) - echo "已取消打包操作,返回上级菜单。" - return - ;; - *) - clear - echo -e "\n 无效的选择,请重新输入。" - # 如果用户输入无效,继续循环 - ;; - esac - done - - # 在这里添加你的代码,处理用户输入后面的部分 - case "$partition_type-$is_sparse" in - 1-1) - create_super_img "OnlyA" "yes" - ;; - 1-2) - create_super_img "OnlyA" "no" - ;; - 2-1) - create_super_img "AB" "yes" - ;; - 2-2) - create_super_img "AB" "no" - ;; - 3-1) - create_super_img "VAB" "yes" - ;; - 3-2) - create_super_img "VAB" "no" - ;; - *) - echo " 无效的选择,请重新输入。" - ;; - esac + keep_clean + mkdir -p "$WORK_DIR/$current_workspace/Extracted-files/super" + # 检测 $WORK_DIR/$current_workspace/Repacked 内的 img 文件 + detected_files=() + while IFS= read -r line; do + line=$(echo "$line" | xargs) # 去掉前后的空格 + if [ -e "$WORK_DIR/$current_workspace/Repacked/$line" ]; then + detected_files+=("$WORK_DIR/$current_workspace/Repacked/$line") + fi + done < <(grep -oP '^[^#]+' "$TOOL_DIR/super_search") + # 询问是否移动到 super 文件夹 + if [ ${#detected_files[@]} -gt 0 ]; then + while true; do + echo -e "\n 侦测到已打包的子分区:\n" + for file in "${detected_files[@]}"; do + echo -e " \e[95m☑ $(basename "$file")\e[0m\n" + done + echo -e "\n 是否将这些文件移动到待打包目录?" + echo -e "\n [1] 移动 [2] 不移动\n" + echo -n " 选择你的操作:" + read move_files + clear + if [[ "$move_files" = "1" ]]; then + for file in "${detected_files[@]}"; do + mv "$file" "$WORK_DIR/$current_workspace/Extracted-files/super/" + done + break + elif [[ "$move_files" = "2" ]]; then + break + else + echo -e "\n 无效的选择,请重新输入。\n" + fi + done + fi + # 获取所有镜像文件 + shopt -s nullglob + img_files=("$WORK_DIR/$current_workspace/Extracted-files/super/"*.img) + shopt -u nullglob + real_img_files=() + for file in "${img_files[@]}"; do + if [ -e "$file" ]; then + real_img_files+=("$file") + fi + done + # 检查是否有足够的镜像文件 + if [ ${#real_img_files[@]} -lt 2 ]; then + echo -e "\n SUPER 目录需要至少应包含两个镜像文件。" + read -n 1 -s -r -p " 按任意键返回工作域菜单..." + return + fi + # 检查是否有被禁止的文件 + forbidden_files=() + for file in "${real_img_files[@]}"; do + filename=$(basename "$file") + if ! grep -q -x "$filename" "$TOOL_DIR/super_search"; then + forbidden_files+=("$file") + fi + done + # 如果有被禁止的文件,显示错误信息并返回 + if [ ${#forbidden_files[@]} -gt 0 ]; then + echo -e "\n 拒绝执行,以下文件禁止合并\n" + for file in "${forbidden_files[@]}"; do + echo -e " \e[33m☒ $(basename "$file")\e[0m\n" + done + read -n 1 -s -r -p " 按任意键返回工作域菜单..." + return + fi + # 询问用户是否要打包 + while true; do + # 列出目标目录下的所有子文件,每个文件前面都有一个编号 + echo -e "\n 待打包目录的子分区:\n" + for i in "${!img_files[@]}"; do + file_name=$(basename "${img_files[$i]}") + printf " \e[96m[%02d] %s\e[0m\n\n" $((i + 1)) "$file_name" + done + echo -e "\n [1] 开始打包 [Q] 返回工作域菜单\n" + echo -n " 选择你想要执行的功能:" + read is_pack + is_pack=$(echo "$is_pack" | tr '[:upper:]' '[:lower:]') + clear + # 处理用户的选择 + case "$is_pack" in + 1) + # 用户选择了打包,询问分区类型和打包方式 + while true; do + echo -e "\n [1] OnlyA 动态分区 [2] AB 动态分区 [3] VAB 动态分区\n" + echo -e " [Q] 返回工作域菜单\n" + echo -n " 请选择你的分区类型:" + read partition_type + partition_type=$(echo "$partition_type" | tr '[:upper:]' '[:lower:]') + if [ "$partition_type" = "q" ]; then + echo " 已取消选择分区类型,返回工作域菜单。" + return + fi + clear + # 处理用户选择的分区类型 + case "$partition_type" in + 1 | 2 | 3) + # 用户选择了有效的分区类型,询问打包方式 + while true; do + echo -e "\n [1] 稀疏 [2] 非稀疏\n" + echo -e " [Q] 返回工作域菜单\n" + echo -n " 请选择打包方式:" + read is_sparse + is_sparse=$(echo "$is_sparse" | tr '[:upper:]' '[:lower:]') + if [ "$is_sparse" = "q" ]; then + echo " 已取消选择,返回工作域菜单。" + return + fi + # 处理用户选择的打包方式 + case "$is_sparse" in + 1 | 2) + break + ;; + *) + clear + echo -e "\n 无效的选择,请重新输入。" + ;; + esac + done + break + ;; + *) + clear + echo -e "\n 无效的选择,请重新输入。" + ;; + esac + done + break + ;; + q) + echo "已取消打包操作,返回上级菜单。" + return + ;; + *) + clear + echo -e "\n 无效的选择,请重新输入。" + ;; + esac + done + # 在这里添加你的代码,处理用户输入后面的部分 + case "$partition_type-$is_sparse" in + 1-1) + create_super_img "OnlyA" "yes" + ;; + 1-2) + create_super_img "OnlyA" "no" + ;; + 2-1) + create_super_img "AB" "yes" + ;; + 2-2) + create_super_img "AB" "no" + ;; + 3-1) + create_super_img "VAB" "yes" + ;; + 3-2) + create_super_img "VAB" "no" + ;; + *) + echo " 无效的选择,请重新输入。" + ;; + esac } + diff --git a/resources/module_codes/cn/rebuild_rom.sh b/resources/module_codes/cn/rebuild_rom.sh index 53b1ce4..b9c9471 100755 --- a/resources/module_codes/cn/rebuild_rom.sh +++ b/resources/module_codes/cn/rebuild_rom.sh @@ -1,195 +1,200 @@ function rebuild_rom { - keep_clean - mkdir -p "$WORK_DIR/$current_workspace/Ready-to-flash/images" - while true; do - echo -e "\n 请把要刷入的分区文件放入在所选工作域目录的 Ready-to-flash/images 文件夹中" - echo -e "\n [1] Fastboot(d) Rom " "[2] Odin Rom " "[3] 取消打包\n" - echo -n " 选择你的操作:" - read main_choice - if [[ "$main_choice" == "1" || "$main_choice" == "2" || "$main_choice" == "3" ]]; then - break - else - clear - echo -e "\n 无效的选项,请重新输入。" - fi - done - if [[ "$main_choice" == "1" ]]; then - clear - while true; do - echo -e "\n [Q] 返回工作域菜单\n" - echo -n " 请输入你的机型:" - read device_model - device_model=$(echo "$device_model" | tr '[:upper:]' '[:lower:]') - if [[ "$device_model" == "Q" || "$device_model" == "q" ]]; then - echo " 取消打包,返回工作域菜单。" - return - elif [[ "$device_model" =~ ^[0-9a-zA-Z]+$ ]]; then - break - else - clear - echo -e "\n 不可能的型号,请重新输入。" - fi - done - sed "s/set \"right_device=\w*\"/set \"right_device=$device_model\"/g" "$TOOL_DIR/flash_tool/FlashROM.bat" > "$TOOL_DIR/flash_tool/StartFlash.bat" - clear - while true; do - echo -e "\n [1] 分卷压缩 " "[2] 完全压缩 " "[Q] 返回工作域菜单\n" - echo -n " 请输入压缩方式:" - read compression_choice - if [[ "$compression_choice" == "1" || "$compression_choice" == "2" || "$compression_choice" == "Q" || "$compression_choice" == "q" ]]; then - break - else - clear - echo -e "\n 无效的选项,请重新输入。" - fi - done - clear - if [[ "$compression_choice" == "1" ]]; then - while true; do - echo -e "\n [Q] 返回工作域菜单\n" - echo -n " 请输入分卷大小:" - read volume_size - if [[ "$volume_size" =~ ^[0-9]+[mgkMGK]$ || "$volume_size" == "Q" || "$volume_size" == "q" ]]; then - break - else - clear - echo -e "\n 无效的分卷大小,请重新输入。" - fi - done - if [[ "$volume_size" == "Q" || "$volume_size" == "q" ]]; then - echo " 取消打包,返回工作域菜单。" - return - fi - clear - start=$(python3 "$TOOL_DIR/get_right_time.py") - echo -e "\n开始打包..." - find "$WORK_DIR/$current_workspace/Ready-to-flash" -mindepth 1 -maxdepth 1 -not -name 'images' -exec rm -rf {} + - "$TOOL_DIR/7z" a -tzip -v${volume_size} "$WORK_DIR/$current_workspace/Ready-to-flash/${current_workspace}.zip" "$TOOL_DIR/flash_tool/bin" "$TOOL_DIR/flash_tool/StartFlash.bat" "$WORK_DIR/$current_workspace/Ready-to-flash/images" -y -mx1 - echo -e "Fastboot(d) Rom 打包完成" - end=$(python3 "$TOOL_DIR/get_right_time.py") - runtime=$(echo "scale=3; if ($end - $start < 1) print 0; $end - $start" | bc) - echo "耗时: $runtime 秒" - elif [[ "$compression_choice" == "2" ]]; then - start=$(python3 "$TOOL_DIR/get_right_time.py") - clear - echo -e "\n开始打包..." - find "$WORK_DIR/$current_workspace/Ready-to-flash" -mindepth 1 -maxdepth 1 -not -name 'images' -exec rm -rf {} + - "$TOOL_DIR/7z" a -tzip "$WORK_DIR/$current_workspace/Ready-to-flash/${current_workspace}.zip" "$TOOL_DIR/flash_tool/bin" "$TOOL_DIR/flash_tool/StartFlash.bat" "$WORK_DIR/$current_workspace/Ready-to-flash/images" -y -mx1 - echo -e "Fastboot(d) Rom 打包完成" - end=$(python3 "$TOOL_DIR/get_right_time.py") - runtime=$(echo "scale=3; if ($end - $start < 1) print 0; $end - $start" | bc) - echo "耗时: $runtime 秒" - else - echo " 取消打包,返回工作域菜单。" - return - fi - echo -n "按任意键返回工作域菜单..." - read -n 1 - elif [[ "$main_choice" == "2" ]]; then - clear - BASE_PATH="$WORK_DIR/$current_workspace/Ready-to-flash/images" - AP_FILES=() - CP_FILES=() - BL_FILES=() - CSC_FILES=() - if [[ -f "$BASE_PATH/modem.bin" ]]; then - while true; do - echo -e "\n 你的设备是否具有独立基带分区?" - echo -e "\n [1] 是 " "[2] 否\n" - echo -n " 选择你的操作:" - read baseband_choice + keep_clean + mkdir -p "$WORK_DIR/$current_workspace/Ready-to-flash/images" + while true; do + echo -e "\n 请把要刷入的分区文件放入在所选工作域目录的 Ready-to-flash/images 文件夹中" + echo -e "\n [1] Fastboot(d) Rom " "[2] Odin Rom " "[Q] 取消打包\n" - if [[ "$baseband_choice" == "1" || "$baseband_choice" == "2" ]]; then - break - else - clear - echo -e "\n 无效的选项,请重新输入。" - fi - done - else - baseband_choice="2" - fi - clear - # 检测是否存在 .pit 文件 - if compgen -G "$BASE_PATH/*.pit" > /dev/null; then - while true; do - echo -e "\n 你的设备是否需要保留数据?" - echo -e "\n [1] 是 " "[2] 否\n" - echo -n " 选择你的操作:" - read retain_data_choice + # 检查是否有 img 文件 + if compgen -G "$WORK_DIR/$current_workspace/Repacked/*.img" >/dev/null; then + echo -e " [M] 轻松移动\n" + fi - if [[ "$retain_data_choice" == "1" || "$retain_data_choice" == "2" ]]; then - break - else - clear - echo -e "\n 无效的选项,请重新输入。" - fi - done - else - retain_data_choice="2" - fi + echo -n " 选择你的操作:" + read main_choice + main_choice=$(echo "$main_choice" | tr '[:upper:]' '[:lower:]') + if [[ "$main_choice" == "1" || "$main_choice" == "2" || "$main_choice" == "q" || "$main_choice" == "m" ]]; then + break + else + clear + echo -e "\n 无效的选项,请重新输入。" + fi + done - clear - echo -e "\n开始打包 Odin Rom..." + if [[ "$main_choice" == "1" ]]; then + clear + while true; do + echo -e "\n [Q] 返回工作域菜单\n" + echo -n " 请输入你的机型:" + read device_model + device_model=$(echo "$device_model" | tr '[:upper:]' '[:lower:]') + if [[ "$device_model" == "q" ]]; then + echo " 取消打包,返回工作域菜单。" + return + elif [[ "$device_model" =~ ^[0-9a-zA-Z]+$ ]]; then + break + else + clear + echo -e "\n 不可能的型号,请重新输入。" + fi + done + sed "s/set \"right_device=\w*\"/set \"right_device=$device_model\"/g" "$TOOL_DIR/flash_tool/FlashROM.bat" >"$TOOL_DIR/flash_tool/StartFlash.bat" + clear + while true; do + echo -e "\n [1] 分卷压缩 " "[2] 完全压缩 " "[Q] 返回工作域菜单\n" + echo -n " 请输入压缩方式:" + read compression_choice + if [[ "$compression_choice" == "1" || "$compression_choice" == "2" || "$compression_choice" == "q" ]]; then + break + else + clear + echo -e "\n 无效的选项,请重新输入。" + fi + done + clear + if [[ "$compression_choice" == "1" ]]; then + while true; do + echo -e "\n [Q] 返回工作域菜单\n" + echo -n " 请输入分卷大小:" + read volume_size + if [[ "$volume_size" =~ ^[0-9]+[mgkMGK]$ || "$volume_size" == "q" ]]; then + break + else + clear + echo -e "\n 无效的分卷大小,请重新输入。" + fi + done + if [[ "$volume_size" == "q" ]]; then + echo " 取消打包,返回工作域菜单。" + return + fi + clear + start=$(python3 "$TOOL_DIR/get_right_time.py") + echo -e "\n开始打包..." + find "$WORK_DIR/$current_workspace/Ready-to-flash" -mindepth 1 -maxdepth 1 -not -name 'images' -exec rm -rf {} + + "$TOOL_DIR/7z" a -tzip -v${volume_size} "$WORK_DIR/$current_workspace/Ready-to-flash/${current_workspace}.zip" "$TOOL_DIR/flash_tool/bin" "$TOOL_DIR/flash_tool/StartFlash.bat" "$WORK_DIR/$current_workspace/Ready-to-flash/images" -y -mx1 + echo -e "Fastboot(d) Rom 打包完成" + end=$(python3 "$TOOL_DIR/get_right_time.py") + runtime=$(echo "scale=3; if ($end - $start < 1) print 0; $end - $start" | bc) + echo "耗时: $runtime 秒" + elif [[ "$compression_choice" == "2" ]]; then + start=$(python3 "$TOOL_DIR/get_right_time.py") + clear + echo -e "\n开始打包..." + find "$WORK_DIR/$current_workspace/Ready-to-flash" -mindepth 1 -maxdepth 1 -not -name 'images' -exec rm -rf {} + + "$TOOL_DIR/7z" a -tzip "$WORK_DIR/$current_workspace/Ready-to-flash/${current_workspace}.zip" "$TOOL_DIR/flash_tool/bin" "$TOOL_DIR/flash_tool/StartFlash.bat" "$WORK_DIR/$current_workspace/Ready-to-flash/images" -y -mx1 + echo -e "Fastboot(d) Rom 打包完成" + end=$(python3 "$TOOL_DIR/get_right_time.py") + runtime=$(echo "scale=3; if ($end - $start < 1) print 0; $end - $start" | bc) + echo "耗时: $runtime 秒" + else + echo " 取消打包,返回工作域菜单。" + return + fi + echo -n "按任意键返回工作域菜单..." + read -n 1 + elif [[ "$main_choice" == "2" ]]; then + clear + # 定义基础路径 + BASE_PATH="$WORK_DIR/$current_workspace/Ready-to-flash/images" + # 初始化空数组 + AP_FILES=() + CP_FILES=() + BL_FILES=() + CSC_FILES=() + # 检测是否存在 modem.bin 文件 + if [[ -f "$BASE_PATH/modem.bin" ]]; then + while true; do + echo -e "\n 你的设备是否具有独立基带分区?" + echo -e "\n [1] 是 " "[2] 否\n" + echo -n " 选择你的操作:" + read baseband_choice + if [[ "$baseband_choice" == "1" || "$baseband_choice" == "2" ]]; then + break + else + clear + echo -e "\n 无效的选项,请重新输入。" + fi + done + else + baseband_choice="2" + fi + clear + # 检测是否存在 .pit 文件 + if compgen -G "$BASE_PATH/*.pit" >/dev/null; then + while true; do + echo -e "\n 你的设备是否需要保留数据?" + echo -e "\n [1] 是 " "[2] 否\n" + echo -n " 选择你的操作:" + read retain_data_choice + if [[ "$retain_data_choice" == "1" || "$retain_data_choice" == "2" ]]; then + break + else + clear + echo -e "\n 无效的选项,请重新输入。" + fi + done + else + retain_data_choice="2" + fi + clear + echo -e "\n开始打包 Odin Rom..." + # 检查并添加文件到 AP_FILES 数组 + while IFS= read -r -d '' file; do + AP_FILES+=("$(basename "$file")") + done < <(find "$BASE_PATH" -maxdepth 1 \( -name "boot.img" -o -name "dtbo.img" -o -name "init_boot.img" -o -name "misc.bin" -o -name "persist.img" -o -name "recovery.img" -o -name "super.img" -o -name "vbmeta_system.img" -o -name "vendor_boot.img" -o -name "vm-bootsys.img" \) -print0) + # 检查并添加 modem.bin 文件到相应的数组 + while IFS= read -r -d '' file; do + if [[ "$baseband_choice" == "1" ]]; then + CP_FILES+=("$(basename "$file")") + else + AP_FILES+=("$(basename "$file")") + fi + done < <(find "$BASE_PATH" -maxdepth 1 -name "modem.bin" -print0) + # 检查并添加文件到 BL_FILES 数组 + while IFS= read -r -d '' file; do + BL_FILES+=("$(basename "$file")") + done < <(find "$BASE_PATH" -maxdepth 1 \( -name "vbmeta.img" -o -regex ".*\.\(elf\|mbn\|bin\|fv\|melf\)" \) ! -name "modem.bin" ! -name "misc.bin" -print0) - # 检查并添加文件到 AP_FILES 数组 - while IFS= read -r -d '' file; do - AP_FILES+=("$(basename "$file")") - done < <(find "$BASE_PATH" -maxdepth 1 \( -name "boot.img" -o -name "dtbo.img" -o -name "init_boot.img" -o -name "misc.bin" -o -name "persist.img" -o -name "recovery.img" -o -name "super.img" -o -name "vbmeta_system.img" -o -name "vendor_boot.img" -o -name "vm-bootsys.img" \) -print0) + # 检查并添加文件到 CSC_FILES 数组 + while IFS= read -r -d '' file; do + if [[ "$retain_data_choice" == "1" ]]; then + # 如果选择保留数据,只添加 cache.img、optics.img 和 prism.img + if [[ "$(basename "$file")" == "cache.img" || "$(basename "$file")" == "optics.img" || "$(basename "$file")" == "prism.img" ]]; then + CSC_FILES+=("$(basename "$file")") + fi + else + # 否则,添加所有相关文件 + CSC_FILES+=("$(basename "$file")") + fi + done < <(find "$BASE_PATH" -maxdepth 1 \( -name "cache.img" -o -name "*.pit" -o -name "omr.img" -o -name "optics.img" -o -name "prism.img" \) -print0) + # 打包 AP 文件 + if [[ ${#AP_FILES[@]} -gt 0 ]]; then + "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/AP-${current_workspace}.tar" "${AP_FILES[@]/#/$BASE_PATH/}" + fi + # 打包 BL 文件 + if [[ ${#BL_FILES[@]} -gt 0 ]]; then + "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/BL-${current_workspace}.tar" "${BL_FILES[@]/#/$BASE_PATH/}" + fi + # 打包 CP 文件 + if [[ ${#CP_FILES[@]} -gt 0 ]]; then + "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/CP-${current_workspace}.tar" "${CP_FILES[@]/#/$BASE_PATH/}" + fi + # 打包 CSC 文件 + if [[ ${#CSC_FILES[@]} -gt 0 ]]; then + "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/CSC-${current_workspace}.tar" "${CSC_FILES[@]/#/$BASE_PATH/}" + fi + echo -e "Odin Rom 打包完成" + echo -n "按任意键返回工作域菜单..." + read -n 1 - # 检查并添加 modem.bin 文件到相应的数组 - while IFS= read -r -d '' file; do - if [[ "$baseband_choice" == "1" ]]; then - CP_FILES+=("$(basename "$file")") - else - AP_FILES+=("$(basename "$file")") - fi - done < <(find "$BASE_PATH" -maxdepth 1 -name "modem.bin" -print0) - - # 检查并添加文件到 BL_FILES 数组 - while IFS= read -r -d '' file; do - BL_FILES+=("$(basename "$file")") - done < <(find "$BASE_PATH" -maxdepth 1 \( -name "vbmeta.img" -o -regex ".*\.\(elf\|mbn\|bin\|fv\|melf\)" \) ! -name "modem.bin" ! -name "misc.bin" -print0) - - # 检查并添加文件到 CSC_FILES 数组 - while IFS= read -r -d '' file; do - if [[ "$retain_data_choice" == "1" ]]; then - # 如果选择保留数据,只添加 cache.img、optics.img 和 prism.img - if [[ "$(basename "$file")" == "cache.img" || "$(basename "$file")" == "optics.img" || "$(basename "$file")" == "prism.img" ]]; then - CSC_FILES+=("$(basename "$file")") - fi - else - # 否则,添加所有相关文件 - CSC_FILES+=("$(basename "$file")") - fi - done < <(find "$BASE_PATH" -maxdepth 1 \( -name "cache.img" -o -name "*.pit" -o -name "omr.img" -o -name "optics.img" -o -name "prism.img" \) -print0) - - # 打包 AP 文件 - if [[ ${#AP_FILES[@]} -gt 0 ]]; then - "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/AP-${current_workspace}.tar" "${AP_FILES[@]/#/$BASE_PATH/}" - fi - - # 打包 BL 文件 - if [[ ${#BL_FILES[@]} -gt 0 ]]; then - "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/BL-${current_workspace}.tar" "${BL_FILES[@]/#/$BASE_PATH/}" - fi - - # 打包 CP 文件 - if [[ ${#CP_FILES[@]} -gt 0 ]]; then - "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/CP-${current_workspace}.tar" "${CP_FILES[@]/#/$BASE_PATH/}" - fi - - # 打包 CSC 文件 - if [[ ${#CSC_FILES[@]} -gt 0 ]]; then - "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/CSC-${current_workspace}.tar" "${CSC_FILES[@]/#/$BASE_PATH/}" - fi - - echo -e "Odin Rom 打包完成" - - echo -n "按任意键返回工作域菜单..." - read -n 1 - - else - echo " 取消打包,返回工作域菜单。" - fi + elif [[ "$main_choice" == "m" ]]; then + clear + find "$WORK_DIR/$current_workspace/Repacked" -name '*.img' -exec mv {} "$WORK_DIR/$current_workspace/Ready-to-flash/images" \; + rebuild_rom + return + else + echo " 取消打包,返回工作域菜单。" + fi } + diff --git a/resources/module_codes/en/extract.sh b/resources/module_codes/en/extract.sh index 8dd1d48..6a7feed 100644 --- a/resources/module_codes/en/extract.sh +++ b/resources/module_codes/en/extract.sh @@ -1,247 +1,254 @@ function extract_single_img { - local single_file="$1" - local single_file_name=$(basename "$single_file") - local base_name="${single_file_name%.*}" - fs_type=$(recognize_file_type "$single_file") - start=$(python3 "$TOOL_DIR/get_right_time.py") + local single_file="$1" + local single_file_name=$(basename "$single_file") + local base_name="${single_file_name%.*}" + fs_type=$(recognize_file_type "$single_file") + start=$(python3 "$TOOL_DIR/get_right_time.py") - # Clean the target folder before extraction - if [[ "$fs_type" == "ext" || "$fs_type" == "erofs" || "$fs_type" == "f2fs" || \ - "$fs_type" == "boot" || "$fs_type" == "dtbo" || "$fs_type" == "recovery" || \ - "$fs_type" == "vbmeta" || "$fs_type" == "vendor_boot" ]]; then - rm -rf "$WORK_DIR/$current_workspace/Extracted-files/$base_name" - fi + # 在提取前清理一次目标文件夹 + if [[ "$fs_type" == "ext" || "$fs_type" == "erofs" || "$fs_type" == "f2fs" || + "$fs_type" == "boot" || "$fs_type" == "dtbo" || "$fs_type" == "recovery" || + "$fs_type" == "vbmeta" || "$fs_type" == "vendor_boot" ]]; then + rm -rf "$WORK_DIR/$current_workspace/Extracted-files/$base_name" + fi - case "$fs_type" in - sparse) - echo "Converting sparse partition file ${single_file_name}, please wait..." - "$TOOL_DIR/simg2img" "$single_file" "$WORK_DIR/$current_workspace/${base_name}_converted.img" - rm -rf "$single_file" - mv "$WORK_DIR/$current_workspace/${base_name}_converted.img" "$WORK_DIR/$current_workspace/${base_name}.img" - single_file="$WORK_DIR/$current_workspace/${base_name}.img" - echo "${single_file_name} 转换完成" - extract_single_img "$single_file" - return - ;; - super) - echo "Extracting SUPER partition file ${single_file_name}, please wait..." - - # Read the byte size of the super file - super_size=$(stat -c%s "$single_file") - - # Create the config folder and write the original_super_size file - mkdir -p "$WORK_DIR/$current_workspace/Extracted-files/config" + case "$fs_type" in + sparse) + echo "Converting sparse partition file ${single_file_name}, please wait..." + "$TOOL_DIR/simg2img" "$single_file" "$WORK_DIR/$current_workspace/${base_name}_converted.img" + rm -rf "$single_file" + mv "$WORK_DIR/$current_workspace/${base_name}_converted.img" "$WORK_DIR/$current_workspace/${base_name}.img" + single_file="$WORK_DIR/$current_workspace/${base_name}.img" + echo "${single_file_name} conversion completed" + extract_single_img "$single_file" + return + ;; + super) + echo "Extracting SUPER partition file ${single_file_name}, please wait..." - if [ ! -s "$WORK_DIR/$current_workspace/Extracted-files/config/original_super_size" ]; then - echo "$super_size" > "$WORK_DIR/$current_workspace/Extracted-files/config/original_super_size" - fi - - "$TOOL_DIR/7z" e -bb1 -aoa "$single_file" -o"$WORK_DIR/$current_workspace" - rm "$single_file" - mkdir -p "$WORK_DIR/$current_workspace/Extracted-files/super" - echo "${single_file_name} extraction completed" - ;; - boot|dtbo|recovery|vbmeta|vendor_boot) - echo "Extracting partition file ${single_file_name}, please wait..." - rm -rf "$TOOL_DIR/boot_editor/build" - cp "$single_file" "$TOOL_DIR/boot_editor/$single_file_name" - (cd "$TOOL_DIR/boot_editor" && ./gradlew unpack) > /dev/null 2>&1 - rm -rf "$WORK_DIR/$current_workspace/Extracted-files/$base_name" - mkdir -p "$WORK_DIR/$current_workspace/Extracted-files/$base_name" - mv -f "$TOOL_DIR/boot_editor/build/unzip_boot"/* "$WORK_DIR/$current_workspace/Extracted-files/$base_name" - mv -f "$TOOL_DIR/boot_editor/$base_name.img" "$TOOL_DIR/boot_editor/$base_name.img.wait" - echo "${single_file_name} extraction completed" - ;; - f2fs) - echo "Extracting partition file ${single_file_name}, please wait..." - "$TOOL_DIR/extract.f2fs" "$single_file" -o "$WORK_DIR/$current_workspace/Extracted-files" > /dev/null 2>&1 - echo "${single_file_name} extraction completed" - ;; - erofs) - echo "Extracting partition file ${single_file_name}, please wait..." - "$TOOL_DIR/extract.erofs" -i "$single_file" -o "$WORK_DIR/$current_workspace/Extracted-files" -x > /dev/null 2>&1 - echo "${single_file_name} extraction completed" - ;; - ext) - echo "Extracting partition file ${single_file_name}, please wait..." - PYTHONDONTWRITEBYTECODE=1 python3 "$TOOL_DIR/ext4_info_get.py" "$single_file" "$WORK_DIR/$current_workspace/Extracted-files/config" - rm -rf "$WORK_DIR/$current_workspace/Extracted-files/$base_name" - mkdir -p "$WORK_DIR/$current_workspace/Extracted-files/$base_name" - "$TOOL_DIR/extract.ext" "$single_file" "./:$WORK_DIR/$current_workspace/Extracted-files/$base_name" - echo "${single_file_name} extraction completed" - ;; - payload) - echo "Extracting ${single_file_name}, please wait..." - "$TOOL_DIR/payload-dumper-go" -c 4 -o "$WORK_DIR/$current_workspace" "$single_file" > /dev/null 2>&1 - rm -rf "$single_file" - echo "${single_file_name} extraction completed" - ;; - zip) - file_list=$("$TOOL_DIR/7z" l "$single_file") - if echo "$file_list" | grep -q "payload.bin" && echo "$file_list" | grep -q "META-INF"; then - echo "Detected ROM package ${single_file_name}, please wait..." - "$TOOL_DIR/7z" e -bb1 -aoa "$single_file" "payload.bin" -o"$WORK_DIR/$current_workspace" - extract_single_img "$WORK_DIR/$current_workspace/payload.bin" - rm -rf "$single_file" - return - elif echo "$file_list" | grep -q "images/" && echo "$file_list" | grep -q ".img"; then - echo "Detected ROM package ${single_file_name}, please wait..." - "$TOOL_DIR/7z" e -bb1 -aoa "$single_file" "images/*.img" -o"$WORK_DIR/$current_workspace" - rm -rf "$single_file" - echo "${single_file_name} extraction completed" - elif echo "$file_list" | grep -qE "AP|BL|CP|CSC"; then - echo "Detected Odin format ROM package ${single_file_name}, please wait..." - "$TOOL_DIR/7z" e -bb1 -aoa "$single_file" -o"$WORK_DIR/$current_workspace" -ir'!AP*' -ir'!BL*' -ir'!CP*' -ir'!CSC*' - for extracted_file in "$WORK_DIR/$current_workspace"/{AP*,BL*,CP*,CSC*}; do - if [ -f "$extracted_file" ]; then - fs_type=$(recognize_file_type "$extracted_file") - if [ "$fs_type" == "tar" ]; then - extract_single_img "$extracted_file" - fi - fi - done - rm -rf "$single_file" - return - else - echo "${single_file_name} may not be a flashable ROM package" - fi - ;; - tar) - echo "Extracting TAR file ${single_file_name}, please wait..." - "$TOOL_DIR/7z" x "$single_file" -o"$WORK_DIR/$current_workspace" -xr'!meta-data' - rm -rf "$single_file" - echo "${single_file_name} extraction completed" - found_lz4=false - for lz4_file in "$WORK_DIR/$current_workspace"/*.lz4; do - if [ -f "$lz4_file" ]; then - extract_single_img "$lz4_file" - found_lz4=true - fi - done - if [ "$found_lz4" = true ]; then - return - fi - ;; - lz4) - echo "Extracting LZ4 file ${single_file_name}, please wait..." - lz4 -dq "$single_file" "$WORK_DIR/$current_workspace/${base_name}" - rm -rf "$single_file" - echo "${single_file_name} extraction completed" - ;; - *) - echo "Unknown file system type" - ;; - esac + # 读取 super 文件的字节数大小 + super_size=$(stat -c%s "$single_file") - for file in "$WORK_DIR/$current_workspace"/*; do - base_name=$(basename "$file") - if [[ ! -s $file ]] || [[ $base_name == *_b.img ]] || [[ $base_name == *_b ]] || [[ $base_name == *_b.ext ]]; then - rm -rf "$file" - elif [[ $base_name == *_a.img ]]; then - mv -f "$file" "${file%_a.img}.img" - elif [[ $base_name == *_a.ext ]]; then - mv -f "$file" "${file%_a.ext}.img" - elif [[ $base_name == *.ext ]]; then - mv -f "$file" "${file%.ext}.img" - fi - done + # 创建 config 文件夹并写入 original_super_size 文件 + mkdir -p "$WORK_DIR/$current_workspace/Extracted-files/config" - end=$(python3 "$TOOL_DIR/get_right_time.py") - runtime=$(echo "scale=3; if ($end - $start < 1) print 0; $end - $start" | bc) - echo "Time taken: $runtime seconds" + # 检查 original_super_size 文件是否存在且有内容 + if [ ! -s "$WORK_DIR/$current_workspace/Extracted-files/config/original_super_size" ]; then + echo "$super_size" >"$WORK_DIR/$current_workspace/Extracted-files/config/original_super_size" + fi + + "$TOOL_DIR/7z" e -bb1 -aoa "$single_file" -o"$WORK_DIR/$current_workspace" + rm "$single_file" + mkdir -p "$WORK_DIR/$current_workspace/Extracted-files/super" + echo "${single_file_name} extraction completed" + ;; + boot | dtbo | recovery | vbmeta | vendor_boot) + echo "Extracting partition file ${single_file_name}, please wait..." + rm -rf "$TOOL_DIR/boot_editor/build" + cp "$single_file" "$TOOL_DIR/boot_editor/$single_file_name" + (cd "$TOOL_DIR/boot_editor" && ./gradlew unpack) >/dev/null 2>&1 + rm -rf "$WORK_DIR/$current_workspace/Extracted-files/$base_name" + mkdir -p "$WORK_DIR/$current_workspace/Extracted-files/$base_name" + mv -f "$TOOL_DIR/boot_editor/build/unzip_boot"/* "$WORK_DIR/$current_workspace/Extracted-files/$base_name" + mv -f "$TOOL_DIR/boot_editor/$base_name.img" "$TOOL_DIR/boot_editor/$base_name.img.wait" + echo "${single_file_name} extraction completed" + ;; + f2fs) + echo "Extracting partition file ${single_file_name}, please wait..." + "$TOOL_DIR/extract.f2fs" "$single_file" -o "$WORK_DIR/$current_workspace/Extracted-files" >/dev/null 2>&1 + echo "${single_file_name} extraction completed" + ;; + erofs) + echo "Extracting partition file ${single_file_name}, please wait..." + "$TOOL_DIR/extract.erofs" -i "$single_file" -o "$WORK_DIR/$current_workspace/Extracted-files" -x >/dev/null 2>&1 + echo "${single_file_name} extraction completed" + ;; + ext) + echo "Extracting partition file ${single_file_name}, please wait..." + PYTHONDONTWRITEBYTECODE=1 python3 "$TOOL_DIR/ext4_info_get.py" "$single_file" "$WORK_DIR/$current_workspace/Extracted-files/config" + rm -rf "$WORK_DIR/$current_workspace/Extracted-files/$base_name" + mkdir -p "$WORK_DIR/$current_workspace/Extracted-files/$base_name" + "$TOOL_DIR/extract.ext" "$single_file" "./:$WORK_DIR/$current_workspace/Extracted-files/$base_name" + echo "${single_file_name} extraction completed" + ;; + payload) + echo "Extracting ${single_file_name}, please wait..." + "$TOOL_DIR/payload-dumper-go" -c 4 -o "$WORK_DIR/$current_workspace" "$single_file" >/dev/null 2>&1 + rm -rf "$single_file" + echo "${single_file_name} extraction completed" + ;; + zip) + # 列出 zip 文件内容 + file_list=$("$TOOL_DIR/7z" l "$single_file") + + # 检查是否存在 payload.bin 文件和 META-INF 文件夹 + if echo "$file_list" | grep -q "payload.bin" && echo "$file_list" | grep -q "META-INF"; then + echo "ROM flash package ${single_file_name} detected, please wait..." + "$TOOL_DIR/7z" e -bb1 -aoa "$single_file" "payload.bin" -o"$WORK_DIR/$current_workspace" + extract_single_img "$WORK_DIR/$current_workspace/payload.bin" + rm -rf "$single_file" + return + # 检查是否存在 images 文件夹和 .img 文件 + elif echo "$file_list" | grep -q "images/" && echo "$file_list" | grep -q ".img"; then + echo "ROM flash package ${single_file_name} detected, please wait..." + "$TOOL_DIR/7z" e -bb1 -aoa "$single_file" "images/*.img" -o"$WORK_DIR/$current_workspace" + rm -rf "$single_file" + echo "${single_file_name} extraction completed" + # 检查是否存在 AP, BL, CP, CSC 开头的文件 + elif echo "$file_list" | grep -qE "AP|BL|CP|CSC"; then + echo "Odin format ROM package ${single_file_name} detected, please wait..." + "$TOOL_DIR/7z" e -bb1 -aoa "$single_file" -o"$WORK_DIR/$current_workspace" -ir'!AP*' -ir'!BL*' -ir'!CP*' -ir'!CSC*' + for extracted_file in "$WORK_DIR/$current_workspace"/{AP*,BL*,CP*,CSC*}; do + if [ -f "$extracted_file" ]; then + fs_type=$(recognize_file_type "$extracted_file") + if [ "$fs_type" == "tar" ]; then + extract_single_img "$extracted_file" + fi + fi + done + rm -rf "$single_file" + return + else + echo "${single_file_name} may not be a flashable ROM package" + fi + ;; + tar) + echo "Extracting TAR file ${single_file_name}, please wait..." + "$TOOL_DIR/7z" x "$single_file" -o"$WORK_DIR/$current_workspace" -xr'!meta-data' + rm -rf "$single_file" + echo "${single_file_name} extraction completed" + + found_lz4=false + for lz4_file in "$WORK_DIR/$current_workspace"/*.lz4; do + if [ -f "$lz4_file" ]; then + extract_single_img "$lz4_file" + found_lz4=true + fi + done + + if [ "$found_lz4" = true ]; then + return + fi + ;; + lz4) + echo "Extracting LZ4 file ${single_file_name}, please wait..." + lz4 -dq "$single_file" "$WORK_DIR/$current_workspace/${base_name}" + rm -rf "$single_file" + echo "${single_file_name} extraction completed" + ;; + *) + echo "Unknown file system type" + ;; + esac + + for file in "$WORK_DIR/$current_workspace"/*; do + base_name=$(basename "$file") + if [[ ! -s $file ]] || [[ $base_name == *_b.img ]] || [[ $base_name == *_b ]] || [[ $base_name == *_b.ext ]]; then + rm -rf "$file" + elif [[ $base_name == *_a.img ]]; then + mv -f "$file" "${file%_a.img}.img" + elif [[ $base_name == *_a.ext ]]; then + mv -f "$file" "${file%_a.ext}.img" + elif [[ $base_name == *.ext ]]; then + mv -f "$file" "${file%.ext}.img" + fi + done + + end=$(python3 "$TOOL_DIR/get_right_time.py") + runtime=$(echo "scale=3; if ($end - $start < 1) print 0; $end - $start" | bc) + echo "Time consuming: $runtime seconds" } function extract_img { - keep_clean - mkdir -p "$WORK_DIR/$current_workspace/Extracted-files/super" - while true; do - shopt -s nullglob - regular_files=("$WORK_DIR/$current_workspace"/*.{bin,img}) - specific_files=("$WORK_DIR/$current_workspace"/*.{zip,lz4,tar,md5}) - matched_files=("${regular_files[@]}" "${specific_files[@]}") - shopt -u nullglob - if [ -e "${matched_files[0]}" ]; then - displayed_files=() - counter=0 - img_only=true - for i in "${!matched_files[@]}"; do - if [ -f "${matched_files[$i]}" ]; then - fs_type=$(recognize_file_type "${matched_files[$i]}") - if [ "$fs_type" != "unknown" ]; then - displayed_files+=("${matched_files[$i]}") - counter=$((counter+1)) - if [[ ! "${matched_files[$i]}" =~ \.img$ ]]; then - img_only=false - fi - fi - fi - done - while true; do - echo -e "\n Files in the current workspace:\n" - for i in "${!displayed_files[@]}"; do - fs_type_upper=$(echo "$(recognize_file_type "${displayed_files[$i]}")" | awk '{print toupper($0)}') - printf " \033[92m[%02d] %s —— %s\033[0m\n\n" "$((i+1))" "$(basename "${displayed_files[$i]}")" "$fs_type_upper" - done - if $img_only; then - echo -e " [ALL] Extract all [S] Simple identify [Q] Return to previous menu\n" - else - echo -e " [S] Simple identify [Q] Return to previous menu\n" - fi - echo -n " Please select the partition file to extract:" - read choice - choice=$(echo "$choice" | tr '[:upper:]' '[:lower:]') - if [ "$choice" = "all" ] && $img_only; then - clear - for file in "${displayed_files[@]}"; do - echo -e "\n" - extract_single_img "$file" - done - echo -n "Press any key to return to the workspace menu..." - read -n 1 - clear - return - elif [ "$choice" = "s" ]; then - mkdir -p "$WORK_DIR/$current_workspace/Ready-to-flash/images" - for file in "$WORK_DIR/$current_workspace"/*.{img,elf,melf,mbn,bin,fv,pit}; do - filename=$(basename "$file") - if [ -f "$WORK_DIR/$current_workspace/optics.img" ]; then - if [ "$filename" != "super.img" ] && [[ "$filename" != vbmeta*.img ]] && [[ "$filename" != "optics.img" ]] && [[ "$filename" != "vendor_boot.img" ]] && ! grep -q "$filename" "$TOOL_DIR/super_search"; then - mv "$file" "$WORK_DIR/$current_workspace/Ready-to-flash/images/" 2>/dev/null - fi - else - if [ "$filename" != "super.img" ] && ! grep -q "$filename" "$TOOL_DIR/super_search"; then - mv "$file" "$WORK_DIR/$current_workspace/Ready-to-flash/images/" 2>/dev/null - fi - fi - done - clear - break - elif [ "$choice" = "q" ]; then - return - elif [[ "$choice" =~ ^[0-9]+$ ]] && [ "$choice" -ge 1 ] && [ "$choice" -le ${#displayed_files[@]} ]; then - file="${displayed_files[$((choice-1))]}" - if [ -f "$file" ]; then - clear - echo -e "\n" - extract_single_img "$file" - echo -n "Press any key to return to the file list..." - read -n 1 - clear - break - else - echo " The selected file does not exist." - fi - else - clear - echo -e "\n Invalid choice, please re-enter." - fi - done - else - echo -e "\n There are no files in the workspace." - echo -n " Press any key to return to the workspace menu..." - read -n 1 - return - fi - done + keep_clean + mkdir -p "$WORK_DIR/$current_workspace/Extracted-files/super" + while true; do + shopt -s nullglob + regular_files=("$WORK_DIR/$current_workspace"/*.{bin,img}) + specific_files=("$WORK_DIR/$current_workspace"/*.{zip,lz4,tar,md5}) + matched_files=("${regular_files[@]}" "${specific_files[@]}") + shopt -u nullglob + if [ -e "${matched_files[0]}" ]; then + displayed_files=() + counter=0 + img_only=true + for i in "${!matched_files[@]}"; do + if [ -f "${matched_files[$i]}" ]; then + fs_type=$(recognize_file_type "${matched_files[$i]}") + if [ "$fs_type" != "unknown" ]; then + displayed_files+=("${matched_files[$i]}") + counter=$((counter + 1)) + if [[ ! "${matched_files[$i]}" =~ \.img$ ]]; then + img_only=false + fi + fi + fi + done + while true; do + echo -e "\nFiles in the current working domain:\n" + for i in "${!displayed_files[@]}"; do + fs_type_upper=$(echo "$(recognize_file_type "${displayed_files[$i]}")" | awk '{print toupper($0)}') + printf " \033[92m[%02d] %s —— %s\033[0m\n\n" "$((i + 1))" "$(basename "${displayed_files[$i]}")" "$fs_type_upper" + done + if $img_only; then + echo -e " [ALL] Extract all [S] Simple identification [Q] Return to the previous menu\n" + else + echo -e " [S] Simple identification [Q] Return to the previous menu\n" + fi + echo -n " please select the partition file to extract:" + read choice + choice=$(echo "$choice" | tr '[:upper:]' '[:lower:]') + if [ "$choice" = "all" ] && $img_only; then + clear + for file in "${displayed_files[@]}"; do + echo -e "\n" + extract_single_img "$file" + done + echo -n "Press any key to return to the workspace menu..." + read -n 1 + clear + return + elif [ "$choice" = "s" ]; then + mkdir -p "$WORK_DIR/$current_workspace/Ready-to-flash/images" + for file in "$WORK_DIR/$current_workspace"/*.{img,elf,melf,mbn,bin,fv,pit}; do + filename=$(basename "$file") + if [ -f "$WORK_DIR/$current_workspace/optics.img" ]; then + if [ "$filename" != "super.img" ] && [[ "$filename" != vbmeta*.img ]] && [[ "$filename" != "optics.img" ]] && [[ "$filename" != "vendor_boot.img" ]] && ! grep -q "$filename" "$TOOL_DIR/super_search"; then + mv "$file" "$WORK_DIR/$current_workspace/Ready-to-flash/images/" 2>/dev/null + fi + else + if [ "$filename" != "super.img" ] && ! grep -q "$filename" "$TOOL_DIR/super_search"; then + mv "$file" "$WORK_DIR/$current_workspace/Ready-to-flash/images/" 2>/dev/null + fi + fi + done + clear + break + elif [ "$choice" = "q" ]; then + return + elif [[ "$choice" =~ ^[0-9]+$ ]] && [ "$choice" -ge 1 ] && [ "$choice" -le ${#displayed_files[@]} ]; then + file="${displayed_files[$((choice - 1))]}" + if [ -f "$file" ]; then + clear + echo -e "\n" + extract_single_img "$file" + echo -n "Press any key to return to the file list..." + read -n 1 + clear + break + else + echo "The file selected by does not exist." + fi + else + clear + echo -e "\n Invalid selection, please re-enter." + fi + done + else + echo -e "\n There is no file in the working domain." + echo -n " Press any key to return to the workspace menu..." + read -n 1 + return + fi + done } - diff --git a/resources/module_codes/en/make_img.sh b/resources/module_codes/en/make_img.sh index 595aa27..ce6b8f2 100644 --- a/resources/module_codes/en/make_img.sh +++ b/resources/module_codes/en/make_img.sh @@ -1,332 +1,330 @@ function update_config_files { - local partition="$1" - local fs_config_file="$WORK_DIR/$current_workspace/Extracted-files/config/${partition}_fs_config" - local file_contexts_file="$WORK_DIR/$current_workspace/Extracted-files/config/${partition}_file_contexts" + local partition="$1" + local fs_config_file="$WORK_DIR/$current_workspace/Extracted-files/config/${partition}_fs_config" + local file_contexts_file="$WORK_DIR/$current_workspace/Extracted-files/config/${partition}_file_contexts" - # 创建临时文件来存储新的配置 - local temp_fs_config_file="$fs_config_file.tmp" - local temp_file_contexts_file="$file_contexts_file.tmp" + # 创建临时文件来存储新的配置 + local temp_fs_config_file="$fs_config_file.tmp" + local temp_file_contexts_file="$file_contexts_file.tmp" - # 将原配置文件的所有内容复制到临时配置文件中 - cat "$fs_config_file" >> "$temp_fs_config_file" - cat "$file_contexts_file" >> "$temp_file_contexts_file" + # 将原配置文件的所有内容复制到临时配置文件中 + cat "$fs_config_file" >>"$temp_fs_config_file" + cat "$file_contexts_file" >>"$temp_file_contexts_file" - # 遍历解包后的目录 - find "$WORK_DIR/$current_workspace/Extracted-files/$partition" -type f -o -type d -o -type l | while read -r file; do - # 移除 "Extracted-files/" 前缀,得到相对路径 - relative_path="${file#$WORK_DIR/$current_workspace/Extracted-files/}" + # 遍历解包后的目录 + find "$WORK_DIR/$current_workspace/Extracted-files/$partition" -type f -o -type d -o -type l | while read -r file; do + # 移除 "Extracted-files/" 前缀,得到相对路径 + relative_path="${file#$WORK_DIR/$current_workspace/Extracted-files/}" - # 检查该路径是否已经在临时配置文件中 - if ! grep -Fq "$relative_path " "$temp_fs_config_file"; then - # 如果不存在,则按照原来的方式添加 - if [ -d "$file" ]; then - echo "$relative_path 0 0 0755" >> "$temp_fs_config_file" - elif [ -L "$file" ]; then - # 处理符号链接 - local gid="0" - local mode="0644" - if [[ "$relative_path" == *"/system/bin"* || "$relative_path" == *"/system/xbin"* || "$relative_path" == *"/vendor/bin"* ]]; then - gid="2000" - fi - if [[ "$relative_path" == *"/bin"* || "$relative_path" == *"/xbin"* ]]; then - mode="0755" - elif [[ "$relative_path" == *".sh"* ]]; then - mode="0750" - fi - local link_target=$(readlink -f "$file") - if [[ "$link_target" == "$WORK_DIR/$current_workspace/Extracted-files/$partition"* ]]; then - local relative_link_target="${link_target#$WORK_DIR/$current_workspace/Extracted-files/$partition}" - echo "$relative_path 0 $gid $mode $relative_link_target" >> "$temp_fs_config_file" - else - echo "$relative_path 0 $gid $mode" >> "$temp_fs_config_file" - fi - else - # 处理普通文件 - local mode="0644" - if [[ "$relative_path" == *".sh"* ]]; then - mode="0750" - fi - echo "$relative_path 0 0 $mode" >> "$temp_fs_config_file" - fi - fi + # 检查该路径是否已经在临时配置文件中 + if ! grep -Fq "$relative_path " "$temp_fs_config_file"; then + # 如果不存在,则按照原来的方式添加 + if [ -d "$file" ]; then + echo "$relative_path 0 0 0755" >>"$temp_fs_config_file" + elif [ -L "$file" ]; then + # 处理符号链接 + local gid="0" + local mode="0644" + if [[ "$relative_path" == *"/system/bin"* || "$relative_path" == *"/system/xbin"* || "$relative_path" == *"/vendor/bin"* ]]; then + gid="2000" + fi + if [[ "$relative_path" == *"/bin"* || "$relative_path" == *"/xbin"* ]]; then + mode="0755" + elif [[ "$relative_path" == *".sh"* ]]; then + mode="0750" + fi + local link_target=$(readlink -f "$file") + if [[ "$link_target" == "$WORK_DIR/$current_workspace/Extracted-files/$partition"* ]]; then + local relative_link_target="${link_target#$WORK_DIR/$current_workspace/Extracted-files/$partition}" + echo "$relative_path 0 $gid $mode $relative_link_target" >>"$temp_fs_config_file" + else + echo "$relative_path 0 $gid $mode" >>"$temp_fs_config_file" + fi + else + # 处理普通文件 + local mode="0644" + if [[ "$relative_path" == *".sh"* ]]; then + mode="0750" + fi + echo "$relative_path 0 0 $mode" >>"$temp_fs_config_file" + fi + fi - escaped_path=$(echo "$relative_path" | sed -e 's/[+.\\[()()]/\\&/g' -e 's/]/\\]/g') - if ! grep -Fq "/$escaped_path " "$temp_file_contexts_file"; then - echo "/$escaped_path u:object_r:${partition}_file:s0" >> "$temp_file_contexts_file" - fi - done + escaped_path=$(echo "$relative_path" | sed -e 's/[+.\[()()]/\&/g' -e 's/]/\]/g') + if ! grep -Fq "/$escaped_path " "$temp_file_contexts_file"; then + echo "/$escaped_path u:object_r:${partition}_file:s0" >>"$temp_file_contexts_file" + fi + done - if ! grep -Fq "${partition}/lost+found " "$temp_fs_config_file"; then - echo "${partition}/lost+found 0 0 0755" >> "$temp_fs_config_file" - fi - if ! grep -Fq "/${partition}/lost\+found " "$temp_file_contexts_file"; then - selinux_context=$(head -n 1 "$temp_file_contexts_file" | awk '{print $2}') - echo "/${partition}/lost\+found ${selinux_context}" >> "$temp_file_contexts_file" - fi - if ! grep -Fq "/${partition}/ " "$temp_file_contexts_file"; then - fix_selinux_context=$(head -n 1 "$temp_file_contexts_file" | awk '{print $2}') - echo "/${partition}/ ${fix_selinux_context}" >> "$temp_file_contexts_file" - fi + if ! grep -Fq "${partition}/lost+found " "$temp_fs_config_file"; then + echo "${partition}/lost+found 0 0 0755" >>"$temp_fs_config_file" + fi + if ! grep -Fq "/${partition}/lost\+found " "$temp_file_contexts_file"; then + selinux_context=$(head -n 1 "$temp_file_contexts_file" | awk '{print $2}') + echo "/${partition}/lost\+found ${selinux_context}" >>"$temp_file_contexts_file" + fi + if ! grep -Fq "/${partition}/ " "$temp_file_contexts_file"; then + fix_selinux_context=$(head -n 1 "$temp_file_contexts_file" | awk '{print $2}') + echo "/${partition}/ ${fix_selinux_context}" >>"$temp_file_contexts_file" + fi - sed -i "/\/${partition}(\/.*)? /d" "$temp_file_contexts_file" + sed -i "/\/${partition}(\/.*)? /d" "$temp_file_contexts_file" - if [[ "$fs_type_choice" == 2 || "$fs_type_choice" == 4 ]]; then - if ! grep -Fq "/${partition}(/.*)? " "$temp_file_contexts_file"; then - echo "/${partition}(/.*)? u:object_r:${partition}_file:s0" >> "$temp_file_contexts_file" - fi - fi + if [[ "$fs_type_choice" == 2 || "$fs_type_choice" == 4 ]]; then + if ! grep -Fq "/${partition}(/.*)? " "$temp_file_contexts_file"; then + echo "/${partition}(/.*)? u:object_r:${partition}_file:s0" >>"$temp_file_contexts_file" + fi + fi - mv "$temp_fs_config_file" "$fs_config_file" - mv "$temp_file_contexts_file" "$file_contexts_file" + mv "$temp_fs_config_file" "$fs_config_file" + mv "$temp_file_contexts_file" "$file_contexts_file" - sort "$fs_config_file" -o "$fs_config_file" - sort "$file_contexts_file" -o "$file_contexts_file" + sort "$fs_config_file" -o "$fs_config_file" + sort "$file_contexts_file" -o "$file_contexts_file" } function package_single_partition { - dir=$1 - fs_type_choice=$2 - utc=$(date +%s) - fs_config_file="$WORK_DIR/$current_workspace/Extracted-files/config/$(basename "$dir")_fs_config" - file_contexts_file="$WORK_DIR/$current_workspace/Extracted-files/config/$(basename "$dir")_file_contexts" - output_image="$WORK_DIR/$current_workspace/Packed/$(basename "$dir").img" - start=$(date +%s%N) - echo -e "Updating the configuration files of the $(basename "$dir") partition..." - update_config_files "$(basename "$dir")" - case "$fs_type_choice" in - 1) - fs_type="erofs" - mkfs_tool_path="$(dirname "$0")/resources/my_tools/make.erofs" - echo "Partition configuration files updated" - echo "Packing the $(basename "$dir") partition files..." + dir=$1 + fs_type_choice=$2 + utc=$(date +%s) + fs_config_file="$WORK_DIR/$current_workspace/Extracted-files/config/$(basename "$dir")_fs_config" + file_contexts_file="$WORK_DIR/$current_workspace/Extracted-files/config/$(basename "$dir")_file_contexts" + output_image="$WORK_DIR/$current_workspace/Packed/$(basename "$dir").img" + start=$(date +%s%N) + echo -e "Updating the configuration file of the $(basename "$dir") partition..." + update_config_files "$(basename "$dir")" + case "$fs_type_choice" in + 1) + fs_type="erofs" + mkfs_tool_path="$(dirname "$0")/resources/my_tools/make.erofs" + echo "Partition configuration file update completed" + echo "Packaging $(basename "$dir") partition file..." - "$mkfs_tool_path" -d1 -zlz4hc,1 -T "$utc" --mount-point="/$(basename "$dir")" --fs-config-file="$fs_config_file" --product-out="$(dirname "$output_image")" --file-contexts="$file_contexts_file" "$output_image" "$dir" > /dev/null 2>&1 - ;; - 2) - fs_type="f2fs" - mkfs_tool_path="$(dirname "$0")/resources/my_tools/make.f2fs" - sload_tool_path="$(dirname "$0")/resources/my_tools/sload.f2fs" - # Calculate the size of the directory (unit: MB) - size=$(($(du -sm "$dir" | cut -f1) * 11 / 10 + 55)) + "$mkfs_tool_path" -d1 -zlz4hc,1 -T "$utc" --mount-point="/$(basename "$dir")" --fs-config-file="$fs_config_file" --product-out="$(dirname "$output_image")" --file-contexts="$file_contexts_file" "$output_image" "$dir" >/dev/null 2>&1 + ;; + 2) + fs_type="f2fs" + mkfs_tool_path="$(dirname "$0")/resources/my_tools/make.f2fs" + sload_tool_path="$(dirname "$0")/resources/my_tools/sload.f2fs" + # 计算目录的大小(单位:MB) + size=$(($(du -sm "$dir" | cut -f1) * 11 / 10 + 55)) - echo "Partition configuration files updated" - echo "Packing the $(basename "$dir") partition files..." - # Create an empty image file of the same size as the directory - dd if=/dev/zero of="$output_image" bs=1M count=$size > /dev/null 2>&1 - "$mkfs_tool_path" "$output_image" -O extra_attr,inode_checksum,sb_checksum,compression -f -T "$utc" -q - "$sload_tool_path" -f "$dir" -C "$fs_config_file" -s "$file_contexts_file" -t "/$(basename "$dir")" "$output_image" -c -T "$utc" > /dev/null 2>&1 - ;; - 3) - fs_type="ext4" - mkfs_tool_path="$(dirname "$0")/resources/my_tools/make.ext4fs" - # Calculate the size of the directory - size=$(du -sb "$dir" | cut -f1) - if [ "$size" -lt $((1024 * 1024)) ]; then - size=$((size * 6)) - elif [ "$size" -lt $((50 * 1024 * 1024)) ]; then - size=$((size * 12 / 10)) - else - # Otherwise, increase the size to 1.1 times the original - size=$((size * 11 / 10)) - fi - echo "Partition configuration files updated" - echo "Packing the $(basename "$dir") partition files..." + echo "Partition configuration file update completed" + echo "Packaging $(basename "$dir") partition file..." + # 创建一个与目录大小相同的空镜像文件 + dd if=/dev/zero of="$output_image" bs=1M count=$size >/dev/null 2>&1 + "$mkfs_tool_path" "$output_image" -O extra_attr,inode_checksum,sb_checksum,compression -f -T "$utc" -q + "$sload_tool_path" -f "$dir" -C "$fs_config_file" -s "$file_contexts_file" -t "/$(basename "$dir")" "$output_image" -c -T "$utc" >/dev/null 2>&1 + ;; + 3) + fs_type="ext4" + mkfs_tool_path="$(dirname "$0")/resources/my_tools/make.ext4fs" + # 计算目录的大小 + size=$(du -sb "$dir" | cut -f1) + if [ "$size" -lt $((1024 * 1024)) ]; then + size=$((size * 6)) + elif [ "$size" -lt $((50 * 1024 * 1024)) ]; then + size=$((size * 12 / 10)) + else + # 否则,将大小增加到原来的1.1倍 + size=$((size * 11 / 10)) + fi + echo "Partition configuration file update completed" + echo "Packaging $(basename "$dir") partition file..." - "$mkfs_tool_path" -J -l "$size" -b 4096 -S "$file_contexts_file" -L $(basename "$dir") -a "/$(basename "$dir")" -C "$fs_config_file" -T "$utc" "$output_image" "$dir" > /dev/null 2>&1 - ;; - 4) - fs_type="f2fss" - mkfs_tool_path="$(dirname "$0")/resources/my_tools/make.f2fs" - sload_tool_path="$(dirname "$0")/resources/my_tools/sload.f2fs" - # Calculate the size of the directory (unit: MB) - size=$(($(du -sm "$dir" | cut -f1) * 11 / 10 + 55)) + "$mkfs_tool_path" -J -l "$size" -b 4096 -S "$file_contexts_file" -L $(basename "$dir") -a "/$(basename "$dir")" -C "$fs_config_file" -T "$utc" "$output_image" "$dir" >/dev/null 2>&1 + ;; + 4) + fs_type="f2fss" + mkfs_tool_path="$(dirname "$0")/resources/my_tools/make.f2fs" + sload_tool_path="$(dirname "$0")/resources/my_tools/sload.f2fs" + # 计算目录的大小(单位:MB) + size=$(($(du -sm "$dir" | cut -f1) * 11 / 10 + 55)) - echo "Partition configuration files updated" - echo "Packing the $(basename "$dir") partition files..." - # Create an empty image file of the same size as the directory - dd if=/dev/zero of="$output_image" bs=1M count=$size > /dev/null 2>&1 - "$mkfs_tool_path" "$output_image" -O extra_attr,inode_checksum,sb_checksum,compression -f -T "$utc" -q - "$sload_tool_path" -f "$dir" -C "$fs_config_file" -s "$file_contexts_file" -t "/$(basename "$dir")" "$output_image" -c -T "$utc" > /dev/null 2>&1 - "$(dirname "$0")/resources/my_tools/img2simg" "$output_image" "$WORK_DIR/$current_workspace/Packed/$(basename "$dir")_sparse.img" - mv "$WORK_DIR/$current_workspace/Packed/$(basename "$dir")_sparse.img" "$output_image" - ;; - 5) - fs_type="ext4s" - mkfs_tool_path="$(dirname "$0")/resources/my_tools/make.ext4fs" - # Calculate the size of the directory - size=$(du -sb "$dir" | cut -f1) - if [ "$size" -lt $((1024 * 1024)) ]; then - size=$((size * 6)) - elif [ "$size" -lt $((50 * 1024 * 1024)) ]; then - size=$((size * 12 / 10)) - else - # Otherwise, increase the size to 1.1 times the original - size=$((size * 11 / 10)) - fi - echo "Partition configuration files updated" - echo "Packing the $(basename "$dir") partition files..." + echo "Partition configuration file update completed" + echo "Packaging $(basename "$dir") partition file..." + # 创建一个与目录大小相同的空镜像文件 + dd if=/dev/zero of="$output_image" bs=1M count=$size >/dev/null 2>&1 + "$mkfs_tool_path" "$output_image" -O extra_attr,inode_checksum,sb_checksum,compression -f -T "$utc" -q + "$sload_tool_path" -f "$dir" -C "$fs_config_file" -s "$file_contexts_file" -t "/$(basename "$dir")" "$output_image" -c -T "$utc" >/dev/null 2>&1 + "$(dirname "$0")/resources/my_tools/img2simg" "$output_image" "$WORK_DIR/$current_workspace/Packed/$(basename "$dir")_sparse.img" + mv "$WORK_DIR/$current_workspace/Packed/$(basename "$dir")_sparse.img" "$output_image" + ;; + 5) + fs_type="ext4s" + mkfs_tool_path="$(dirname "$0")/resources/my_tools/make.ext4fs" + # 计算目录的大小 + size=$(du -sb "$dir" | cut -f1) + if [ "$size" -lt $((1024 * 1024)) ]; then + size=$((size * 6)) + elif [ "$size" -lt $((50 * 1024 * 1024)) ]; then + size=$((size * 12 / 10)) + else + # 否则,将大小增加到原来的1.1倍 + size=$((size * 11 / 10)) + fi + echo "Partition configuration file update completed" + echo "Packaging $(basename "$dir") partition file..." - "$mkfs_tool_path" -s -J -l "$size" -b 4096 -S "$file_contexts_file" -L $(basename "$dir") -a "/$(basename "$dir")" -C "$fs_config_file" -T "$utc" "$output_image" "$dir" > /dev/null 2>&1 - ;; - esac - echo "$(basename "$dir") partition file packing completed" - end=$(date +%s%N) - runtime=$(awk "BEGIN {print ($end - $start) / 1000000000}") - runtime=$(printf "%.3f" "$runtime") - echo "Time consumed: $runtime seconds" + "$mkfs_tool_path" -s -J -l "$size" -b 4096 -S "$file_contexts_file" -L $(basename "$dir") -a "/$(basename "$dir")" -C "$fs_config_file" -T "$utc" "$output_image" "$dir" >/dev/null 2>&1 + ;; + esac + echo "$(basename "$dir") partition file packaging completed" + end=$(date +%s%N) + runtime=$(awk "BEGIN {print ($end - $start) / 1000000000}") + runtime=$(printf "%.3f" "$runtime") + echo "Time consuming: $runtime seconds" } function package_special_partition { - echo -e "Packing $(basename "$dir") partition" - # Get the start time - start=$(date +%s%N) - # Define a local variable dir - local dir="$1" + echo -e "Packaging $(basename "$dir") partition" + # 获取开始时间 + start=$(date +%s%N) + # 定义一个本地变量 dir + local dir="$1" - # Delete all files and folders in the directory "$TOOL_DIR/boot_editor/build/unzip_boot" - rm -rf "$TOOL_DIR/boot_editor/build/unzip_boot" - # Create the directory "$TOOL_DIR/boot_editor/build/unzip_boot" - mkdir -p "$TOOL_DIR/boot_editor/build/unzip_boot" + # 删除目录 "$TOOL_DIR/boot_editor/build/unzip_boot" 下的所有文件和文件夹 + rm -rf "$TOOL_DIR/boot_editor/build/unzip_boot" + # 创建目录 "$TOOL_DIR/boot_editor/build/unzip_boot" + mkdir -p "$TOOL_DIR/boot_editor/build/unzip_boot" - # Copy all files and folders from "$dir" to "$TOOL_DIR/boot_editor/build/unzip_boot" - cp -r "$dir"/. "$TOOL_DIR/boot_editor/build/unzip_boot" + # 复制 "$dir" 下的所有文件和文件夹到 "$TOOL_DIR/boot_editor/build/unzip_boot" + cp -r "$dir"/. "$TOOL_DIR/boot_editor/build/unzip_boot" - # Traverse all .img files - for file in $(find $TOOL_DIR/boot_editor -type f -name "*.img") - do - # Get the base name of the file (excluding the extension) - base_name=$(basename "$file" .img) + # 遍历所有的 .img 文件 + for file in $(find $TOOL_DIR/boot_editor -type f -name "*.img"); do + # 获取文件的基本名(不包含扩展名) + base_name=$(basename "$file" .img) - # Rename the .img file to .img.wait - mv "$file" "$TOOL_DIR/boot_editor/${base_name}.img.wait" - done + # 将 .img 文件重命名为 .img.wait + mv "$file" "$TOOL_DIR/boot_editor/${base_name}.img.wait" + done - # Move and rename the file "$(basename "$dir").img.wait" to "$(basename "$dir").img" - mv "$TOOL_DIR/boot_editor/$(basename "$dir").img.wait" "$TOOL_DIR/boot_editor/$(basename "$dir").img" + # 将文件 "$(basename "$dir").img.wait" 移动并重命名为 "$(basename "$dir").img" + mv "$TOOL_DIR/boot_editor/$(basename "$dir").img.wait" "$TOOL_DIR/boot_editor/$(basename "$dir").img" - # Execute the ./gradlew pack command in the "$TOOL_DIR/boot_editor" directory - (cd "$TOOL_DIR/boot_editor" && ./gradlew pack) > /dev/null 2>&1 + # 在 "$TOOL_DIR/boot_editor" 目录下执行 ./gradlew pack 命令 + (cd "$TOOL_DIR/boot_editor" && ./gradlew pack) >/dev/null 2>&1 - # Copy the "$(basename "$dir").img.signed" file to "$WORK_DIR/$current_workspace/Packed/$(basename "$dir").img" - cp -r "$TOOL_DIR/boot_editor/$(basename "$dir").img.signed" "$WORK_DIR/$current_workspace/Packed/$(basename "$dir").img" - # Move and rename the "$(basename "$dir").img.signed" file to "$(basename "$dir").img" - mv "$TOOL_DIR/boot_editor/$(basename "$dir").img.signed" "$TOOL_DIR/boot_editor/$(basename "$dir").img" - # Move and rename the "$(basename "$dir").img" file to "$(basename "$dir").img.wait" - mv "$TOOL_DIR/boot_editor/$(basename "$dir").img" "$TOOL_DIR/boot_editor/$(basename "$dir").img.wait" + # 将 "$(basename "$dir").img.signed" 文件复制到 "$WORK_DIR/$current_workspace/Packed/$(basename "$dir").img" + cp -r "$TOOL_DIR/boot_editor/$(basename "$dir").img.signed" "$WORK_DIR/$current_workspace/Packed/$(basename "$dir").img" + # 将 "$(basename "$dir").img.signed" 文件移动并重命名为 "$(basename "$dir").img" + mv "$TOOL_DIR/boot_editor/$(basename "$dir").img.signed" "$TOOL_DIR/boot_editor/$(basename "$dir").img" + # 将 "$(basename "$dir").img" 文件移动并重命名为 "$(basename "$dir").img.wait" + mv "$TOOL_DIR/boot_editor/$(basename "$dir").img" "$TOOL_DIR/boot_editor/$(basename "$dir").img.wait" - rm -rf "$TOOL_DIR/boot_editor/build" + rm -rf "$TOOL_DIR/boot_editor/build" - echo "$(basename "$dir") partition file packaging completed" + echo "$(basename "$dir") partition file packaging completed" - end=$(date +%s%N) - runtime=$(awk "BEGIN {print ($end - $start) / 1000000000}") - runtime=$(printf "%.3f" "$runtime") - echo "Time consumed: $runtime seconds" + end=$(date +%s%N) + runtime=$(awk "BEGIN {print ($end - $start) / 1000000000}") + runtime=$(printf "%.3f" "$runtime") + echo "Time consuming: $runtime seconds" } function package_regular_image { - mkdir -p "$WORK_DIR/$current_workspace/Packed" - while true; do - echo -e "\n Current partition directory: \n" - local i=1 - local dir_array=() - local special_dir_count=0 - for dir in "$WORK_DIR/$current_workspace/Extracted-files"/*; do - if [ -d "$dir" ] && [ "$(basename "$dir")" != "config" ] && [ "$(basename "$dir")" != "super" ]; then - printf " \033[0;31m[%02d] %s\033[0m\n\n" "$i" "$(basename "$dir")" - dir_array[i]="$dir" - i=$((i+1)) - if [[ "$(basename "$dir")" == "dtbo" || "$(basename "$dir")" == "boot" || "$(basename "$dir")" == "init_boot" || "$(basename "$dir")" == "vendor_boot" || "$(basename "$dir")" == "recovery" || "$(basename "$dir")" == *"vbmeta"* ]]; then - special_dir_count=$((special_dir_count+1)) - fi - fi - done - if [ ${#dir_array[@]} -eq 0 ]; then - clear - echo -e "\n No partition files detected." - echo -n " Press any key to return..." - read -n 1 - clear - return - fi - echo -e " [ALL] Package all partition files [Q] Return to workspace menu\n" - echo -n " Please select the partition directory to be packaged: " - read dir_num - dir_num=$(echo "$dir_num" | tr '[:upper:]' '[:lower:]') # Convert input to lowercase - if [ "$dir_num" = "all" ]; then - if [ $special_dir_count -ne ${#dir_array[@]} ]; then - clear - while true; do - echo -e "\n [1] EROFS [2] F2FS [3] EXT4" - echo -e "\n [4] F2FSS [5] EXT4S\n" - echo -e " [Q] Return to workspace menu\n" - echo -n " Please select the file system type to be packaged: " - read fs_type_choice - fs_type_choice=$(echo "$fs_type_choice" | tr '[:upper:]' '[:lower:]') # Convert input to lowercase - if [[ "$fs_type_choice" == "1" || "$fs_type_choice" == "2" || "$fs_type_choice" == "3" || "$fs_type_choice" == "4" || "$fs_type_choice" == "5" ]]; then - break - elif [ "$fs_type_choice" = "q" ]; then - return - else - clear - echo -e "\n Invalid input, please re-enter." - fi - done - fi - clear - for dir in "${dir_array[@]}"; do - if [[ "$(basename "$dir")" == "dtbo" || "$(basename "$dir")" == "boot" || "$(basename "$dir")" == "init_boot" || "$(basename "$dir")" == "vendor_boot" || "$(basename "$dir")" == "recovery" || "$(basename "$dir")" == *"vbmeta"* ]]; then - echo -e "\n" - package_special_partition "$dir" - else - echo -e "\n" - package_single_partition "$dir" "$fs_type_choice" - fi - done - echo -n "Packaging complete, press any key to return..." - read -n 1 - clear - continue - elif [ "$dir_num" = "q" ]; then - break - else - dir="${dir_array[$dir_num]}" - if [ -d "$dir" ]; then - if [[ "$(basename "$dir")" == "dtbo" || "$(basename "$dir")" == "boot" || "$(basename "$dir")" == "init_boot" || "$(basename "$dir")" == "vendor_boot" || "$(basename "$dir")" == "recovery" || "$(basename "$dir")" == *"vbmeta"* ]]; then - clear - echo -e "\n" - package_special_partition "$dir" - else - clear - while true; do - echo -e "\n [1] EROFS [2] F2FS [3] EXT4" - echo -e "\n [4] F2FSS [5] EXT4S\n" - echo -e " [Q] Return to workspace menu\n" - echo -n " Please select the file system type to be packaged: " - read fs_type_choice - fs_type_choice=$(echo "$fs_type_choice" | tr '[:upper:]' '[:lower:]') # Convert input to lowercase - if [[ "$fs_type_choice" == "1" || "$fs_type_choice" == "2" || "$fs_type_choice" == "3" || "$fs_type_choice" == "4" || "$fs_type_choice" == "5" ]]; then - break - elif [ "$fs_type_choice" = "q" ]; then - return - else - clear - echo -e "\n Invalid input, please re-enter." - fi - done - clear - echo -e "\n" - package_single_partition "$dir" "$fs_type_choice" - fi - echo -n "Packaging complete, press any key to return..." - read -n 1 - clear - continue - else - clear - echo -e "\n The selected directory does not exist, please re-select." - fi - fi - done + mkdir -p "$WORK_DIR/$current_workspace/Packed" + while true; do + echo -e "\nCurrent partition directory:\n" + local i=1 + local dir_array=() + local special_dir_count=0 + for dir in "$WORK_DIR/$current_workspace/Extracted-files"/*; do + if [ -d "$dir" ] && [ "$(basename "$dir")" != "config" ] && [ "$(basename "$dir")" != "super" ]; then + printf " \033[0;31m[%02d] %s\033[0m\n\n" "$i" "$(basename "$dir")" + dir_array[i]="$dir" + i=$((i + 1)) + if [[ "$(basename "$dir")" == "dtbo" || "$(basename "$dir")" == "boot" || "$(basename "$dir")" == "init_boot" || "$(basename "$dir")" == "vendor_boot" || "$(basename "$dir")" == "recovery" || "$(basename "$dir")" == *"vbmeta"* ]]; then + special_dir_count=$((special_dir_count + 1)) + fi + fi + done + if [ ${#dir_array[@]} -eq 0 ]; then + clear + echo -e "\n No partition files were detected." + echo -n " Press any key to return..." + read -n 1 + clear + return + fi + echo -e " [ALL] Pack all partition files [Q] Return to the workspace menu\n" + echo -n " 请选择打包的分区目录:" + read dir_num + dir_num=$(echo "$dir_num" | tr '[:upper:]' '[:lower:]') # Convert input to lowercase + if [ "$dir_num" = "all" ]; then + if [ $special_dir_count -ne ${#dir_array[@]} ]; then + clear + while true; do + echo -e "\n [1] EROFS [2] F2FS [3] EXT4" + echo -e "\n [4] F2FSS [5] EXT4S\n" + echo -e " [Q] Return to the workspace menu\n" + echo -n " please select the file system type to be packaged:" + read fs_type_choice + fs_type_choice=$(echo "$fs_type_choice" | tr '[:upper:]' '[:lower:]') # Convert input to lowercase + if [[ "$fs_type_choice" == "1" || "$fs_type_choice" == "2" || "$fs_type_choice" == "3" || "$fs_type_choice" == "4" || "$fs_type_choice" == "5" ]]; then + break + elif [ "$fs_type_choice" = "q" ]; then + return + else + clear + echo -e "\n Invalid input, please re-enter." + fi + done + fi + clear + for dir in "${dir_array[@]}"; do + if [[ "$(basename "$dir")" == "dtbo" || "$(basename "$dir")" == "boot" || "$(basename "$dir")" == "init_boot" || "$(basename "$dir")" == "vendor_boot" || "$(basename "$dir")" == "recovery" || "$(basename "$dir")" == *"vbmeta"* ]]; then + echo -e "\n" + package_special_partition "$dir" + else + echo -e "\n" + package_single_partition "$dir" "$fs_type_choice" + fi + done + echo -n "Packaging completed, press any key to return..." + read -n 1 + clear + continue + elif [ "$dir_num" = "q" ]; then + break + else + dir="${dir_array[$dir_num]}" + if [ -d "$dir" ]; then + if [[ "$(basename "$dir")" == "dtbo" || "$(basename "$dir")" == "boot" || "$(basename "$dir")" == "init_boot" || "$(basename "$dir")" == "vendor_boot" || "$(basename "$dir")" == "recovery" || "$(basename "$dir")" == *"vbmeta"* ]]; then + clear + echo -e "\n" + package_special_partition "$dir" + else + clear + while true; do + echo -e "\n [1] EROFS [2] F2FS [3] EXT4" + echo -e "\n [4] F2FSS [5] EXT4S\n" + echo -e " [Q] Return to the workspace menu\n" + echo -n " please select the file system type to be packaged:" + read fs_type_choice + fs_type_choice=$(echo "$fs_type_choice" | tr '[:upper:]' '[:lower:]') # Convert input to lowercase + if [[ "$fs_type_choice" == "1" || "$fs_type_choice" == "2" || "$fs_type_choice" == "3" || "$fs_type_choice" == "4" || "$fs_type_choice" == "5" ]]; then + break + elif [ "$fs_type_choice" = "q" ]; then + return + else + clear + echo -e "\n Invalid input, please re-enter." + fi + done + clear + echo -e "\n" + package_single_partition "$dir" "$fs_type_choice" + fi + echo -n "Packaging completed, press any key to return..." + read -n 1 + clear + continue + else + clear + echo -e "\n The selected directory does not exist, please select again." + fi + fi + done } - diff --git a/resources/module_codes/en/make_super.sh b/resources/module_codes/en/make_super.sh index 62a850b..d2b1582 100644 --- a/resources/module_codes/en/make_super.sh +++ b/resources/module_codes/en/make_super.sh @@ -1,202 +1,220 @@ function create_super_img { - local partition_type=$1 - local is_sparse=$2 - local img_files=() - - for file in "$WORK_DIR/$current_workspace/Extracted-files/super/"*.img; do - file_type=$(recognize_file_type "$file") - if [[ "$file_type" == "ext" || "$file_type" == "f2fs" || "$file_type" == "erofs" ]]; then - img_files+=("$file") - fi - done - - local total_size=0 - for img_file in "${img_files[@]}"; do - file_type=$(recognize_file_type "$img_file") - file_size_bytes=$(stat -c%s "$img_file") - total_size=$((total_size + file_size_bytes)) - done - remainder=$((total_size % 4096)) - if [ $remainder -ne 0 ]; then - total_size=$((total_size + 4096 - remainder)) - fi - - local extra_space=$((100 * 1024 * 1024 * 1024 / 100)) - - case "$partition_type" in - "AB") - total_size=$(((total_size + extra_space) * 2)) - ;; - "OnlyA"|"VAB") - total_size=$((total_size + extra_space)) - ;; - esac - clear - - while true; do - local original_super_size=$(cat "$WORK_DIR/$current_workspace/Extracted-files/config/original_super_size" 2>/dev/null) - echo -e "" - echo -n " [1] 9126805504 [2] $total_size --Auto Calculate" - if [ -n "$original_super_size" ]; then - echo -e " [3] \e[31m$original_super_size\e[0m --Original Size\n" - else - echo -e "\n" - fi - - echo -e " [C] Custom Input [Q] Return to Workspace Menu\n" - echo -n " Please select the package size: " - read device_size_option - - case "$device_size_option" in - 1) - device_size=9126805504 - if ((device_size < total_size)); then - echo " Less than auto-calculated size, please choose another option." - continue - fi - break - ;; - 2) - device_size=$total_size - if ((device_size < total_size)); then - echo " Less than auto-calculated size, please choose another option." - continue - fi - break - ;; - 3) - if [ -n "$original_super_size" ]; then - device_size=$original_super_size - if ((device_size < total_size)); then - echo " Less than auto-calculated size, please choose another option." - continue - fi - break - else - clear - echo -e "\n Invalid choice, please re-enter." - fi - ;; - C|c) - clear - while true; do - echo -e "\n Note: Auto-calculated size is $total_size\n" - echo -e " [Q] Return to Workspace Menu\n" - echo -n " Please enter custom size: " - read device_size - - if [[ "$device_size" =~ ^[0-9]+$ ]]; then - if ((device_size < total_size)); then - clear - echo -e "\n The entered value is less than the auto-calculated size, please re-enter" - else - if ((device_size % 4096 == 0)); then - break - else - clear - echo -e "\n The entered value is not a multiple of 4096 bytes, please re-enter" - fi - fi - elif [ "${device_size,,}" = "q" ]; then - return - else - clear - echo -e "\n Invalid input, please re-enter" - fi - done - break - ;; - Q|q) - echo " Packaging operation canceled, returning to workspace menu." - return - ;; - *) - clear - echo -e "\n Invalid choice, please re-enter." - ;; - esac - done - - clear - echo -e "\n" - - local metadata_size="65536" - local block_size="4096" - local super_name="super" - local group_name="qti_dynamic_partitions" - local group_name_a="${group_name}_a" - local group_name_b="${group_name}_b" - - case "$partition_type" in - "AB"|"VAB") - metadata_slots="3" - ;; - *) - metadata_slots="2" - ;; - esac - - local params="" - - case "$is_sparse" in - "yes") - params+="--sparse" - ;; - esac - - case "$partition_type" in - "VAB") - overhead_adjusted_size=$((device_size - 10 * 1024 * 1024)) - params+=" --group \"$group_name_a:$overhead_adjusted_size\"" - params+=" --group \"$group_name_b:$overhead_adjusted_size\"" - params+=" --virtual-ab" - ;; - "AB") - overhead_adjusted_size=$(((device_size / 2) - 10 * 1024 * 1024)) - params+=" --group \"$group_name_a:$overhead_adjusted_size\"" - params+=" --group \"$group_name_b:$overhead_adjusted_size\"" - ;; - *) - overhead_adjusted_size=$((device_size - 10 * 1024 * 1024)) - params+=" --group \"$group_name:$overhead_adjusted_size\"" - ;; - esac - - for img_file in "${img_files[@]}"; do - local base_name=$(basename "$img_file") - local partition_name=${base_name%.*} - local partition_size=$(stat -c%s "$img_file") - local file_type=$(recognize_file_type "$img_file") - if [[ "$file_type" == "ext" || "$file_type" == "f2fs" ]]; then - local read_write_attr="none" - else - local read_write_attr="readonly" - fi - - case "$partition_type" in - "VAB") - params+=" --partition \"${partition_name}_a:$read_write_attr:$partition_size:$group_name_a\"" - params+=" --image \"${partition_name}_a=$img_file\"" - params+=" --partition \"${partition_name}_b:$read_write_attr:0:$group_name_b\"" - ;; - "AB") - params+=" --partition \"${partition_name}_a:$read_write_attr:$partition_size:$group_name_a\"" - params+=" --image \"${partition_name}_a=$img_file\"" - params+=" --partition \"${partition_name}_b:$read_write_attr:$partition_size:$group_name_b\"" - params+=" --image \"${partition_name}_b=$img_file\"" - ;; - *) - params+=" --partition \"$partition_name:$read_write_attr:$partition_size:$group_name\"" - params+=" --image \"$partition_name=$img_file\"" - ;; - esac - done - - echo -e "Packaging SUPER partition, please wait...\n..................\n..................\n.................." - mkdir -p "$WORK_DIR/$current_workspace/Repacked" - local start=$(python3 "$TOOL_DIR/get_right_time.py") - - eval "$TOOL_DIR/lpmake \ + local partition_type=$1 + local is_sparse=$2 + local img_files=() + + # 筛选出文件类型为 ext, f2fs, erofs 的文件 + for file in "$WORK_DIR/$current_workspace/Extracted-files/super/"*.img; do + file_type=$(recognize_file_type "$file") + if [[ "$file_type" == "ext" || "$file_type" == "f2fs" || "$file_type" == "erofs" ]]; then + img_files+=("$file") + fi + done + + # 计算 super 文件夹中所有文件的总字节数 + local total_size=0 + for img_file in "${img_files[@]}"; do + file_type=$(recognize_file_type "$img_file") + # 计算文件的大小 + file_size_bytes=$(stat -c%s "$img_file") + total_size=$((total_size + file_size_bytes)) + done + remainder=$((total_size % 4096)) + if [ $remainder -ne 0 ]; then + total_size=$((total_size + 4096 - remainder)) + fi + + # 定义额外的空间大小 + local extra_space=$((100 * 1024 * 1024 * 1024 / 100)) + + # 根据分区类型调整 total_size 的值 + case "$partition_type" in + "AB") + total_size=$(((total_size + extra_space) * 2)) + ;; + "OnlyA" | "VAB") + total_size=$((total_size + extra_space)) + ;; + esac + clear + + while true; do + local original_super_size=$(cat "$WORK_DIR/$current_workspace/Extracted-files/config/original_super_size" 2>/dev/null) + # 根据是否能读取到 original_super_size 文件的值,显示不同的选项 + echo -e "" + echo -n " [1] 9126805504 [2] $total_size --automatic calculation" + if [ -n "$original_super_size" ]; then + echo -e " [3] [31m$original_super_size [0m --original size\n" + else + echo -e "\n" + fi + + echo -e " [C] Custom input [Q] Return to workspace menu\n" + echo -n " please select the package size:" + read device_size_option + + # 根据用户的选择,设置 device_size 的值 + case "$device_size_option" in + 1) + device_size=9126805504 + if ((device_size < total_size)); then + echo " is smaller than the automatically calculated size, please execute other options." + continue + fi + break + ;; + 2) + device_size=$total_size + if ((device_size < total_size)); then + echo " is smaller than the automatically calculated size, please execute other options." + continue + fi + break + ;; + 3) + if [ -n "$original_super_size" ]; then + device_size=$original_super_size + if ((device_size < total_size)); then + echo " is smaller than the automatically calculated size, please execute other options." + continue + fi + break + else + clear + echo -e "\n Invalid selection, please re-enter." + fi + ;; + C | c) + clear + while true; do + echo -e "\n Tip: The automatically calculated size is $total_size\n" + echo -e " [Q] Return to the workspace menu\n" + echo -n " please enter a custom size:" + read device_size + + if [[ "$device_size" =~ ^[0-9]+$ ]]; then + # 如果输入值小于 total_size,要求重新输入 + if ((device_size < total_size)); then + clear + echo -e "\n The value entered is less than the automatically calculated size, please re-enter" + else + if ((device_size % 4096 == 0)); then + break + else + clear + echo -e "\nThe entered value is not a multiple of 4096 bytes, please re-enter" + fi + fi + elif [ "${device_size,,}" = "q" ]; then + return + else + clear + echo -e "\n Invalid input, please re-enter" + fi + done + break + ;; + Q | q) + echo " has canceled the packaging operation and returned to the work domain menu." + return + ;; + *) + clear + echo -e "\n Invalid selection, please re-enter." + ;; + esac + done + + clear # 清除屏幕 + echo -e "\n" + + # 其他参数 + local metadata_size="65536" + local block_size="4096" + local super_name="super" + local group_name="qti_dynamic_partitions" + local group_name_a="${group_name}_a" + local group_name_b="${group_name}_b" + + # 根据分区类型设置 metadata_slots 的值 + case "$partition_type" in + "AB" | "VAB") + metadata_slots="3" + ;; + *) + metadata_slots="2" + ;; + esac + + # 初始化参数字符串 + local params="" + + case "$is_sparse" in + "yes") + params+="--sparse" + ;; + esac + + case "$partition_type" in + "VAB") + overhead_adjusted_size=$((device_size - 10 * 1024 * 1024)) + params+=" --group \"$group_name_a:$overhead_adjusted_size\"" + params+=" --group \"$group_name_b:$overhead_adjusted_size\"" + params+=" --virtual-ab" + ;; + "AB") + overhead_adjusted_size=$(((device_size / 2) - 10 * 1024 * 1024)) + params+=" --group \"$group_name_a:$overhead_adjusted_size\"" + params+=" --group \"$group_name_b:$overhead_adjusted_size\"" + ;; + *) + overhead_adjusted_size=$((device_size - 10 * 1024 * 1024)) + params+=" --group \"$group_name:$overhead_adjusted_size\"" + ;; + esac + + # 计算每个分区所拥有的大小 + for img_file in "${img_files[@]}"; do + # 从文件路径中提取文件名 + local base_name=$(basename "$img_file") + local partition_name=${base_name%.*} + + # 计算文件的大小 + local partition_size=$(stat -c%s "$img_file") + + # 根据文件系统类型设置 read-write 属性 + local file_type=$(recognize_file_type "$img_file") + if [[ "$file_type" == "ext" || "$file_type" == "f2fs" ]]; then + local read_write_attr="none" + else + local read_write_attr="readonly" + fi + + # 根据分区类型设置分区组名参数 + case "$partition_type" in + "VAB") + params+=" --partition \"${partition_name}_a:$read_write_attr:$partition_size:$group_name_a\"" + params+=" --image \"${partition_name}_a=$img_file\"" + params+=" --partition \"${partition_name}_b:$read_write_attr:0:$group_name_b\"" + ;; + "AB") + params+=" --partition \"${partition_name}_a:$read_write_attr:$partition_size:$group_name_a\"" + params+=" --image \"${partition_name}_a=$img_file\"" + params+=" --partition \"${partition_name}_b:$read_write_attr:$partition_size:$group_name_b\"" + params+=" --image \"${partition_name}_b=$img_file\"" + ;; + *) + params+=" --partition \"$partition_name:$read_write_attr:$partition_size:$group_name\"" + params+=" --image \"$partition_name=$img_file\"" + ;; + esac + done + + echo -e "Packaging SUPER partition, waiting...\n.............\n............ ....\n............." + mkdir -p "$WORK_DIR/$current_workspace/Repacked" + local start=$(python3 "$TOOL_DIR/get_right_time.py") + + eval "$TOOL_DIR/lpmake \ --device-size \"$device_size\" \ --metadata-size \"$metadata_size\" \ --metadata-slots \"$metadata_slots\" \ @@ -204,158 +222,181 @@ function create_super_img { --super-name \"$super_name\" \ --force-full-image \ $params \ - --output \"$WORK_DIR/$current_workspace/Repacked/super.img\"" > /dev/null 2>&1 + --output \"$WORK_DIR/$current_workspace/Repacked/super.img\"" >/dev/null 2>&1 - echo "SUPER partition packaged" + echo "SUPER partition has been packed" - local end=$(python3 "$TOOL_DIR/get_right_time.py") - local runtime=$(echo "scale=3; if ($end - $start < 1) print 0; $end - $start" | bc) - echo "Time taken: $runtime seconds" + local end=$(python3 "$TOOL_DIR/get_right_time.py") + local runtime=$(echo "scale=3; if ($end - $start < 1) print 0; $end - $start" | bc) + echo "Time consuming: $runtime seconds" - echo -n "Press any key to return to the workspace menu..." - read -n 1 + echo -n "Press any key to return to the workspace menu..." + read -n 1 } function package_super_image { - echo -e "\n" - mkdir -p "$WORK_DIR/$current_workspace/Extracted-files/super" - - # Get all image files - img_files=("$WORK_DIR/$current_workspace/Extracted-files/super/"*.img) - real_img_files=() - for file in "${img_files[@]}"; do - if [ -e "$file" ]; then - real_img_files+=("$file") - fi - done - - # Check if there are enough image files - if [ ${#real_img_files[@]} -lt 2 ]; then - echo " The SUPER directory should contain at least two image files." - read -n 1 -s -r -p " Press any key to return to the workspace menu..." - return - fi - - # Check for forbidden files - forbidden_files=() - for file in "${real_img_files[@]}"; do - filename=$(basename "$file") - if ! grep -q -x "$filename" "$TOOL_DIR/super_search"; then - forbidden_files+=("$file") - fi - done - - # If there are forbidden files, display an error message and return - if [ ${#forbidden_files[@]} -gt 0 ]; then - echo -e " Forbidden partition files for packaging:\n" - for file in "${forbidden_files[@]}"; do - echo -e " \e[33m$(basename "$file")\e[0m\n" - done - read -n 1 -s -r -p " Press any key to return to the workspace menu..." - return - fi - - # Ask the user if they want to package - while true; do - # List all subfiles in the target directory, each file has a number in front - echo -e " SUPER partitions to be packaged:\n" - for i in "${!img_files[@]}"; do - file_name=$(basename "${img_files[$i]}") - printf " \e[96m[%02d] %s\e[0m\n\n" $((i+1)) "$file_name" - done - - echo -e "\n [Y] Package SUPER " "[N] Return to workspace menu\n" - echo -n " Choose the function you want to execute:" - read is_pack - clear - - # Handle the user's choice - case "$is_pack" in - Y|y) - # The user chose to package, ask for partition type and packaging method - while true; do - echo -e "\n [1] OnlyA Dynamic Partition " "[2] AB Dynamic Partition " "[3] VAB Dynamic Partition\n" - echo -e " [Q] Return to workspace menu\n" - echo -n " Please choose your partition type:" - read partition_type - - if [ "${partition_type,,}" = "q" ]; then # Convert user input to lowercase - echo " Partition type selection cancelled, returning to workspace menu." - return - fi - clear - - # Handle the user's chosen partition type - case "$partition_type" in - 1|2|3) - # The user chose a valid partition type, ask for packaging method - while true; do - echo -e "\n [1] Sparse " "[2] Non-sparse\n" - echo -e " [Q] Return to workspace menu\n" - echo -n " Please choose the packaging method:" - read is_sparse - - if [ "${is_sparse,,}" = "q" ]; then - echo " Selection cancelled, returning to workspace menu." - return - fi - - # Handle the user's chosen packaging method - case "$is_sparse" in - 1|2) - break - ;; - *) - clear - echo -e "\n Invalid selection, please re-enter." - ;; - esac - done - break - ;; - *) - clear - echo -e "\n Invalid selection, please re-enter." - # If the user input is invalid, continue the loop - ;; - esac - done - break - ;; - N|n) - echo "Packaging operation cancelled, returning to upper menu." - return - ;; - *) - clear - echo -e "\n Invalid selection, please re-enter." - # If the user input is invalid, continue the loop - ;; - esac - done - - # Add your code here, handle the part after the user input - case "$partition_type-$is_sparse" in - 1-1) - create_super_img "OnlyA" "yes" - ;; - 1-2) - create_super_img "OnlyA" "no" - ;; - 2-1) - create_super_img "AB" "yes" - ;; - 2-2) - create_super_img "AB" "no" - ;; - 3-1) - create_super_img "VAB" "yes" - ;; - 3-2) - create_super_img "VAB" "no" - ;; - *) - echo " Invalid selection, please re-enter." - ;; - esac + keep_clean + mkdir -p "$WORK_DIR/$current_workspace/Extracted-files/super" + # 检测 $WORK_DIR/$current_workspace/Repacked 内的 img 文件 + detected_files=() + while IFS= read -r line; do + line=$(echo "$line" | xargs) # Remove leading and trailing spaces + if [ -e "$WORK_DIR/$current_workspace/Repacked/$line" ]; then + detected_files+=("$WORK_DIR/$current_workspace/Repacked/$line") + fi + done < <(grep -oP '^[^#]+' "$TOOL_DIR/super_search") + # 询问是否移动到 super 文件夹 + if [ ${#detected_files[@]} -gt 0 ]; then + while true; do + echo -e "\n 侦测到已打包的子分区:\n" + for file in "${detected_files[@]}"; do + echo -e " \e[95m☑ $(basename "$file")\e[0m\n" + done + echo -e "\n Do you want to move these files to the directory to be packaged?" + echo -e "\n [1] Move [2] Don't move\n" + echo -n " choose your operation:" + read move_files + clear + if [[ "$move_files" = "1" ]]; then + for file in "${detected_files[@]}"; do + mv "$file" "$WORK_DIR/$current_workspace/Extracted-files/super/" + done + break + elif [[ "$move_files" = "2" ]]; then + break + else + echo -e "\nInvalid selection, please re-enter.\n" + fi + done + fi + # 获取所有镜像文件 + shopt -s nullglob + img_files=("$WORK_DIR/$current_workspace/Extracted-files/super/"*.img) + shopt -u nullglob + real_img_files=() + for file in "${img_files[@]}"; do + if [ -e "$file" ]; then + real_img_files+=("$file") + fi + done + # 检查是否有足够的镜像文件 + if [ ${#real_img_files[@]} -lt 2 ]; then + echo -e "\n The SUPER directory needs to contain at least two image files." + read -n 1 -s -r -p " Press any key to return to the workspace menu..." + return + fi + # 检查是否有被禁止的文件 + forbidden_files=() + for file in "${real_img_files[@]}"; do + filename=$(basename "$file") + if ! grep -q -x "$filename" "$TOOL_DIR/super_search"; then + forbidden_files+=("$file") + fi + done + # 如果有被禁止的文件,显示错误信息并返回 + if [ ${#forbidden_files[@]} -gt 0 ]; then + echo -e "\n Refusal to execute, the following files are prohibited from merging\n" + for file in "${forbidden_files[@]}"; do + echo -e " u001b[33m☒ $(basename "$file")u001b[0m\n" + done + read -n 1 -s -r -p " Press any key to return to the workspace menu..." + return + fi + # 询问用户是否要打包 + while true; do + # 列出目标目录下的所有子文件,每个文件前面都有一个编号 + echo -e "\n Subpartition of the directory to be packed:\n" + for i in "${!img_files[@]}"; do + file_name=$(basename "${img_files[$i]}") + printf " \e[96m[%02d] %s\e[0m\n\n" $((i + 1)) "$file_name" + done + echo -e "\n [1] Start packaging [Q] Return to workspace menu\n" + echo -n " selects the function you want to perform:" + read is_pack + is_pack=$(echo "$is_pack" | tr '[:upper:]' '[:lower:]') + clear + # 处理用户的选择 + case "$is_pack" in + 1) + # 用户选择了打包,询问分区类型和打包方式 + while true; do + echo -e "\n [1] OnlyA dynamic partition [2] AB dynamic partition [3] VAB dynamic partition\n" + echo -e " [Q] Return to the workspace menu\n" + echo -n " please select your partition type:" + read partition_type + partition_type=$(echo "$partition_type" | tr '[:upper:]' '[:lower:]') + if [ "$partition_type" = "q" ]; then + echo " has deselected the partition type and returned to the workspace menu." + return + fi + clear + # 处理用户选择的分区类型 + case "$partition_type" in + 1 | 2 | 3) + # 用户选择了有效的分区类型,询问打包方式 + while true; do + echo -e "\n [1] sparse [2] non-sparse\n" + echo -e " [Q] Return to the workspace menu\n" + echo -n " please select the packaging method:" + read is_sparse + is_sparse=$(echo "$is_sparse" | tr '[:upper:]' '[:lower:]') + if [ "$is_sparse" = "q" ]; then + echo " has been deselected, returning to the workspace menu." + return + fi + # 处理用户选择的打包方式 + case "$is_sparse" in + 1 | 2) + break + ;; + *) + clear + echo -e "\n Invalid selection, please re-enter." + ;; + esac + done + break + ;; + *) + clear + echo -e "\n Invalid selection, please re-enter." + ;; + esac + done + break + ;; + q) + echo "The packaging operation has been canceled and returns to the previous menu." + return + ;; + *) + clear + echo -e "\n Invalid selection, please re-enter." + ;; + esac + done + # 在这里添加你的代码,处理用户输入后面的部分 + case "$partition_type-$is_sparse" in + 1-1) + create_super_img "OnlyA" "yes" + ;; + 1-2) + create_super_img "OnlyA" "no" + ;; + 2-1) + create_super_img "AB" "yes" + ;; + 2-2) + create_super_img "AB" "no" + ;; + 3-1) + create_super_img "VAB" "yes" + ;; + 3-2) + create_super_img "VAB" "no" + ;; + *) + echo " Invalid selection, please re-enter." + ;; + esac } diff --git a/resources/module_codes/en/rebuild_rom.sh b/resources/module_codes/en/rebuild_rom.sh old mode 100755 new mode 100644 index 8a592d7..546afdb --- a/resources/module_codes/en/rebuild_rom.sh +++ b/resources/module_codes/en/rebuild_rom.sh @@ -1,195 +1,199 @@ function rebuild_rom { - keep_clean - mkdir -p "$WORK_DIR/$current_workspace/Ready-to-flash/images" - while true; do - echo -e "\n Please place the partition files to be flashed in the Ready-to-flash/images folder of the selected workspace directory" - echo -e "\n [1] Fastboot(d) Rom " "[2] Odin Rom " "[3] Cancel packaging\n" - echo -n " Choose your action: " - read main_choice - if [[ "$main_choice" == "1" || "$main_choice" == "2" || "$main_choice" == "3" ]]; then - break - else - clear - echo -e "\n Invalid option, please re-enter." - fi - done - if [[ "$main_choice" == "1" ]]; then - clear - while true; do - echo -e "\n [Q] Return to workspace menu\n" - echo -n " Enter your device model: " - read device_model - device_model=$(echo "$device_model" | tr '[:upper:]' '[:lower:]') - if [[ "$device_model" == "Q" || "$device_model" == "q" ]]; then - echo " Packaging canceled, returning to workspace menu." - return - elif [[ "$device_model" =~ ^[0-9a-zA-Z]+$ ]]; then - break - else - clear - echo -e "\n Invalid model, please re-enter." - fi - done - sed "s/set \"right_device=\w*\"/set \"right_device=$device_model\"/g" "$TOOL_DIR/flash_tool/FlashROM.bat" > "$TOOL_DIR/flash_tool/StartFlash.bat" - clear - while true; do - echo -e "\n [1] Split compression " "[2] Full compression " "[Q] Return to workspace menu\n" - echo -n " Enter compression method: " - read compression_choice - if [[ "$compression_choice" == "1" || "$compression_choice" == "2" || "$compression_choice" == "Q" || "$compression_choice" == "q" ]]; then - break - else - clear - echo -e "\n Invalid option, please re-enter." - fi - done - clear - if [[ "$compression_choice" == "1" ]]; then - while true; do - echo -e "\n [Q] Return to workspace menu\n" - echo -n " Enter volume size: " - read volume_size - if [[ "$volume_size" =~ ^[0-9]+[mgkMGK]$ || "$volume_size" == "Q" || "$volume_size" == "q" ]]; then - break - else - clear - echo -e "\n Invalid volume size, please re-enter." - fi - done - if [[ "$volume_size" == "Q" || "$volume_size" == "q" ]]; then - echo " Packaging canceled, returning to workspace menu." - return - fi - clear - start=$(python3 "$TOOL_DIR/get_right_time.py") - echo -e "\nStarting packaging..." - find "$WORK_DIR/$current_workspace/Ready-to-flash" -mindepth 1 -maxdepth 1 -not -name 'images' -exec rm -rf {} + - "$TOOL_DIR/7z" a -tzip -v${volume_size} "$WORK_DIR/$current_workspace/Ready-to-flash/${current_workspace}.zip" "$TOOL_DIR/flash_tool/bin" "$TOOL_DIR/flash_tool/StartFlash.bat" "$WORK_DIR/$current_workspace/Ready-to-flash/images" -y -mx1 - echo -e "Fastboot(d) Rom packaging completed" - end=$(python3 "$TOOL_DIR/get_right_time.py") - runtime=$(echo "scale=3; if ($end - $start < 1) print 0; $end - $start" | bc) - echo "Time taken: $runtime seconds" - elif [[ "$compression_choice" == "2" ]]; then - start=$(python3 "$TOOL_DIR/get_right_time.py") - clear - echo -e "\nStarting packaging..." - find "$WORK_DIR/$current_workspace/Ready-to-flash" -mindepth 1 -maxdepth 1 -not -name 'images' -exec rm -rf {} + - "$TOOL_DIR/7z" a -tzip "$WORK_DIR/$current_workspace/Ready-to-flash/${current_workspace}.zip" "$TOOL_DIR/flash_tool/bin" "$TOOL_DIR/flash_tool/StartFlash.bat" "$WORK_DIR/$current_workspace/Ready-to-flash/images" -y -mx1 - echo -e "Fastboot(d) Rom packaging completed" - end=$(python3 "$TOOL_DIR/get_right_time.py") - runtime=$(echo "scale=3; if ($end - $start < 1) print 0; $end - $start" | bc) - echo "Time taken: $runtime seconds" - else - echo " Packaging canceled, returning to workspace menu." - return - fi - echo -n "Press any key to return to workspace menu..." - read -n 1 - elif [[ "$main_choice" == "2" ]]; then - clear - BASE_PATH="$WORK_DIR/$current_workspace/Ready-to-flash/images" - AP_FILES=() - CP_FILES=() - BL_FILES=() - CSC_FILES=() - if [[ -f "$BASE_PATH/modem.bin" ]]; then - while true; do - echo -e "\n Does your device have a separate baseband partition?" - echo -e "\n [1] Yes " "[2] No\n" - echo -n " Choose your action: " - read baseband_choice + keep_clean + mkdir -p "$WORK_DIR/$current_workspace/Ready-to-flash/images" + while true; do + echo -e "\n Please put the partition file to be flashed into the Ready-to-flash/images folder in the selected working domain directory" + echo -e "\n [1] Fastboot(d) Rom " "[2] Odin Rom " "[Q] Unpack\n" - if [[ "$baseband_choice" == "1" || "$baseband_choice" == "2" ]]; then - break - else - clear - echo -e "\n Invalid option, please try again." - fi - done - else - baseband_choice="2" - fi - clear - # Check if .pit file exists - if compgen -G "$BASE_PATH/*.pit" > /dev/null; then - while true; do - echo -e "\n Does your device need to retain data?" - echo -e "\n [1] Yes " "[2] No\n" - echo -n " Choose your action: " - read retain_data_choice + # 检查是否有 img 文件 + if compgen -G "$WORK_DIR/$current_workspace/Repacked/*.img" >/dev/null; then + echo -e " [M] Move easily\n" + fi - if [[ "$retain_data_choice" == "1" || "$retain_data_choice" == "2" ]]; then - break - else - clear - echo -e "\n Invalid option, please try again." - fi - done - else - retain_data_choice="2" - fi + echo -n " choose your operation:" + read main_choice + main_choice=$(echo "$main_choice" | tr '[:upper:]' '[:lower:]') + if [[ "$main_choice" == "1" || "$main_choice" == "2" || "$main_choice" == "q" || "$main_choice" == "m" ]]; then + break + else + clear + echo -e "\n Invalid option, please re-enter." + fi + done - clear - echo -e "\nStarting to package Odin Rom..." + if [[ "$main_choice" == "1" ]]; then + clear + while true; do + echo -e "\n [Q] Return to workspace menu\n" + echo -n " please enter your model:" + read device_model + device_model=$(echo "$device_model" | tr '[:upper:]' '[:lower:]') + if [[ "$device_model" == "q" ]]; then + echo " cancels packaging and returns to the work domain menu." + return + elif [[ "$device_model" =~ ^[0-9a-zA-Z]+$ ]]; then + break + else + clear + echo -e "\n Impossible model, please re-enter." + fi + done + sed "s/set \"right_device=\w*\"/set \"right_device=$device_model\"/g" "$TOOL_DIR/flash_tool/FlashROM.bat" >"$TOOL_DIR/flash_tool/StartFlash.bat" + clear + while true; do + echo -e "\n [1] Volume compression " "[2] Full compression " "[Q] Return to workspace menu\n" + echo -n " please enter the compression method:" + read compression_choice + if [[ "$compression_choice" == "1" || "$compression_choice" == "2" || "$compression_choice" == "q" ]]; then + break + else + clear + echo -e "\n Invalid option, please re-enter." + fi + done + clear + if [[ "$compression_choice" == "1" ]]; then + while true; do + echo -e "\n [Q] Return to workspace menu\n" + echo -n " please enter the volume size:" + read volume_size + if [[ "$volume_size" =~ ^[0-9]+[mgkMGK]$ || "$volume_size" == "q" ]]; then + break + else + clear + echo -e "\n Invalid volume size, please re-enter." + fi + done + if [[ "$volume_size" == "q" ]]; then + echo " cancels packaging and returns to the work domain menu." + return + fi + clear + start=$(python3 "$TOOL_DIR/get_right_time.py") + echo -e "\nStart packaging..." + find "$WORK_DIR/$current_workspace/Ready-to-flash" -mindepth 1 -maxdepth 1 -not -name 'images' -exec rm -rf {} + + "$TOOL_DIR/7z" a -tzip -v${volume_size} "$WORK_DIR/$current_workspace/Ready-to-flash/${current_workspace}.zip" "$TOOL_DIR/flash_tool/bin" "$TOOL_DIR/flash_tool/StartFlash.bat" "$WORK_DIR/$current_workspace/Ready-to-flash/images" -y -mx1 + echo -e "Fastboot(d) Rom packaging completed" + end=$(python3 "$TOOL_DIR/get_right_time.py") + runtime=$(echo "scale=3; if ($end - $start < 1) print 0; $end - $start" | bc) + echo "Time consuming: $runtime seconds" + elif [[ "$compression_choice" == "2" ]]; then + start=$(python3 "$TOOL_DIR/get_right_time.py") + clear + echo -e "\nStart packaging..." + find "$WORK_DIR/$current_workspace/Ready-to-flash" -mindepth 1 -maxdepth 1 -not -name 'images' -exec rm -rf {} + + "$TOOL_DIR/7z" a -tzip "$WORK_DIR/$current_workspace/Ready-to-flash/${current_workspace}.zip" "$TOOL_DIR/flash_tool/bin" "$TOOL_DIR/flash_tool/StartFlash.bat" "$WORK_DIR/$current_workspace/Ready-to-flash/images" -y -mx1 + echo -e "Fastboot(d) Rom packaging completed" + end=$(python3 "$TOOL_DIR/get_right_time.py") + runtime=$(echo "scale=3; if ($end - $start < 1) print 0; $end - $start" | bc) + echo "Time consuming: $runtime seconds" + else + echo " cancels packaging and returns to the work domain menu." + return + fi + echo -n "Press any key to return to the workspace menu..." + read -n 1 + elif [[ "$main_choice" == "2" ]]; then + clear + # 定义基础路径 + BASE_PATH="$WORK_DIR/$current_workspace/Ready-to-flash/images" + # 初始化空数组 + AP_FILES=() + CP_FILES=() + BL_FILES=() + CSC_FILES=() + # 检测是否存在 modem.bin 文件 + if [[ -f "$BASE_PATH/modem.bin" ]]; then + while true; do + echo -e "\n Does your device have a separate baseband partition?" + echo -e "\n [1] Yes " "[2] No\n" + echo -n " choose your operation:" + read baseband_choice + if [[ "$baseband_choice" == "1" || "$baseband_choice" == "2" ]]; then + break + else + clear + echo -e "\n Invalid option, please re-enter." + fi + done + else + baseband_choice="2" + fi + clear + # 检测是否存在 .pit 文件 + if compgen -G "$BASE_PATH/*.pit" >/dev/null; then + while true; do + echo -e "\n Does your device need to retain data?" + echo -e "\n [1] Yes " "[2] No\n" + echo -n " choose your operation:" + read retain_data_choice + if [[ "$retain_data_choice" == "1" || "$retain_data_choice" == "2" ]]; then + break + else + clear + echo -e "\n Invalid option, please re-enter." + fi + done + else + retain_data_choice="2" + fi + clear + echo -e "\nStart packaging Odin Rom..." + # 检查并添加文件到 AP_FILES 数组 + while IFS= read -r -d '' file; do + AP_FILES+=("$(basename "$file")") + done < <(find "$BASE_PATH" -maxdepth 1 \( -name "boot.img" -o -name "dtbo.img" -o -name "init_boot.img" -o -name "misc.bin" -o -name "persist.img" -o -name "recovery.img" -o -name "super.img" -o -name "vbmeta_system.img" -o -name "vendor_boot.img" -o -name "vm-bootsys.img" \) -print0) + # 检查并添加 modem.bin 文件到相应的数组 + while IFS= read -r -d '' file; do + if [[ "$baseband_choice" == "1" ]]; then + CP_FILES+=("$(basename "$file")") + else + AP_FILES+=("$(basename "$file")") + fi + done < <(find "$BASE_PATH" -maxdepth 1 -name "modem.bin" -print0) + # 检查并添加文件到 BL_FILES 数组 + while IFS= read -r -d '' file; do + BL_FILES+=("$(basename "$file")") + done < <(find "$BASE_PATH" -maxdepth 1 \( -name "vbmeta.img" -o -regex ".*\.\(elf\|mbn\|bin\|fv\|melf\)" \) ! -name "modem.bin" ! -name "misc.bin" -print0) - # Check and add files to AP_FILES array - while IFS= read -r -d '' file; do - AP_FILES+=("$(basename "$file")") - done < <(find "$BASE_PATH" -maxdepth 1 \( -name "boot.img" -o -name "dtbo.img" -o -name "init_boot.img" -o -name "misc.bin" -o -name "persist.img" -o -name "recovery.img" -o -name "super.img" -o -name "vbmeta_system.img" -o -name "vendor_boot.img" -o -name "vm-bootsys.img" \) -print0) + # 检查并添加文件到 CSC_FILES 数组 + while IFS= read -r -d '' file; do + if [[ "$retain_data_choice" == "1" ]]; then + # 如果选择保留数据,只添加 cache.img、optics.img 和 prism.img + if [[ "$(basename "$file")" == "cache.img" || "$(basename "$file")" == "optics.img" || "$(basename "$file")" == "prism.img" ]]; then + CSC_FILES+=("$(basename "$file")") + fi + else + # 否则,添加所有相关文件 + CSC_FILES+=("$(basename "$file")") + fi + done < <(find "$BASE_PATH" -maxdepth 1 \( -name "cache.img" -o -name "*.pit" -o -name "omr.img" -o -name "optics.img" -o -name "prism.img" \) -print0) + # 打包 AP 文件 + if [[ ${#AP_FILES[@]} -gt 0 ]]; then + "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/AP-${current_workspace}.tar" "${AP_FILES[@]/#/$BASE_PATH/}" + fi + # 打包 BL 文件 + if [[ ${#BL_FILES[@]} -gt 0 ]]; then + "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/BL-${current_workspace}.tar" "${BL_FILES[@]/#/$BASE_PATH/}" + fi + # 打包 CP 文件 + if [[ ${#CP_FILES[@]} -gt 0 ]]; then + "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/CP-${current_workspace}.tar" "${CP_FILES[@]/#/$BASE_PATH/}" + fi + # 打包 CSC 文件 + if [[ ${#CSC_FILES[@]} -gt 0 ]]; then + "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/CSC-${current_workspace}.tar" "${CSC_FILES[@]/#/$BASE_PATH/}" + fi + echo -e "Odin Rom packaging completed" + echo -n "Press any key to return to the workspace menu..." + read -n 1 - # Check and add modem.bin file to the appropriate array - while IFS= read -r -d '' file; do - if [[ "$baseband_choice" == "1" ]]; then - CP_FILES+=("$(basename "$file")") - else - AP_FILES+=("$(basename "$file")") - fi - done < <(find "$BASE_PATH" -maxdepth 1 -name "modem.bin" -print0) - - # Check and add files to BL_FILES array - while IFS= read -r -d '' file; do - BL_FILES+=("$(basename "$file")") - done < <(find "$BASE_PATH" -maxdepth 1 \( -name "vbmeta.img" -o -regex ".*\.\(elf\|mbn\|bin\|fv\|melf\)" \) ! -name "modem.bin" ! -name "misc.bin" -print0) - - # Check and add files to CSC_FILES array - while IFS= read -r -d '' file; do - if [[ "$retain_data_choice" == "1" ]]; then - # If retaining data, only add cache.img, optics.img, and prism.img - if [[ "$(basename "$file")" == "cache.img" || "$(basename "$file")" == "optics.img" || "$(basename "$file")" == "prism.img" ]]; then - CSC_FILES+=("$(basename "$file")") - fi - else - # Otherwise, add all relevant files - CSC_FILES+=("$(basename "$file")") - fi - done < <(find "$BASE_PATH" -maxdepth 1 \( -name "cache.img" -o -name "*.pit" -o -name "omr.img" -o -name "optics.img" -o -name "prism.img" \) -print0) - - # Package AP files - if [[ ${#AP_FILES[@]} -gt 0 ]]; then - "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/AP-${current_workspace}.tar" "${AP_FILES[@]/#/$BASE_PATH/}" - fi - - # Package BL files - if [[ ${#BL_FILES[@]} -gt 0 ]]; then - "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/BL-${current_workspace}.tar" "${BL_FILES[@]/#/$BASE_PATH/}" - fi - - # Package CP files - if [[ ${#CP_FILES[@]} -gt 0 ]]; then - "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/CP-${current_workspace}.tar" "${CP_FILES[@]/#/$BASE_PATH/}" - fi - - # Package CSC files - if [[ ${#CSC_FILES[@]} -gt 0 ]]; then - "$TOOL_DIR/7z" a -ttar -mx1 "$WORK_DIR/$current_workspace/Ready-to-flash/CSC-${current_workspace}.tar" "${CSC_FILES[@]/#/$BASE_PATH/}" - fi - - echo -e "Odin Rom packaging completed" - - echo -n "Press any key to return to the workspace menu..." - read -n 1 - - else - echo " Packaging canceled, returning to the workspace menu." - fi + elif [[ "$main_choice" == "m" ]]; then + clear + find "$WORK_DIR/$current_workspace/Repacked" -name '*.img' -exec mv {} "$WORK_DIR/$current_workspace/Ready-to-flash/images" \; + rebuild_rom + return + else + echo " cancels packaging and returns to the work domain menu." + fi }