From 7e40f61924784d8233ed9fe1ef32294a1fe34be3 Mon Sep 17 00:00:00 2001 From: Super User Date: Wed, 17 Jun 2026 21:05:33 -0400 Subject: [PATCH] release.sh: arrow navigation, barra fija, sin residuos --- release.sh | 214 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 135 insertions(+), 79 deletions(-) diff --git a/release.sh b/release.sh index 0090eb7..f5e05a2 100755 --- a/release.sh +++ b/release.sh @@ -5,134 +5,190 @@ ROOT="$(cd "$(dirname "$0")" && pwd)" AAB_DIR="$ROOT/build/app/outputs/bundle/release" FLUTTER="/opt/flutter/bin/flutter" JAVA_HOME="/root/.sdkman/candidates/java/21.0.11-amzn" -ADB="/opt/android-sdk/platform-tools/adb" -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -CYAN='\033[0;36m' -BOLD='\033[1m' -NC='\033[0m' +# ── colors ── +R='\033[0;31m' G='\033[0;32m' Y='\033[1;33m' +C='\033[0;36m' B='\033[1m' N='\033[0m' bar="━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -len=${#bar} +blen=${#bar} -progress() { - local pct=$1 - local msg=$2 - local filled=$(( pct * len / 100 )) - local empty=$(( len - filled )) - printf "\r${CYAN}[${bar:0:filled}${NC}${bar:0:empty}${CYAN}]${NC} %3d%% %s" "$pct" "$msg" +# ── helpers ── +cleanup() { tput cnorm; exit; } +trap cleanup EXIT INT TERM + +cursor_off() { tput civis; } +cursor_on() { tput cnorm; } + +# ── arrow selector ── +# usage: select_arrow "opt1" "opt2" ... → prints chosen, returns 0 +select_arrow() { + local opts=("$@") + local sel=0 + local row + row=$(tput lines) + row=$(( row - ${#opts[@]} - 1 )) + local col=4 + local key + + cursor_off + while true; do + for i in "${!opts[@]}"; do + tput cup "$(( row + i ))" "$col" + if [ "$i" -eq "$sel" ]; then + printf "${C}❯ ${opts[$i]}${N} \033[K" + else + printf " ${opts[$i]} \033[K" + fi + done + IFS= read -rsn1 key + if [[ $key == $'\x1b' ]]; then + read -rsn2 key + case "$key" in + '[A') (( sel > 0 )) && (( sel-- )) ;; + '[B') (( sel < ${#opts[@]} - 1 )) && (( sel++ )) ;; + esac + elif [[ $key == "" ]]; then + # clear selection lines + for i in "${!opts[@]}"; do + tput cup "$(( row + i ))" "$col" + printf " \033[K" + done + cursor_on + echo "${opts[$sel]}" + return 0 + fi + done } -clear -echo -e "${BOLD}═══════════════════════════════════════${NC}" -echo -e "${BOLD} Factura del Hogar — Release Builder ${NC}" -echo -e "${BOLD}═══════════════════════════════════════${NC}" -echo +# ── progress bar (fixed position) ── +PROGRESS_ROW=0 +set_progress_row() { PROGRESS_ROW=$(tput lines); } +progress() { + local pct=$1 msg=$2 + local filled=$(( pct * blen / 100 )) + local empty=$(( blen - filled )) + local offset=$(( PROGRESS_ROW - 2 )) + tput cup "$offset" 0 + printf "${C}[${bar:0:filled}${N}${bar:0:empty}${C}]${N} %3d%% %s\033[K" "$pct" "$msg" +} -# --- Verify project root --- +# ── ── ── ── ── ── ── ── ── +clear +cat </dev/null; then - echo -e "${RED}✗ This is not a Flutter project root (pubspec.yaml not found).${NC}" + echo -e "${R}✗ Not a Flutter project root.${N}" exit 1 fi NAME=$(grep "^name:" "$ROOT/pubspec.yaml" | head -1 | awk '{print $2}' | tr -d '"') VERSION=$(grep "^version:" "$ROOT/pubspec.yaml" | head -1 | awk '{print $2}') -echo -e " Project ${CYAN}$NAME${NC}" -echo -e " Version ${CYAN}$VERSION${NC}" -echo -e " Output ${CYAN}$AAB_DIR${NC}" + +printf " Project ${C}%s${N}\n" "$NAME" +printf " Version ${C}%s${N}\n" "$VERSION" +printf " Output ${C}%s${N}\n" "$AAB_DIR" echo -# --- Confirm --- -echo -e "${YELLOW}⚠ A release build will be created for Play Store.${NC}" -read -rp "$(echo -e ${BOLD}"Continue? [Y/n]: "${NC})" REPLY -REPLY="${REPLY:-y}" -if [[ ! "$REPLY" =~ ^[Yy]$ ]]; then - echo -e "${YELLOW}Canceled.${NC}" +# ── confirm with arrows ── +echo -e " ${Y}Build release for Play Store?${N}" +CHOICE=$(select_arrow "Yes" "No") +if [ "$CHOICE" != "Yes" ]; then + echo -e "${Y}Canceled.${N}" exit 0 fi -echo +set_progress_row export JAVA_HOME="$JAVA_HOME" -# --- Clean --- -progress 5 "Cleaning previous build..." -"$FLUTTER" clean > /dev/null 2>&1 -sleep 0.3 -progress 8 "Done" +# ── clean ── +progress 3 "Cleaning..." +"$FLUTTER" clean > /dev/null 2>&1 || true +progress 6 "Cleaning... done" -# --- Pub get --- -echo -progress 8 "Fetching dependencies..." +# ── pub get ── +progress 8 "Dependencies..." "$FLUTTER" pub get > /dev/null 2>&1 -progress 12 "Done" +progress 12 "Dependencies... done" -# --- Build AAB --- -echo +# ── build AAB ── progress 12 "Building release AAB..." -BUILD_OUTPUT=$("$FLUTTER" build appbundle --release 2>&1) -if [ $? -ne 0 ]; then - echo -e "\n${RED}✗ Build failed:${NC}" +BUILD_OUTPUT=$("$FLUTTER" build appbundle --release 2>&1) || { + echo + tput cup "$(( PROGRESS_ROW - 1 ))" 0 + echo -e "${R}✗ Build failed:${N}" echo "$BUILD_OUTPUT" exit 1 -fi -progress 70 "AAB built successfully" +} +progress 75 "AAB built successfully" -# --- Native debug symbols --- -echo +# ── native debug symbols ── SYMBOLS_DIR="$ROOT/build/app/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib" -progress 70 "Packaging native debug symbols..." +progress 78 "Packaging symbols..." if [ -d "$SYMBOLS_DIR" ]; then cd "$SYMBOLS_DIR" rm -f "$AAB_DIR/native-debug-symbols.zip" zip -r "$AAB_DIR/native-debug-symbols.zip" . > /dev/null 2>&1 cd "$ROOT" - progress 90 "Symbols packaged" + progress 95 "Symbols packaged" else - echo -e "\n${YELLOW}⚠ No native libs found at $SYMBOLS_DIR${NC}" + echo + tput cup "$(( PROGRESS_ROW - 1 ))" 0 + echo -e "${Y}⚠ No native libs found${N}" fi -# --- Verify output --- -echo -progress 95 "Verifying..." -sleep 0.3 +# ── verify ── +progress 98 "Verifying..." +sleep 0.2 progress 100 "Complete!" -echo -e "\n\n" - -# --- Results --- -echo -e "${BOLD}═══════════════════════════════════════${NC}" -echo -e "${GREEN}✓ Build successful!${NC}" echo + +# ── results ── AAB_FILE="$AAB_DIR/app-release.aab" SYM_FILE="$AAB_DIR/native-debug-symbols.zip" -echo -e " ${CYAN}App Bundle${NC} ${AAB_FILE:+$AAB_FILE}" -echo -e " ${CYAN}Debug Symbols${NC} ${SYM_FILE:+$SYM_FILE}" -echo -e " ${CYAN}Version${NC} ${VERSION}" - size_aab=$(du -sh "$AAB_FILE" 2>/dev/null | cut -f1) size_sym=$(du -sh "$SYM_FILE" 2>/dev/null | cut -f1) -echo -e " ${CYAN}AAB size${NC} ${size_aab:-N/A}" -echo -e " ${CYAN}Symbols size${NC} ${size_sym:-N/A}" -echo -# --- Move prompt --- -read -rp "$(echo -e ${BOLD}"Move files to another location? [y/N]: "${NC})" MOVE_REPLY -MOVE_REPLY="${MOVE_REPLY:-n}" -if [[ "$MOVE_REPLY" =~ ^[Yy]$ ]]; then - read -rp "$(echo -e ${BOLD}"Destination directory: "${NC})" DEST +cat </dev/null && echo -e "${GREEN}✓ AAB copied to $DEST${NC}" || echo -e "${RED}✗ Failed to copy AAB${NC}" + cp "$AAB_FILE" "$DEST/" 2>/dev/null \ + && echo -e " ${G}✓ AAB copied${N}" \ + || echo -e " ${R}✗ Failed to copy AAB${N}" if [ -f "$SYM_FILE" ]; then - cp "$SYM_FILE" "$DEST/" 2>/dev/null && echo -e "${GREEN}✓ Symbols copied to $DEST${NC}" || echo -e "${RED}✗ Failed to copy symbols${NC}" + cp "$SYM_FILE" "$DEST/" 2>/dev/null \ + && echo -e " ${G}✓ Symbols copied${N}" \ + || echo -e " ${R}✗ Failed to copy symbols${N}" fi else - echo -e "${RED}✗ Directory does not exist: $DEST${NC}" + echo -e " ${R}✗ Directory not found: $DEST${N}" fi fi echo -echo -e "${BOLD}═══════════════════════════════════════${NC}" -echo -e "${GREEN}Ready to upload to Play Console!${NC}" -echo -e "${BOLD}═══════════════════════════════════════${NC}" +echo -e "${B}═══════════════════════════════════════${N}" +echo -e "${G}Ready to upload to Play Console!${N}" +echo -e "${B}═══════════════════════════════════════${N}"