Skip to content

Commit a9bc481

Browse files
committed
AIT: Final fixes before release
Signed-off-by: ravindu644 <droidcasts@protonmail.com>
1 parent edf738d commit a9bc481

3 files changed

Lines changed: 82 additions & 37 deletions

File tree

.bin/repack-erofs.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ case $FS_CHOICE in
591591

592592
mv "$OUTPUT_IMG.tmp" "$OUTPUT_IMG"
593593
echo -e "\n${GREEN}${BOLD}Successfully created EROFS image: $OUTPUT_IMG${RESET}"
594-
echo -e "${BLUE}Image size: $(stat -c %s "$OUTPUT_IMG" | numfmt --to=iec-i --suffix=B)${RESET}"
594+
echo -e "${BLUE}Image size: $(stat -c %s "$OUTPUT_IMG" | numfmt --to=iec-i --suffix=B)${RESET}\n"
595595
;;
596596

597597
ext4)
@@ -677,7 +677,7 @@ case $FS_CHOICE in
677677
[ -n "$SUDO_USER" ] && chown "$SUDO_USER:$SUDO_USER" "$OUTPUT_IMG"
678678

679679
echo -e "\n${GREEN}${BOLD}Successfully created EXT4 image: $OUTPUT_IMG${RESET}"
680-
echo -e "${BLUE}Image size: $(stat -c %s "$OUTPUT_IMG" | numfmt --to=iec-i --suffix=B)${RESET}"
680+
echo -e "${BLUE}Image size: $(stat -c %s "$OUTPUT_IMG" | numfmt --to=iec-i --suffix=B)${RESET}\n"
681681
;;
682682

683683
*)

.bin/super-tools.sh

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -262,36 +262,38 @@ run_repack() {
262262
echo -e "\n${GREEN}${BOLD}Repack successful!${RESET}"
263263
}
264264

265-
266-
# --- START OF NEW, ROBUST MAIN EXECUTION LOGIC ---
265+
# --- MAIN EXECUTION LOGIC ---
267266

268267
# Initialize variables for arguments and flags
269268
ACTION=""
270-
ARGS=()
269+
POSITIONAL_ARGS=()
271270
INTERACTIVE_MODE=true
272271

273-
# Parse arguments and flags
272+
# This loop correctly separates global flags from positional arguments,
273+
# regardless of their order.
274274
while (( "$#" )); do
275275
case "$1" in
276276
--no-banner)
277277
INTERACTIVE_MODE=false
278-
shift
278+
shift # Consume the flag
279279
;;
280280
-*)
281-
echo -e "${RED}Error: Unknown option $1${RESET}" >&2
281+
echo -e "${RED}Error: Unknown global option $1${RESET}" >&2
282282
print_usage
283283
;;
284284
*)
285-
if [ -z "$ACTION" ]; then
286-
ACTION="$1"
287-
else
288-
ARGS+=("$1")
289-
fi
290-
shift
285+
# Not a flag, so it must be a positional argument.
286+
POSITIONAL_ARGS+=("$1")
287+
shift # Consume the argument
291288
;;
292289
esac
293290
done
294291

292+
# Now, POSITIONAL_ARGS contains only the action and its own arguments
293+
ACTION=${POSITIONAL_ARGS[0]:-}
294+
# Use array slicing to get the true arguments for the action
295+
ACTION_ARGS=("${POSITIONAL_ARGS[@]:1}")
296+
295297
# Validate action
296298
if [ "$ACTION" != "unpack" ] && [ "$ACTION" != "repack" ]; then
297299
if [ "$INTERACTIVE_MODE" = true ]; then print_banner; fi
@@ -300,12 +302,12 @@ if [ "$ACTION" != "unpack" ] && [ "$ACTION" != "repack" ]; then
300302
fi
301303

