Skip to content

Commit 72f6574

Browse files
committed
Added bulk scripts and added style guide
- Added bulk disable autostart on all nested VMs - Added bulk unmount ISOs on all nested VMs - Added ChangeAllMACPrefix.sh for editing the prefix' of a single host instance. - Added the script style guide so I can try to not suck and actually keep things consistent - Changed the example script so it was more useful
1 parent 0a8ef66 commit 72f6574

11 files changed

Lines changed: 756 additions & 32 deletions

File tree

CCPVE.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# in the repository executable and finally call CCPVEOffline.sh.
77
#
88
# Usage:
9-
# ./CCPVE.sh [-nh]
9+
# ./CCPVE.sh [-h]
1010
#
1111
# This script requires 'unzip' and 'wget'. If not installed, it will prompt to install them.
1212
#
@@ -18,12 +18,13 @@ set -e
1818

1919
apt update || true
2020

21-
SHOW_HEADER="true"
21+
# By default do not show the GUI header; use -h to display it
22+
SHOW_HEADER="false"
2223

2324
while [[ $# -gt 0 ]]; do
2425
case "$1" in
25-
-nh)
26-
SHOW_HEADER="false"
26+
-h)
27+
SHOW_HEADER="true"
2728
shift
2829
;;
2930
*)
@@ -97,8 +98,8 @@ fi
9798
# --- Call GUI.sh --------------------------------------------------
9899
if [ -f "./GUI.sh" ]; then
99100
echo "Calling GUI.sh..."
100-
if [ "$SHOW_HEADER" != "true" ]; then
101-
bash "./GUI.sh" -nh
101+
if [ "$SHOW_HEADER" = "true" ]; then
102+
bash "./GUI.sh" -h
102103
else
103104
bash "./GUI.sh"
104105
fi

GUI.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# GUI.sh
44
#
55
# A menu-driven Bash script to navigate and run .sh files in the current folder (and subfolders).
6-
# This version assumes everything is already extracted/unzipped in this directoryno download or unzip needed.
6+
# This version assumes everything is already extracted/unzipped in this directory-no download or unzip needed.
77
#
8-
# ./GUI.sh [-nh]
8+
# ./GUI.sh [-h]
99
#
1010
# Usage:
1111
# 1) cd into the directory containing your .sh files (and this script).
@@ -37,7 +37,7 @@ DISPLAY_PREFIX="cc_pve" # How we display the "root" in the UI
3737
HELP_FLAG="--help" # If your scripts support a help flag, we pass this
3838
LAST_SCRIPT="" # The last script run
3939
LAST_OUTPUT="" # Truncated output of the last script
40-
SHOW_HEADER="true"
40+
SHOW_HEADER="false"
4141

4242
###############################################################################
4343
# IMPORT UTILITY FUNCTIONS FOR SCRIPTS AND COLOR GRADIENT LIBRARY
@@ -52,8 +52,8 @@ source "${UTILITYPATH}/Colors.sh"
5252

