Remove old update_apt_proxy_all.sh script and its documentation; replace with a new implementation featuring enhanced proxy configuration for Proxmox LXC containers and VMs.

This commit is contained in:
2025-07-29 14:18:06 +06:00
parent 8308812474
commit c31eedef3d
2 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
# update_apt_proxy_all.sh
This script automates the configuration of the apt-cacher-ng proxy for all Proxmox LXC containers, VMs (with QEMU Guest Agent), and optionally the Proxmox node itself.
## Features
- Interactive prompts for proxy IP, port, and target selection (LXC, VM, All, Node).
- Updates `/etc/apt/apt.conf.d/01proxy` in selected targets.
- Works with both LXC containers and VMs (requires QEMU Guest Agent for VMs).
- Optionally updates the Proxmox node itself.
## Usage
You can run the script directly if its cloned locally:
```bash
bash scripts/misc/update_apt_proxy_all.sh
```
Or, run it directly from the raw link (no need to clone):
```bash
bash <(curl -s https://git.lewsion.com/endrence/proxmox-scripts/raw/branch/main/scripts/misc/update_apt_proxy_all.sh)
```
Follow the prompts to select targets and configure the proxy.
## Requirements
- Proxmox environment with `pct` and `qm` commands available.
- QEMU Guest Agent installed in VMs for VM updates.
## License
MIT

View File

@@ -0,0 +1,86 @@
#!/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${NC}"
# Prompt for target selection
while true; do
echo -e "${YELLOW}Select what to update:${NC}"
echo "1) LXC Containers"
echo "2) VMs"
echo "3) All (LXC + VMs)"
read -rp "Enter choice [1-3]: " TARGET_CHOICE
case $TARGET_CHOICE in
1|2|3) break;;
*) echo -e "${RED}Invalid choice. Please enter 1, 2, or 3.${NC}";;
esac
done
# Prompt for updating Proxmox node itself
while true; do
read -rp "Do you want to update the Proxmox node itself with the cache? (y/n): " UPDATE_NODE
case $UPDATE_NODE in
y|n) break;;
*) echo -e "${RED}Please enter y or n.${NC}";;
esac
done
# 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 selected targets with this proxy? (y/n): " CONFIRM
[[ "$CONFIRM" != "y" ]] && echo "Aborted." && exit 1
### Update LXC containers ###
if pct list &>/dev/null && { [ "$TARGET_CHOICE" = "1" ] || [ "$TARGET_CHOICE" = "3" ]; }; then
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
fi
### Update VMs via QEMU Guest Agent ###
if qm list &>/dev/null && { [ "$TARGET_CHOICE" = "2" ] || [ "$TARGET_CHOICE" = "3" ]; }; then
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
fi
### Update Proxmox Node itself ###
if [ "$UPDATE_NODE" = "y" ]; then
echo -e "\n${GREEN}Updating Proxmox Node itself...${NC}"
mkdir -p /etc/apt/apt.conf.d
echo "${APT_PROXY}" > /etc/apt/apt.conf.d/01proxy
echo -e "${GREEN}Proxmox Node updated successfully.${NC}"
fi
echo -e "\n${GREEN}All done. apt-cacher-ng configuration updated as selected.${NC}"