302304
# Validate argument counts for each action
303-
if [ "$ACTION" == "unpack" ] && [ "${#ARGS[@]}" -ne 2 ]; then
305+
if [ "$ACTION" == "unpack" ] && [ "${#ACTION_ARGS[@]}" -ne 2 ]; then
304306
if [ "$INTERACTIVE_MODE" = true ]; then print_banner; fi
305307
echo -e "${RED}Error: 'unpack' requires exactly 2 arguments: <super_image> and <output_directory>.${RESET}"
306308
print_usage
307309
fi
308-
if [ "$ACTION" == "repack" ] && { [ "${#ARGS[@]}" -ne 2 ] && [ "${#ARGS[@]}" -ne 3 ]; }; then
310+
if [ "$ACTION" == "repack" ] && { [ "${#ACTION_ARGS[@]}" -ne 2 ] && [ "${#ACTION_ARGS[@]}" -ne 3 ]; }; then
309311
if [ "$INTERACTIVE_MODE" = true ]; then print_banner; fi
310312
echo -e "${RED}Error: 'repack' requires 2 arguments with an optional '--raw' flag.${RESET}"
311313
print_usage
@@ -319,10 +321,10 @@ check_dependencies
319321

320322
case "$ACTION" in
321323
unpack)
322-
run_unpack "${ARGS[0]}" "${ARGS[1]}"
324+
run_unpack "${ACTION_ARGS[@]}"
323325
;;
324326
repack)
325-
run_repack "${ARGS[0]}" "${ARGS[1]}" "${ARGS[2]}"
327+
run_repack "${ACTION_ARGS[@]}"
326328
;;
327329
esac
328330

android_image_tools.sh

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ run_super_unpack_interactive() {
615615
read -rp $'\nPress Enter to return...'
616616
}
617617