5353
while [[ $# -gt 0 ]]; do
5454
case "$1" in
55-
-nh)
56-
SHOW_HEADER="false"
55+
-h)
56+
SHOW_HEADER="true"
5757
shift
5858
;;
5959
*)

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ Or an even shorter single line call:
3737
bash <(curl -L pve.coela.sh)
3838
```
3939

40-
41-
Short single line call with a minimal header:
40+
Short single line call with the full header:
4241
```bash
43-
bash <(curl -L pve.coela.sh) -nh
42+
bash <(curl -L pve.coela.sh) -h
4443
```
4544

4645
![Single Line Online Command](.site/SingleLineCommand.png)

RemoteManagement/ConfigureOverSSH/Proxmox/BulkCloneSetIP.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ EOF
133133
# Build + push inner script
134134
tmpInner="$(mktemp)"
135135
cat >"$tmpInner" <<'INNER_EOF'
136-
#!/usr/bin/env bash
136+
#!/bin/bash
137137
set -euo pipefail
138138
139139
NEW_PREFIX="$1" # e.g., BC:13:46
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
#!/bin/bash
2+
#
3+
# BulkDisableAutoStart.sh
4+
#
5+
# Disables autostart for all VM (qm) and LXC (pct) resources inside a range of
6+
# nested Proxmox virtual machines identified by VMIDs on the parent host.
7+
# For each VMID in the provided range, the script attempts to determine the
8+
# management IP via the QEMU guest agent; if unavailable, it falls back to
9+
# parsing the VM config for an IP (best-effort). It then connects via SSH using
10+
# provided credentials and disables autostart flags on all internal resources.
11+
#
12+
# Usage:
13+
# ./BulkDisableAutoStart.sh <startVmId> <endVmId> <sshUsername> <sshPassword>
14+
#
15+
# Example:
16+
# ./BulkDisableAutoStart.sh 200 210 root passw0rd
17+
#
18+
# Notes:
19+
# - Must be run as root on the outer Proxmox host.
20+
# - Requires 'qm' with guest agent responding for reliable IP detection.
21+
# - SSH password auth is used (non-interactive). Keys can be adapted if desired.
22+
# - Only modifies autostart flags (onboot=0) within nested environment; no reboots performed.
23+
#
24+
# Function Index:
25+
# - usage
26+
# - get_ip_for_vmid
27+
# - ssh_exec
28+
# - disable_autostart_inner
29+
# - process_vmid
30+
# - main
31+
#
32+
33+
###############################################################################
34+
# Usage
35+
###############################################################################
36+
usage() {
37+
cat <<USAGE
38+
Usage: ${0##*/} <startVmId> <endVmId> <sshUsername> <sshPassword>
39+
40+
Disables autostart (onboot) for all VMs and LXCs inside each nested Proxmox
41+
instance whose VMID is in the inclusive range [startVmId, endVmId].
42+
43+
Arguments:
44+
startVmId Starting VMID (inclusive)
45+
endVmId Ending VMID (inclusive)
46+
sshUsername SSH username for nested Proxmox host
47+
sshPassword SSH password for nested Proxmox host
48+
49+
Environment:
50+
UTILITYPATH (optional, exported by GUI.sh) to source shared helpers.
51+
USAGE
52+
}
53+
54+
###############################################################################
55+
# Setup / Imports
56+
###############################################################################
57+
source "${UTILITYPATH}/Prompts.sh"
58+
source "${UTILITYPATH}/Communication.sh"
59+
source "${UTILITYPATH}/Queries.sh"
60+
source "${UTILITYPATH}/SSH.sh"
61+
62+
__check_root__
63+
__check_proxmox__
64+
__install_or_prompt__ "sshpass"
65+
__install_or_prompt__ "jq"
66+
67+
68+
###############################################################################
69+
# Argument Parsing
70+
###############################################################################
71+
if [[ $# -lt 4 ]]; then
72+
echo "Error: Missing arguments." >&2
73+
usage
74+
exit 1
75+
fi
76+
77+
startVmId="$1"
78+
endVmId="$2"
79+
sshUser="$3"
80+
sshPass="$4"
81+
82+
if ! [[ "$startVmId" =~ ^[0-9]+$ && "$endVmId" =~ ^[0-9]+$ && $endVmId -ge $startVmId ]]; then
83+
echo "Invalid VMID range: $startVmId..$endVmId" >&2
84+
exit 1
85+
fi
86+
87+
###############################################################################
88+
# Helpers
89+
###############################################################################
90+
# IP retrieval uses utility: __get_ip_from_vmid__ (from Queries.sh)
91+
# SSH reachability waits via: __wait_for_ssh__ (from SSH.sh)
92+
93+
# disable_autostart_inner <host>
94+
# Runs inside nested host: disable autostart for qm + pct resources.
95+
disable_autostart_inner() {
96+
local host="$1"
97+
sshpass -p "$sshPass" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
98+
"$sshUser@$host" bash -s <<'INNER'
99+
set -euo pipefail
100+
if ! command -v qm &>/dev/null; then
101+
echo "Not a Proxmox environment (qm missing)." >&2
102+
exit 1
103+
fi
104+
# Disable autostart for QEMU VMs
105+
declare -a vms
106+
mapfile -t vms < <(qm list | awk 'NR>1 {print $1}')
107+
for id in "${vms[@]}"; do
108+
if qm config "$id" | grep -q '^onboot: *1'; then
109+
qm set "$id" -onboot 0 >/dev/null 2>&1 || true
110+
echo "VM $id: onboot -> 0"
111+
else
112+
echo "VM $id: already 0 or no onboot flag"
113+
fi
114+
done
115+
# Disable autostart for LXCs if pct exists
116+
if command -v pct &>/dev/null; then
117+
declare -a cts
118+
mapfile -t cts < <(pct list | awk 'NR>1 {print $1}')
119+
for cid in "${cts[@]}"; do
120+
if pct config "$cid" | grep -q '^onboot: *1'; then
121+
pct set "$cid" -onboot 0 >/dev/null 2>&1 || true
122+
echo "CT $cid: onboot -> 0"
123+
else
124+
echo "CT $cid: already 0 or no onboot flag"
125+
fi
126+
done
127+
fi
128+
INNER
129+
}
130+
131+
# process_vmid <vmid>
132+
process_vmid() {
133+
local vmid="$1"
134+
if command -v __info__ &>/dev/null; then
135+
__info__ "Processing VMID $vmid"
136+
else
137+
echo "=== VMID $vmid ==="
138+
fi
139+
local ip
140+
if ! ip="$( __get_ip_from_vmid__ "$vmid" 2>/dev/null )"; then
141+
if command -v __err__ &>/dev/null; then
142+
__err__ "Could not determine IP for VMID $vmid"
143+
else
144+
echo "Error: Could not determine IP for VMID $vmid" >&2
145+
fi
146+
return 1
147+
fi
148+
# Ensure SSH is reachable (best-effort) before attempting changes
149+
__wait_for_ssh__ "$ip" "$sshUser" "$sshPass" 2>/dev/null || true
150+
if command -v __update__ &>/dev/null; then
151+
__update__ "Disabling autostart on nested host $ip"
152+
else
153+
echo "Connecting to $ip ..."
154+
fi
155+
if disable_autostart_inner "$ip"; then
156+
command -v __ok__ &>/dev/null && __ok__ "Done VMID $vmid" || echo "Completed VMID $vmid"
157+
else
158+
command -v __err__ &>/dev/null && __err__ "Failed VMID $vmid" || echo "Failed VMID $vmid" >&2
159+
fi
160+
}
161+
162+
###############################################################################
163+
# MAIN
164+
###############################################################################
165+
main() {
166+
for ((id=startVmId; id<=endVmId; id++)); do
167+
process_vmid "$id"
168+
done
169+
echo "All requested VMIDs processed ($startVmId..$endVmId)."
170+
171+
__prompt_keep_installed_packages__
172+
}
173+
174+
main "$@"
175+
176+
177+
###############################################################################
178+
# Testing status
179+
###############################################################################
180+
# Tested: (pending) range on lab cluster; guest agent required for accurate IP discovery.

0 commit comments

Comments
 (0)