From 95f1b1f4a63377dd76c2e76e27031da5178db3b8 Mon Sep 17 00:00:00 2001 From: JieXu Date: Sat, 15 Nov 2025 23:10:34 +0800 Subject: [PATCH] Update reinstall-fbl.sh --- reinstall-fbl.sh | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/reinstall-fbl.sh b/reinstall-fbl.sh index ffdfc28..375a6dc 100644 --- a/reinstall-fbl.sh +++ b/reinstall-fbl.sh @@ -105,7 +105,7 @@ Examples: Notes: * This script will dd an entire disk. Make sure the auto-detected disk is correct, or override it with --disk explicitly. - * On RHEL/Rocky/Alma/Fedora, the script will try to install xz, qemu-img and curl automatically + * On RHEL/Rocky/Alma/Fedora, the script will try to install xz, qemu-img, curl and pv automatically if they are missing. * All target systems use cloud-init NoCloud to inject root password, SSH keys, etc. EOF @@ -182,6 +182,10 @@ ensure_dependencies_linux_rhel_like() { if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1 && ! command -v fetch >/dev/null 2>&1; then need_pkgs+=("curl") fi + # pv is optional but nice to have for decompression progress + if ! command -v pv >/dev/null 2>&1; then + need_pkgs+=("pv") + fi if [ "${#need_pkgs[@]}" -gt 0 ]; then info "Installing missing dependencies with $pm: ${need_pkgs[*]}" @@ -190,7 +194,7 @@ ensure_dependencies_linux_rhel_like() { } ensure_dependencies_linux_generic() { - # For non-Red-Hat Linux, just check and error with a clear message. + # For non-Red-Hat Linux, just check and error with a clear message for hard deps. local missing=() if ! command -v qemu-img >/dev/null 2>&1; then @@ -207,10 +211,14 @@ ensure_dependencies_linux_generic() { error "Missing dependencies on Linux: ${missing[*]} Please install them manually with your package manager (e.g. apt, zypper, pacman) and rerun this script." fi + + if ! command -v pv >/dev/null 2>&1; then + warn "Optional tool 'pv' not found. xz decompression will work but without a progress bar. +You can install 'pv' with your package manager if you want throughput/time progress." + fi } ensure_dependencies_freebsd() { - # Placeholder for future automation. # For now just check and give a hint. local missing=() @@ -229,6 +237,12 @@ ensure_dependencies_freebsd() { Hint: you can install them with: pkg install qemu-tools xz curl" fi + + if ! command -v pv >/dev/null 2>&1; then + warn "Optional tool 'pv' not found. xz decompression will work but without a progress bar. +On FreeBSD you can install it with: + pkg install pv" + fi } ensure_dependencies() { @@ -680,7 +694,7 @@ while [ $# -gt 0 ]; do done detect_os_arch -ensure_dependencies # auto install / check qemu-img, xz, curl/wget/fetch +ensure_dependencies # auto install / check qemu-img, xz, curl/wget/fetch, pv (on RHEL-like) # Disk handling: auto-detect if not provided if [ -n "$DISK" ]; then @@ -708,7 +722,7 @@ if [ -z "$PASSWORD" ] && [ -z "$SSH_KEYS_ALL" ]; then # Empty: auto-generate random password, no need to confirm if [ -z "$pw1" ]; then if command -v tr >/dev/null 2>&1; then - PASSWORD=$(LC_ALL=C tr -dc 'A-Za-z0n9' /dev/null 2>&1; then - # pv 可选依赖,有则显示流量和时间 + # pv is optional; if present, show progress xz -dc "$IMG_QCOW.xz" | pv >"$IMG_QCOW" else xz -dc "$IMG_QCOW.xz" >"$IMG_QCOW"