Last active
November 15, 2025 14:17
-
-
Save farrokhi/b44448e76c308337caa0c244d1f3bf66 to your computer and use it in GitHub Desktop.
This script corrects Proxmox VE APT sources by disabling commercial repositories and enabling community repositories. It is designed to be transparent, showing a diff of all proposed changes and asking for user confirmation before applying them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # This script corrects Proxmox VE APT sources by disabling commercial repositories | |
| # and enabling community repositories. It shows a diff of all proposed changes and | |
| # asks for user confirmation before applying them. | |
| # | |
| set -euo pipefail | |
| # --- Helper Functions --- | |
| propose_and_apply_change() { | |
| local file_path="$1" | |
| local new_content | |
| new_content=$(cat) | |
| echo "Processing: ${file_path}" | |
| if [[ -f "$file_path" ]]; then | |
| local current_content | |
| current_content=$(cat "$file_path") | |
| if [[ "${current_content}" == "${new_content}" ]]; then | |
| echo "No changes needed." | |
| echo | |
| return | |
| fi | |
| echo "Diff of proposed changes:" | |
| diff -u --label="Current: ${file_path}" --label="Proposed: ${file_path}" \ | |
| <(echo "${current_content}") <(echo "${new_content}") || true | |
| else | |
| echo "File does not exist. Proposed content:" | |
| echo "${new_content}" | |
| fi | |
| echo | |
| read -p "Apply these changes? (y/n) " -n 1 -r | |
| echo | |
| if [[ $REPLY =~ ^[Yy]$ ]]; then | |
| echo "$new_content" | tee "$file_path" >/dev/null | |
| echo "Changes applied." | |
| else | |
| echo "Changes skipped." | |
| fi | |
| echo | |
| } | |
| # --- Proxmox Version Specific Handlers --- | |
| handle_pve8() { | |
| echo "Handling Proxmox VE 8.x (.list format)..." | |
| echo | |
| propose_and_apply_change "/etc/apt/sources.list" <<'EOF' | |
| deb http://deb.debian.org/debian bookworm main contrib | |
| deb http://deb.debian.org/debian bookworm-updates main contrib | |
| deb http://security.debian.org/debian-security bookworm-security main contrib | |
| EOF | |
| propose_and_apply_change "/etc/apt/sources.list.d/pve-enterprise.list" <<'EOF' | |
| # deb https://enterprise.proxmox.com/debian/pve bookworm pve-enterprise | |
| EOF | |
| propose_and_apply_change "/etc/apt/sources.list.d/pve-no-subscription.list" <<'EOF' | |
| deb http://download.proxmox.com/debian/pve bookworm pve-no-subscription | |
| EOF | |
| } | |
| handle_pve9() { | |
| echo "Handling Proxmox VE 9.x (deb822 format)..." | |
| echo | |
| propose_and_apply_change "/etc/apt/sources.list.d/debian.sources" <<'EOF' | |
| Types: deb | |
| URIs: http://deb.debian.org/debian | |
| Suites: trixie | |
| Components: main contrib | |
| Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg | |
| Types: deb | |
| URIs: http://security.debian.org/debian-security | |
| Suites: trixie-security | |
| Components: main contrib | |
| Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg | |
| Types: deb | |
| URIs: http://deb.debian.org/debian | |
| Suites: trixie-updates | |
| Components: main contrib | |
| Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg | |
| EOF | |
| propose_and_apply_change "/etc/apt/sources.list.d/pve-enterprise.sources" <<'EOF' | |
| Types: deb | |
| URIs: https://enterprise.proxmox.com/debian/pve | |
| Suites: trixie | |
| Components: pve-enterprise | |
| Signed-By: /usr/share/keyrings/proxmox-archive-keyring.gpg | |
| Enabled: false | |
| EOF | |
| propose_and_apply_change "/etc/apt/sources.list.d/pve-no-subscription.sources" <<'EOF' | |
| Types: deb | |
| URIs: http://download.proxmox.com/debian/pve | |
| Suites: trixie | |
| Components: pve-no-subscription | |
| Signed-By: /usr/share/keyrings/proxmox-archive-keyring.gpg | |
| EOF | |
| } | |
| # --- Main Execution --- | |
| main() { | |
| clear | |
| echo "Proxmox VE APT Source Corrector" | |
| echo "--------------------------------" | |
| echo "This script disables commercial sources and enables community sources." | |
| echo "It will show all proposed changes and ask for permission before modifying files." | |
| echo "NOTE: This script must be run as root." | |
| echo | |
| if [[ $EUID -ne 0 ]]; then | |
| echo "ERROR: This script must be run as root." | |
| exit 1 | |
| fi | |
| if ! command -v pveversion &>/dev/null; then | |
| echo "ERROR: This script is intended to be run on a Proxmox VE host." | |
| exit 1 | |
| fi | |
| local pve_version | |
| pve_version=$(pveversion | awk -F'/' '{print $2}' | awk -F'-' '{print $1}') | |
| local pve_major | |
| pve_major="${pve_version%%.*}" | |
| echo "Detected Proxmox VE Version: ${pve_version}" | |
| echo | |
| if [[ "$pve_major" == "8" ]]; then | |
| handle_pve8 | |
| elif [[ "$pve_major" == "9" ]]; then | |
| handle_pve9 | |
| else | |
| echo "ERROR: Unsupported Proxmox VE major version: $pve_major" | |
| echo "Supported versions are 8.x and 9.x." | |
| exit 1 | |
| fi | |
| echo "Script finished. Run 'apt update' to refresh package lists." | |
| } | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment