From aaf0b5e8623f40e31ca5010435a691c98cfd4138 Mon Sep 17 00:00:00 2001 From: ENDRENCE LETERNET Date: Tue, 29 Jul 2025 11:17:18 +0600 Subject: [PATCH] Initial Commit --- scripts/update_apt_proxy_all.sh | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 scripts/update_apt_proxy_all.sh diff --git a/scripts/update_apt_proxy_all.sh b/scripts/update_apt_proxy_all.sh new file mode 100644 index 0000000..a3cf876 --- /dev/null +++ b/scripts/update_apt_proxy_all.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# Colors +GREEN="\033[1;32m" +RED="\033[1;31m" +YELLOW="\033[1;33m" +NC="\033[0m" + +echo -e "${GREEN}Proxmox Apt-Cacher-NG Setup for All LXC/VM${NC}" + +# Ask for the apt-cacher-ng server IP and port +read -rp "Enter your apt-cacher-ng IP address (default: 192.168.1.10): " CACHE_IP +CACHE_IP="${CACHE_IP:-192.168.1.10}" + +read -rp "Enter apt-cacher-ng port (default: 3142): " CACHE_PORT +CACHE_PORT="${CACHE_PORT:-3142}" + +APT_PROXY="Acquire::http::Proxy \"http://${CACHE_IP}:${CACHE_PORT}\";" + +echo -e "\n${YELLOW}Using APT Proxy: ${APT_PROXY}${NC}\n" + +# Confirm before proceeding +read -rp "Proceed to update all LXC containers and VMs with this proxy? (y/n): " CONFIRM +[[ "$CONFIRM" != "y" ]] && echo "Aborted." && exit 1 + +### Update LXC containers ### +echo -e "\n${GREEN}Updating LXC Containers...${NC}" + +for CTID in $(pct list | awk 'NR>1 {print $1}'); do + echo -e "\n${YELLOW}Updating LXC: $CTID${NC}" + + pct exec "$CTID" -- bash -c " + mkdir -p /etc/apt/apt.conf.d + echo '${APT_PROXY}' > /etc/apt/apt.conf.d/01proxy + " + + echo -e "${GREEN}LXC $CTID updated successfully.${NC}" +done + +### Update VMs via QEMU Guest Agent ### +echo -e "\n${GREEN}Updating VMs via QEMU Agent...${NC}" + +for VMID in $(qm list | awk 'NR>1 {print $1}'); do + if qm guest cmd "$VMID" get-osinfo &>/dev/null; then + echo -e "\n${YELLOW}Updating VM: $VMID${NC}" + + qm guest exec "$VMID" -- bash -c " + mkdir -p /etc/apt/apt.conf.d + echo '${APT_PROXY}' > /etc/apt/apt.conf.d/01proxy + " &>/dev/null + + echo -e "${GREEN}VM $VMID updated successfully.${NC}" + else + echo -e "${RED}Skipping VM $VMID – QEMU Guest Agent not available.${NC}" + fi +done + +echo -e "\n${GREEN}All done. apt-cacher-ng configuration updated on containers and agent-enabled VMs.${NC}"