618-
# --- MODIFIED: run_super_create_config_interactive now handles percentage overhead ---
618+
# --- MODIFIED: run_super_create_config_interactive now asks for logging preference ---
619619
run_super_create_config_interactive() {
620620

621621
local project_dir metadata_dir final_config_file
@@ -700,12 +700,26 @@ run_super_create_config_interactive() {
700700
done
701701
done
702702

703+
clear; print_banner
704+
echo -e "\n${BOLD}Final Configuration Step${RESET}"
705+
select_option "Enable detailed, real-time logs during super repack?" \
706+
"Yes (Recommended for debugging)" \
707+
"No (Show a clean spinner)"
708+
709+
local enable_verbose_logs="false"
710+
if [ "$AIT_CHOICE_INDEX" -eq 0 ]; then
711+
enable_verbose_logs="true"
712+
fi
713+
703714
{
704715
echo "# --- Universal Repack Configuration ---"
705716
echo "# Project: $(basename "$project_dir")"
706717
echo "# Generated on $(date)"
707718
echo "# WARNING: Do NOT edit this file manually unless you know what you are doing."
708719
echo ""
720+
echo "# --- Repack Behavior Settings ---"
721+
echo "ENABLE_VERBOSE_LOGS=${enable_verbose_logs}"
722+
echo ""
709723
echo "# --- Super Partition Metadata ---"
710724
grep -v -E '^(#|$)' "${metadata_dir}/super_repack_info.txt"
711725
echo ""
@@ -733,7 +747,7 @@ run_super_create_config_interactive() {
733747
read -rp $'\nPress Enter to return...'
734748
}
735749

736-
# --- MODIFIED: run_super_repack_interactive now passes percentage overhead ---
750+
# --- MODIFIED: run_super_repack_interactive now supports conditional logging ---
737751
run_super_repack_interactive() {
738752

739753
local project_dir metadata_dir part_config_file logical_dir extracted_dir
@@ -773,7 +787,6 @@ run_super_repack_interactive() {
773787
set +e # Disable exit on error for the loop
774788
local total=$(echo "$PARTITION_LIST" | wc -w)
775789
local current=0
776-
local spinner=( '' '' '' '' '' '' '' '' '' '' )
777790
local all_successful=true
778791

779792
echo -e "\n${BLUE}--- Repacking content into logical partitions ---${RESET}"
@@ -794,23 +807,40 @@ run_super_repack_interactive() {
794807
fi
795808
fi
796809

797-
bash "$REPACK_SCRIPT_PATH" "${project_dir}/extracted_content/${part_name}" "${logical_dir}/${part_name}.img" "${repack_args[@]}" --no-banner >/dev/null 2>&1 &
798-
local pid=$!
799-
800-
while kill -0 $pid 2>/dev/null; do
801-
echo -ne "\r\033[K${YELLOW}(${current}/${total}) Repacking: ${BOLD}${part_name}${RESET}... ${spinner[$((spin++ % 10))]}"
802-
sleep 0.1
803-
done
804-
805-
wait $pid
806-
if [ $? -ne 0 ]; then
807-
echo -e "\r\033[K${RED}(${current}/${total}) FAILED to repack: ${BOLD}${part_name}${RESET} [✗]"
808-
all_successful=false
809-
break
810+
# Use a default of 'false' if the variable isn't in the config file
811+
if [ "${ENABLE_VERBOSE_LOGS:-false}" == "true" ]; then
812+
# --- VERBOSE LOGGING PATH ---
813+
echo -e "\n${YELLOW}--- (${current}/${total}) Repacking: ${BOLD}${part_name}${RESET} ---${RESET}"
814+
bash "$REPACK_SCRIPT_PATH" "${project_dir}/extracted_content/${part_name}" "${logical_dir}/${part_name}.img" "${repack_args[@]}" --no-banner
815+
816+
if [ $? -ne 0 ]; then
817+
echo -e "${RED}--- [✗] FAILED: ${BOLD}${part_name}${RESET} repack failed. See logs above. ---${RESET}"
818+
all_successful=false
819+
break
820+
else
821+
echo -e "${GREEN}--- [✓] Success: ${BOLD}${part_name}${RESET} repacked ---${RESET}"
822+
fi
810823
else
811-
echo -e "\r\033[K${GREEN}(${current}/${total}) Repacked: ${BOLD}${part_name}${RESET} [✓]"
824+
# --- SILENT SPINNER PATH ---
825+
bash "$REPACK_SCRIPT_PATH" "${project_dir}/extracted_content/${part_name}" "${logical_dir}/${part_name}.img" "${repack_args[@]}" --no-banner >/dev/null 2>&1 &
826+
local pid=$!
827+
local spin=0
828+
local spinner=( '' '' '' '' '' '' '' '' '' '' )
829+
830+
while kill -0 $pid 2>/dev/null; do
831+
echo -ne "\r\033[K${YELLOW}(${current}/${total}) Repacking: ${BOLD}${part_name}${RESET}... ${spinner[$((spin++ % 10))]}"
832+
sleep 0.1
833+
done
834+
835+
wait $pid
836+
if [ $? -ne 0 ]; then
837+
echo -e "\r\033[K${RED}(${current}/${total}) FAILED to repack: ${BOLD}${part_name}${RESET} [✗]"
838+
all_successful=false
839+
break
840+
else
841+
echo -e "\r\033[K${GREEN}(${current}/${total}) Repacked: ${BOLD}${part_name}${RESET} [✓]"
842+
fi
812843
fi
813-
814844
done
815845

816846
if [ "$all_successful" = false ]; then
@@ -820,10 +850,23 @@ run_super_repack_interactive() {
820850
fi
821851

822852
echo -e "\n${BLUE}--- Assembling final super image ---${RESET}"
853+
854+
set -e
823855
bash "$SUPER_SCRIPT_PATH" repack "$logical_dir" "$output_image" "$sparse_flag" --no-banner
824856

825-
rm -rf "$logical_dir"
857+
# Check the exit code of the last command explicitly
858+
if [ $? -ne 0 ]; then
859+
# This block will now correctly execute if super-tools.sh fails
860+
echo -e "\n${RED}${BOLD}FATAL: Failed to assemble the final super image. Please check the errors above.${RESET}"
861+
# Restore the original trap and exit
862+
trap 'cleanup_and_exit' INT TERM EXIT
863+
read -rp $'\nPress Enter to return...'
864+
return
865+
fi
866+
826867
set +e
868+
869+
rm -rf "$logical_dir"
827870
trap 'cleanup_and_exit' INT TERM EXIT
828871

829872
echo -e "\n${GREEN}${BOLD}Super repack successful!${RESET}"

0 commit comments

Comments
 (0)