From 9a329a754bd115b2383ba2586d244c3b7b961dcf Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Mar 2026 05:18:54 +0000 Subject: [PATCH] replace ZIM text prompts with whiptail radiolist + checklist - Radiolist first: Choose / All / Skip (ESC = skip) - Checklist shows all 18 ZIMs with sizes; pre-checks any already downloaded ZIMs so re-runs don't re-select what you have - ZIM_PICKS now stores space-separated names (wikipedia, stackoverflow, archlinux...) instead of numbers; dispatch updated to match - Text fallback (no whiptail): same numbered list as before, converts input numbers to names before dispatch - Summary shows count and names of selected ZIMs https://claude.ai/code/session_012gDnantBmFTWZGCiKyjazx --- laptop_full_setup.sh | 203 +++++++++++++++++++++++++++++-------------- 1 file changed, 140 insertions(+), 63 deletions(-) diff --git a/laptop_full_setup.sh b/laptop_full_setup.sh index 6840215..902d2f4 100755 --- a/laptop_full_setup.sh +++ b/laptop_full_setup.sh @@ -290,52 +290,126 @@ if $SVC_KIWIX; then unset _MPTS _MP _i _KIWIX_CHOICE # ── Q4: Download ZIMs now? ───────────────────────────────────────────────── - echo "" - echo -e " ${BOLD}[4/6] Download ZIM files? (offline Wikipedia, Stack Overflow, etc.)${NC}" - echo " Downloads run in the background — safe to start now and leave overnight." - echo " Total: ~130GB (Wikipedia 46GB, Project Gutenberg 60GB, others smaller)" - echo "" - echo " 1) Yes — download all ZIMs overnight (~130GB)" - echo " 2) Select — choose which ZIMs to download" - echo " 3) No — skip for now (run ./kiwix_download.sh later)" - echo "" - read -rp " Choice [3]: " ZIM_CHOICE - ZIM_CHOICE="${ZIM_CHOICE:-3}" + # ON if any matching ZIM file already exists in KIWIX_DIR + _zimon() { ls "$KIWIX_DIR/${1}"*.zim 2>/dev/null | grep -q . && echo ON || echo OFF; } - # ── Q4a: ZIM selection (only if choice == 2) ────────────────────────────── + ZIM_CHOICE="3" ZIM_PICKS="" - if [[ "$ZIM_CHOICE" == "2" ]]; then - # Helper: show [done] if a ZIM matching a glob pattern already exists - _zim_tag() { - local pattern="$1" - ls "$KIWIX_DIR"/${pattern}*.zim 2>/dev/null | grep -q . && echo " ${GREEN}[downloaded]${NC}" || echo "" - } + + if command -v whiptail &>/dev/null && [[ -t 0 ]]; then + if _ZIM_MODE=$(whiptail --backtitle "Kiwix" \ + --title "[4/6] Kiwix ZIM Downloads" \ + --radiolist "Download offline Wikipedia, Stack Overflow, etc.? (runs in background)" \ + 11 68 3 \ + "select" "Choose individual ZIMs " ON \ + "all" "Download everything (~130 GB) " OFF \ + "skip" "Skip — run kiwix_download.sh later " OFF \ + 3>&1 1>&2 2>&3 2>/dev/null); then + _ZIM_MODE="${_ZIM_MODE//\"/}" + case "$_ZIM_MODE" in + all) ZIM_CHOICE="1" ;; + select|*) + ZIM_CHOICE="2" + if _ZIM_SEL=$(whiptail --backtitle "Kiwix" \ + --title "Select ZIMs to Download" \ + --checklist "SPACE = toggle ENTER = confirm ESC = skip\nPre-checked = already downloaded" \ + 24 72 16 \ + "wikipedia" "$(printf '%-30s %7s' 'Wikipedia' '~46 GB')" "$(_zimon wikipedia_en_all_nopic)" \ + "stackoverflow" "$(printf '%-30s %7s' 'Stack Overflow' '~3 GB')" "$(_zimon stackoverflow.com_en_all)" \ + "archlinux" "$(printf '%-30s %7s' 'Arch Linux Wiki' '~30 MB')" "$(_zimon archlinux_en_all)" \ + "wiktionary" "$(printf '%-30s %7s' 'Wiktionary' '~2 GB')" "$(_zimon wiktionary_en_all_nopic)" \ + "wikibooks" "$(printf '%-30s %7s' 'Wikibooks' '~500 MB')" "$(_zimon wikibooks_en_all_nopic)" \ + "wikisource" "$(printf '%-30s %7s' 'Wikisource' '~4 GB')" "$(_zimon wikisource_en_all_nopic)" \ + "wikivoyage" "$(printf '%-30s %7s' 'Wikivoyage' '~200 MB')" "$(_zimon wikivoyage_en_all_nopic)" \ + "wikiversity" "$(printf '%-30s %7s' 'Wikiversity' '~500 MB')" "$(_zimon wikiversity_en_all_nopic)" \ + "wikinews" "$(printf '%-30s %7s' 'WikiNews' '~300 MB')" "$(_zimon wikinews_en_all_nopic)" \ + "wikiquote" "$(printf '%-30s %7s' 'Wikiquote' '~300 MB')" "$(_zimon wikiquote_en_all_nopic)" \ + "vikidia" "$(printf '%-30s %7s' 'Vikidia (kids K-8)' '~66 MB')" "$(_zimon vikidia_en_all_nopic)" \ + "ted" "$(printf '%-30s %7s' 'TED Talks' '~5 GB')" "$(_zimon ted_mul_youth)" \ + "phet" "$(printf '%-30s %7s' 'PhET Simulations' '~500 MB')" "$(_zimon phet_en_all)" \ + "devdocs" "$(printf '%-30s %7s' 'DevDocs' '~1 GB')" "$(_zimon devdocs_en_zig)" \ + "freecodecamp" "$(printf '%-30s %7s' 'FreeCodeCamp' 'small')" "$(_zimon freecodecamp_en_all)" \ + "ifixit" "$(printf '%-30s %7s' 'iFixit' '~2 GB')" "$(_zimon ifixit_en_all)" \ + "libretexts" "$(printf '%-30s %7s' 'LibreTexts' 'varies')" "$(_zimon libretexts.org_en)" \ + "gutenberg" "$(printf '%-30s %7s' 'Project Gutenberg' '~60 GB')" "$(_zimon gutenberg_en_all)" \ + 3>&1 1>&2 2>&3 2>/dev/null); then + if [[ -n "$_ZIM_SEL" ]]; then + ZIM_PICKS=$(tr -d '"' <<< "$_ZIM_SEL") + else + ZIM_CHOICE="3" # Enter with nothing checked → skip + fi + else + ZIM_CHOICE="3" # ESC → skip + fi + ;; + esac + fi # ESC on radiolist → ZIM_CHOICE stays "3" + else + # Text fallback echo "" - echo " Select ZIMs to download (space-separated numbers, e.g. 1 3 5):" - echo " ZIMs already in $KIWIX_DIR are marked [downloaded]." + echo -e " ${BOLD}[4/6] Download ZIM files? (offline Wikipedia, Stack Overflow, etc.)${NC}" + echo " Downloads run in the background — safe to start now and leave overnight." + echo " Total: ~130GB (Wikipedia 46GB, Project Gutenberg 60GB, others smaller)" echo "" - printf " %2s) %-26s %6s %s\n" 1 "Wikipedia" "~46GB" "$(_zim_tag "wikipedia_en_all_nopic")" - printf " %2s) %-26s %6s %s\n" 2 "Stack Overflow" "~3GB" "$(_zim_tag "stackoverflow.com_en_all")" - printf " %2s) %-26s %6s %s\n" 3 "Arch Linux Wiki" "~30MB" "$(_zim_tag "archlinux_en_all")" - printf " %2s) %-26s %6s %s\n" 4 "Wiktionary" "~2GB" "$(_zim_tag "wiktionary_en_all_nopic")" - printf " %2s) %-26s %6s %s\n" 5 "Wikibooks" "~500MB" "$(_zim_tag "wikibooks_en_all_nopic")" - printf " %2s) %-26s %6s %s\n" 6 "Wikisource" "~4GB" "$(_zim_tag "wikisource_en_all_nopic")" - printf " %2s) %-26s %6s %s\n" 7 "Wikivoyage" "~200MB" "$(_zim_tag "wikivoyage_en_all_nopic")" - printf " %2s) %-26s %6s %s\n" 8 "Wikiversity" "~500MB" "$(_zim_tag "wikiversity_en_all_nopic")" - printf " %2s) %-26s %6s %s\n" 9 "WikiNews" "~300MB" "$(_zim_tag "wikinews_en_all_nopic")" - printf " %2s) %-26s %6s %s\n" 10 "Wikiquote" "~300MB" "$(_zim_tag "wikiquote_en_all_nopic")" - printf " %2s) %-26s %6s %s\n" 11 "Vikidia (kids K-8)" "~66MB" "$(_zim_tag "vikidia_en_all_nopic")" - printf " %2s) %-26s %6s %s\n" 12 "TED Talks" "~5GB" "$(_zim_tag "ted_mul_youth")" - printf " %2s) %-26s %6s %s\n" 13 "PhET Simulations" "~500MB" "$(_zim_tag "phet_en_all")" - printf " %2s) %-26s %6s %s\n" 14 "DevDocs" "~1GB" "$(_zim_tag "devdocs_en_zig")" - printf " %2s) %-26s %6s %s\n" 15 "FreeCodeCamp" "~small" "$(_zim_tag "freecodecamp_en_all")" - printf " %2s) %-26s %6s %s\n" 16 "iFixit" "~2GB" "$(_zim_tag "ifixit_en_all")" - printf " %2s) %-26s %6s %s\n" 17 "LibreTexts" "~varies" "$(_zim_tag "libretexts.org_en")" - printf " %2s) %-26s %6s %s\n" 18 "Project Gutenberg" "~60GB" "$(_zim_tag "gutenberg_en_all")" + echo " 1) Yes — download all ZIMs overnight (~130GB)" + echo " 2) Select — choose which ZIMs to download" + echo " 3) No — skip for now (run ./kiwix_download.sh later)" echo "" - read -rp " Your choices (e.g. 1 2 3): " ZIM_PICKS - unset -f _zim_tag + read -rp " Choice [3]: " ZIM_CHOICE + ZIM_CHOICE="${ZIM_CHOICE:-3}" + + if [[ "$ZIM_CHOICE" == "2" ]]; then + _zim_tag() { + ls "$KIWIX_DIR/${1}"*.zim 2>/dev/null | grep -q . && echo " ${GREEN}[downloaded]${NC}" || echo "" + } + echo "" + echo " Select ZIMs to download (space-separated numbers, e.g. 1 3 5):" + printf " %2s) %-26s %7s %s\n" 1 "Wikipedia" "~46 GB" "$(_zim_tag wikipedia_en_all_nopic)" + printf " %2s) %-26s %7s %s\n" 2 "Stack Overflow" "~3 GB" "$(_zim_tag stackoverflow.com_en_all)" + printf " %2s) %-26s %7s %s\n" 3 "Arch Linux Wiki" "~30 MB" "$(_zim_tag archlinux_en_all)" + printf " %2s) %-26s %7s %s\n" 4 "Wiktionary" "~2 GB" "$(_zim_tag wiktionary_en_all_nopic)" + printf " %2s) %-26s %7s %s\n" 5 "Wikibooks" "~500 MB" "$(_zim_tag wikibooks_en_all_nopic)" + printf " %2s) %-26s %7s %s\n" 6 "Wikisource" "~4 GB" "$(_zim_tag wikisource_en_all_nopic)" + printf " %2s) %-26s %7s %s\n" 7 "Wikivoyage" "~200 MB" "$(_zim_tag wikivoyage_en_all_nopic)" + printf " %2s) %-26s %7s %s\n" 8 "Wikiversity" "~500 MB" "$(_zim_tag wikiversity_en_all_nopic)" + printf " %2s) %-26s %7s %s\n" 9 "WikiNews" "~300 MB" "$(_zim_tag wikinews_en_all_nopic)" + printf " %2s) %-26s %7s %s\n" 10 "Wikiquote" "~300 MB" "$(_zim_tag wikiquote_en_all_nopic)" + printf " %2s) %-26s %7s %s\n" 11 "Vikidia (kids K-8)" "~66 MB" "$(_zim_tag vikidia_en_all_nopic)" + printf " %2s) %-26s %7s %s\n" 12 "TED Talks" "~5 GB" "$(_zim_tag ted_mul_youth)" + printf " %2s) %-26s %7s %s\n" 13 "PhET Simulations" "~500 MB" "$(_zim_tag phet_en_all)" + printf " %2s) %-26s %7s %s\n" 14 "DevDocs" "~1 GB" "$(_zim_tag devdocs_en_zig)" + printf " %2s) %-26s %7s %s\n" 15 "FreeCodeCamp" "small" "$(_zim_tag freecodecamp_en_all)" + printf " %2s) %-26s %7s %s\n" 16 "iFixit" "~2 GB" "$(_zim_tag ifixit_en_all)" + printf " %2s) %-26s %7s %s\n" 17 "LibreTexts" "varies" "$(_zim_tag libretexts.org_en)" + printf " %2s) %-26s %7s %s\n" 18 "Project Gutenberg" "~60 GB" "$(_zim_tag gutenberg_en_all)" + echo "" + read -rp " Your choices (e.g. 1 2 3): " _ZIM_NUMS + for _n in $_ZIM_NUMS; do + case "$_n" in + 1) ZIM_PICKS+="${ZIM_PICKS:+ }wikipedia" ;; + 2) ZIM_PICKS+="${ZIM_PICKS:+ }stackoverflow" ;; + 3) ZIM_PICKS+="${ZIM_PICKS:+ }archlinux" ;; + 4) ZIM_PICKS+="${ZIM_PICKS:+ }wiktionary" ;; + 5) ZIM_PICKS+="${ZIM_PICKS:+ }wikibooks" ;; + 6) ZIM_PICKS+="${ZIM_PICKS:+ }wikisource" ;; + 7) ZIM_PICKS+="${ZIM_PICKS:+ }wikivoyage" ;; + 8) ZIM_PICKS+="${ZIM_PICKS:+ }wikiversity" ;; + 9) ZIM_PICKS+="${ZIM_PICKS:+ }wikinews" ;; + 10) ZIM_PICKS+="${ZIM_PICKS:+ }wikiquote" ;; + 11) ZIM_PICKS+="${ZIM_PICKS:+ }vikidia" ;; + 12) ZIM_PICKS+="${ZIM_PICKS:+ }ted" ;; + 13) ZIM_PICKS+="${ZIM_PICKS:+ }phet" ;; + 14) ZIM_PICKS+="${ZIM_PICKS:+ }devdocs" ;; + 15) ZIM_PICKS+="${ZIM_PICKS:+ }freecodecamp" ;; + 16) ZIM_PICKS+="${ZIM_PICKS:+ }ifixit" ;; + 17) ZIM_PICKS+="${ZIM_PICKS:+ }libretexts" ;; + 18) ZIM_PICKS+="${ZIM_PICKS:+ }gutenberg" ;; + esac + done + unset -f _zim_tag + fi fi + unset -f _zimon else ZIM_CHOICE="3" fi @@ -680,8 +754,11 @@ if $INSTALL_AI && $SVC_SEARXNG; then echo " ✓ SearXNG → $_sx" fi $PULL_MODELS && echo " ✓ Pull models : $EMBED_MODEL + $FAST_MODEL + $CHAT_MODEL + $CODE_MODEL${REASON_MODEL:+ + $REASON_MODEL}" -[[ "$ZIM_CHOICE" == "1" ]] && echo " ✓ Download all ZIMs in background (~130GB)" -[[ "$ZIM_CHOICE" == "2" ]] && echo " ✓ Select ZIMs to download (prompted after stack starts)" +[[ "$ZIM_CHOICE" == "1" ]] && echo " ✓ Download all ZIMs in background (~130 GB)" +if [[ "$ZIM_CHOICE" == "2" ]]; then + _nzim=$(wc -w <<< "$ZIM_PICKS") + echo " ✓ Download ${_nzim} ZIM(s): $ZIM_PICKS" +fi echo "" read -rp " Proceed? [Y/n]: " CONFIRM [[ "${CONFIRM,,}" == "n" ]] && echo "Aborted." && exit 0 @@ -1388,28 +1465,28 @@ if $SVC_KIWIX && [[ "$ZIM_CHOICE" != "3" ]]; then GUT=$(latest_zim "$MIRROR2/gutenberg" "gutenberg_en_all") if [[ "$ZIM_CHOICE" == "2" ]]; then - # ZIM_PICKS was captured during the wizard — just dispatch + # ZIM_PICKS contains space-separated ZIM names selected during the wizard rm -f "$KIWIX_DIR/.download_pids" - for n in $ZIM_PICKS; do - case "$n" in - 1) dl_zim "wikipedia" "$WIKI" "Wikipedia" ;; - 2) dl_zim "stack_exchange" "$SO" "Stack Overflow" ;; - 3) dl_zim "other" "$ARCH" "Arch Linux Wiki" ;; - 4) dl_zim "wiktionary" "$WIKT" "Wiktionary" ;; - 5) dl_zim "wikibooks" "$WIKB" "Wikibooks" ;; - 6) dl_zim "wikisource" "$WIKS" "Wikisource" ;; - 7) dl_zim "wikivoyage" "$WIKV" "Wikivoyage" ;; - 8) dl_zim "wikiversity" "$WIKUNI" "Wikiversity" ;; - 9) dl_zim "wikinews" "$WIKNEWS" "WikiNews" ;; - 10) dl_zim "wikiquote" "$WIKQ" "Wikiquote" ;; - 11) dl_zim "vikidia" "$VIKIDIA" "Vikidia (kids K-8)" ;; - 12) dl_zim "ted" "$TED" "TED Talks" ;; - 13) dl_zim "phet" "$PHET" "PhET Simulations" ;; - 14) dl_zim "devdocs" "$DEVDOCS" "DevDocs" ;; - 15) dl_zim "freecodecamp" "$FCC" "FreeCodeCamp" ;; - 16) dl_zim "ifixit" "$IFIX" "iFixit" ;; - 17) dl_zim "libretexts" "$LIBRE" "LibreTexts" ;; - 18) dl_zim "gutenberg" "$GUT" "Project Gutenberg" "$MIRROR2" ;; + for _zn in $ZIM_PICKS; do + case "$_zn" in + wikipedia) dl_zim "wikipedia" "$WIKI" "Wikipedia" ;; + stackoverflow) dl_zim "stack_exchange" "$SO" "Stack Overflow" ;; + archlinux) dl_zim "other" "$ARCH" "Arch Linux Wiki" ;; + wiktionary) dl_zim "wiktionary" "$WIKT" "Wiktionary" ;; + wikibooks) dl_zim "wikibooks" "$WIKB" "Wikibooks" ;; + wikisource) dl_zim "wikisource" "$WIKS" "Wikisource" ;; + wikivoyage) dl_zim "wikivoyage" "$WIKV" "Wikivoyage" ;; + wikiversity) dl_zim "wikiversity" "$WIKUNI" "Wikiversity" ;; + wikinews) dl_zim "wikinews" "$WIKNEWS" "WikiNews" ;; + wikiquote) dl_zim "wikiquote" "$WIKQ" "Wikiquote" ;; + vikidia) dl_zim "vikidia" "$VIKIDIA" "Vikidia (kids K-8)" ;; + ted) dl_zim "ted" "$TED" "TED Talks" ;; + phet) dl_zim "phet" "$PHET" "PhET Simulations" ;; + devdocs) dl_zim "devdocs" "$DEVDOCS" "DevDocs" ;; + freecodecamp) dl_zim "freecodecamp" "$FCC" "FreeCodeCamp" ;; + ifixit) dl_zim "ifixit" "$IFIX" "iFixit" ;; + libretexts) dl_zim "libretexts" "$LIBRE" "LibreTexts" ;; + gutenberg) dl_zim "gutenberg" "$GUT" "Project Gutenberg" "$MIRROR2" ;; esac done else