mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-03-31 06:24:02 -04:00
* core: add progress; fix exit status Introduce post_progress_to_api() in alpine-install.func and install.func to send a lightweight, fire-and-forget telemetry ping (HTTP POST) that updates an existing telemetry record to "configuring" when DIAGNOSTICS=yes and RANDOM_UUID is set. The function is non-blocking (curl -m 5, errors ignored) and is invoked during container setup and after OS updates to signal active progress. Also adjust api_exit_script() in build.func to report success (post_update_to_api "done" "0") for cases where the script exited normally but a completion status wasn't posted, instead of reporting failure. * Safer tools.func load and improved error handling Replace process-substitution sourcing of tools.func with an explicit curl -> variable -> source via /dev/stdin, adding failure messages and a check that expected functions (e.g. fetch_and_deploy_gh_release) are present (misc/alpine-install.func, misc/install.func). Add categorize_error mapping for exit code 10 -> "config" (misc/api.func). Tweak build.func: minor pipeline formatting and change the ERR trap to capture the actual exit code and only call ensure_log_on_host/post_update on non-zero exits, preventing erroneous failure reporting. * tools: add data init and auto-reporting to tools and pve section Introduce telemetry helpers in misc/api.func: _telemetry_report_exit (reports success/failure via post_tool_to_api/post_addon_to_api) and init_tool_telemetry (reads DIAGNOSTICS, starts install timer and installs an EXIT trap to auto-report). Integrate telemetry into many tools/addon and tools/pve scripts by sourcing the remote api.func and calling init_tool_telemetry (guarded with declare -f). Also apply a minor arithmetic formatting tweak in misc/build.func for RECOVERY_ATTEMPT.
87 lines
3.3 KiB
Bash
87 lines
3.3 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Copyright (c) 2021-2026 community-scripts ORG
|
|
# Author: MickLesk (CanbiZ)
|
|
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
|
|
|
|
function header_info {
|
|
clear
|
|
cat <<"EOF"
|
|
____ ________ ____ __ __ __ _ ____ ___
|
|
/ __ \_________ _ ______ ___ ____ _ __ / ____/ /__ ____ _____ / __ \_________ / /_ ____ _____ ___ ____/ / / /| | / / |/ /____
|
|
/ /_/ / ___/ __ \| |/_/ __ `__ \/ __ \| |/_/ / / / / _ \/ __ `/ __ \ / / / / ___/ __ \/ __ \/ __ `/ __ \/ _ \/ __ / / / | | / / /|_/ / ___/
|
|
/ ____/ / / /_/ /> </ / / / / / /_/ /> < / /___/ / __/ /_/ / / / / / /_/ / / / /_/ / / / / /_/ / / / / __/ /_/ / / /__| |/ / / / (__ )
|
|
/_/ /_/ \____/_/|_/_/ /_/ /_/\____/_/|_| \____/_/\___/\__,_/_/ /_/ \____/_/ / .___/_/ /_/\__,_/_/ /_/\___/\__,_/ /_____/___/_/ /_/____/
|
|
/_/
|
|
EOF
|
|
}
|
|
|
|
# Telemetry
|
|
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func) 2>/dev/null || true
|
|
declare -f init_tool_telemetry &>/dev/null && init_tool_telemetry "clean-orphaned-lvm" "tool"
|
|
|
|
# Function to check for orphaned LVM volumes
|
|
function find_orphaned_lvm {
|
|
echo -e "\n🔍 Scanning for orphaned LVM volumes...\n"
|
|
|
|
orphaned_volumes=()
|
|
while read -r lv vg size seg_type; do
|
|
# Exclude system-critical LVs and Ceph OSDs
|
|
if [[ "$lv" == "data" || "$lv" == "root" || "$lv" == "swap" || "$lv" =~ ^osd-block- ]]; then
|
|
continue
|
|
fi
|
|
|
|
# Exclude thin pools (any name)
|
|
if [[ "$seg_type" == "thin-pool" ]]; then
|
|
continue
|
|
fi
|
|
|
|
container_id=$(echo "$lv" | grep -oE "[0-9]+" | head -1)
|
|
# Check if the ID exists as a VM or LXC container
|
|
if [ -f "/etc/pve/lxc/${container_id}.conf" ] || [ -f "/etc/pve/qemu-server/${container_id}.conf" ]; then
|
|
continue
|
|
fi
|
|
|
|
orphaned_volumes+=("$lv" "$vg" "$size")
|
|
done < <(lvs --noheadings -o lv_name,vg_name,lv_size,seg_type --separator ' ' 2>/dev/null | awk '{print $1, $2, $3, $4}')
|
|
|
|
# Display orphaned volumes
|
|
echo -e "❗ The following orphaned LVM volumes were found:\n"
|
|
printf "%-25s %-10s %-10s\n" "LV Name" "VG" "Size"
|
|
printf "%-25s %-10s %-10s\n" "-------------------------" "----------" "----------"
|
|
|
|
for ((i = 0; i < ${#orphaned_volumes[@]}; i += 3)); do
|
|
printf "%-25s %-10s %-10s\n" "${orphaned_volumes[i]}" "${orphaned_volumes[i + 1]}" "${orphaned_volumes[i + 2]}"
|
|
done
|
|
echo ""
|
|
}
|
|
|
|
# Function to delete selected volumes
|
|
function delete_orphaned_lvm {
|
|
for ((i = 0; i < ${#orphaned_volumes[@]}; i += 3)); do
|
|
lv="${orphaned_volumes[i]}"
|
|
vg="${orphaned_volumes[i + 1]}"
|
|
size="${orphaned_volumes[i + 2]}"
|
|
|
|
read -p "❓ Do you want to delete $lv (VG: $vg, Size: $size)? [y/N]: " confirm
|
|
if [[ "$confirm" =~ ^[Yy]$ ]]; then
|
|
echo -e "🗑️ Deleting $lv from $vg..."
|
|
lvremove -f "$vg/$lv"
|
|
if [ $? -eq 0 ]; then
|
|
echo -e "✅ Successfully deleted $lv.\n"
|
|
else
|
|
echo -e "❌ Failed to delete $lv.\n"
|
|
fi
|
|
else
|
|
echo -e "⚠️ Skipping $lv.\n"
|
|
fi
|
|
done
|
|
}
|
|
|
|
# Run script
|
|
header_info
|
|
find_orphaned_lvm
|
|
delete_orphaned_lvm
|
|
|
|
echo -e "✅ Cleanup process completed!\n"
|