Skip to content

Commit dedaac6

Browse files
committed
Put the last thirteen mechanical VM scripts on the shared wizard
Same conversion again, now with the helper calls each script makes inside its own wizard preserved in place: select_os, select_cloud_init, select_portainer, set_root_password, set_ssh_keys, configure_netbird_setup. Dropping those was the mistake debian-13 nearly shipped, so the converter now records whether a call sat before or after the standard block and puts it back there. Two needed a second pass. docker-vm's default_settings has an arm64 conditional whose branches contain nothing but echo lines, and stripping every echo left an if with two empty halves -- so only summary lines at the function's own indentation are removed now. owncloud-vm defined start_script twice, identically apart from two colour codes; both are gone. Across the twenty converted scripts this comes to roughly 4400 lines removed and 330 whiptail calls down to about 30. What is left is genuinely script-specific: OS pickers, password entry, Portainer, NetBird setup.
1 parent 824d3b8 commit dedaac6

13 files changed

Lines changed: 272 additions & 3175 deletions

‎vm/allstarlink-vm.sh‎

Lines changed: 22 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ else
3939
fi
4040

4141
function default_settings() {
42+
vm_apply_machine_type "i440fx"
4243
VMID="$NEXTID"
43-
FORMAT=",efitype=4m"
44-
MACHINE=""
4544
DISK_CACHE=""
4645
HN="allstarlink"
4746
CPU_TYPE=""
@@ -53,233 +52,44 @@ function default_settings() {
5352
MTU=""
5453
START_VM="yes"
5554
METHOD="default"
56-
echo -e "${DGN}Using Virtual Machine ID: ${BGN}${VMID}${CL}"
57-
echo -e "${DGN}Using Machine Type: ${BGN}i440fx${CL}"
58-
echo -e "${DGN}Using Disk Cache: ${BGN}None${CL}"
59-
echo -e "${DGN}Using Hostname: ${BGN}${HN}${CL}"
60-
echo -e "${DGN}Using CPU Model: ${BGN}KVM64${CL}"
61-
echo -e "${DGN}Allocated Cores: ${BGN}${CORE_COUNT}${CL}"
62-
echo -e "${DGN}Allocated RAM: ${BGN}${RAM_SIZE}${CL}"
63-
echo -e "${DGN}Using Bridge: ${BGN}${BRG}${CL}"
64-
echo -e "${DGN}Using MAC Address: ${BGN}${MAC}${CL}"
65-
echo -e "${DGN}Using VLAN: ${BGN}Default${CL}"
66-
echo -e "${DGN}Using Interface MTU Size: ${BGN}Default${CL}"
67-
echo -e "${DGN}Start VM when completed: ${BGN}yes${CL}"
68-
echo -e "${BL}Creating a AllStarLink VM using the above default settings${CL}"
55+
vm_echo_default_settings
6956
}
7057

7158
function advanced_settings() {
7259
METHOD="advanced"
73-
while true; do
74-
if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 $NEXTID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
75-
if [ -z "$VMID" ]; then
76-
VMID="$NEXTID"
77-
fi
78-
if pct status "$VMID" &>/dev/null || qm status "$VMID" &>/dev/null; then
79-
echo -e "${CROSS}${RD} ID $VMID is already in use${CL}"
80-
sleep 2
81-
continue
82-
fi
83-
echo -e "${DGN}Virtual Machine ID: ${BGN}$VMID${CL}"
84-
break
85-
else
86-
exit_script
87-
fi
88-
done
89-
90-
if MACH=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "MACHINE TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \
91-
"i440fx" "Machine i440fx" ON \
92-
"q35" "Machine q35" OFF \
93-
3>&1 1>&2 2>&3); then
94-
if [ $MACH = q35 ]; then
95-
echo -e "${DGN}Using Machine Type: ${BGN}$MACH${CL}"
96-
FORMAT=""
97-
MACHINE=" -machine q35"
98-
else
99-
echo -e "${DGN}Using Machine Type: ${BGN}$MACH${CL}"
100-
FORMAT=",efitype=4m"
101-
MACHINE=""
102-
fi
103-
else
104-
exit_script
105-
fi
106-
107-
if DISK_CACHE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DISK CACHE" --radiolist "Choose" --cancel-button Exit-Script 10 58 2 \
108-
"0" "None (Default)" ON \
109-
"1" "Write Through" OFF \
110-
3>&1 1>&2 2>&3); then
111-
if [ $DISK_CACHE = "1" ]; then
112-
echo -e "${DGN}Using Disk Cache: ${BGN}Write Through${CL}"
113-
DISK_CACHE="cache=writethrough,"
114-
else
115-
echo -e "${DGN}Using Disk Cache: ${BGN}None${CL}"
116-
DISK_CACHE=""
117-
fi
118-
else
119-
exit_script
120-
fi
121-
122-
if VM_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 allstarlink --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
123-
if [ -z $VM_NAME ]; then
124-
HN="allstarlink"
125-
echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
126-
else
127-
HN=$(echo ${VM_NAME,,} | tr -d ' ')
128-
echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
129-
fi
130-
else
131-
exit_script
132-
fi
133-
134-
if CPU_TYPE1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "CPU MODEL" --radiolist "Choose" --cancel-button Exit-Script 10 58 2 \
135-
"0" "KVM64 (Default)" ON \
136-
"1" "Host" OFF \
137-
3>&1 1>&2 2>&3); then
138-
if [ $CPU_TYPE1 = "1" ]; then
139-
echo -e "${DGN}Using CPU Model: ${BGN}Host${CL}"
140-
CPU_TYPE=" -cpu host"
141-
else
142-
echo -e "${DGN}Using CPU Model: ${BGN}KVM64${CL}"
143-
CPU_TYPE=""
144-
fi
145-
else
146-
exit_script
147-
fi
148-
149-
if CORE_COUNT=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate CPU Cores" 8 58 2 --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
150-
if [ -z $CORE_COUNT ]; then
151-
CORE_COUNT="2"
152-
echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"
153-
else
154-
echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"
155-
fi
156-
else
157-
exit_script
158-
fi
159-
160-
if RAM_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate RAM in MiB" 8 58 2048 --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
161-
if [ -z $RAM_SIZE ]; then
162-
RAM_SIZE="4096"
163-
echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"
164-
else
165-
echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"
166-
fi
167-
else
168-
exit_script
169-
fi
170-
171-
if BRG=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
172-
if [ -z $BRG ]; then
173-
BRG="vmbr0"
174-
echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"
175-
else
176-
echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"
177-
fi
178-
else
179-
exit_script
180-
fi
181-
182-
if MAC1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a MAC Address" 8 58 $GEN_MAC --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
183-
if [ -z $MAC1 ]; then
184-
MAC="$GEN_MAC"
185-
echo -e "${DGN}Using MAC Address: ${BGN}$MAC${CL}"
186-
else
187-
MAC="$MAC1"
188-
echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}"
189-
fi
190-
else
191-
exit_script
192-
fi
193-
194-
if VLAN1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
195-
if [ -z $VLAN1 ]; then
196-
VLAN1="Default"
197-
VLAN=""
198-
echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}"
199-
else
200-
VLAN=",tag=$VLAN1"
201-
echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}"
202-
fi
203-
else
204-
exit_script
205-
fi
206-
207-
if MTU1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Interface MTU Size (leave blank for default)" 8 58 --title "MTU SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
208-
if [ -z $MTU1 ]; then
209-
MTU1="Default"
210-
MTU=""
211-
echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}"
212-
else
213-
MTU=",mtu=$MTU1"
214-
echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}"
215-
fi
216-
else
217-
exit_script
218-
fi
219-
220-
if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "START VIRTUAL MACHINE" --yesno "Start VM when completed?" 10 58); then
221-
echo -e "${DGN}Start VM when completed: ${BGN}yes${CL}"
222-
START_VM="yes"
223-
else
224-
echo -e "${DGN}Start VM when completed: ${BGN}no${CL}"
225-
START_VM="no"
226-
fi
227-
228-
if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create a AllStarLink VM?" --no-button Do-Over 10 58); then
229-
echo -e "${RD}Creating a AllStarLink VM using the above advanced settings${CL}"
60+
vm_prompt_vmid "${VMID:-$(get_valid_nextid)}"
61+
vm_prompt_machine_type "i440fx"
62+
vm_prompt_disk_size "8G"
63+
vm_prompt_disk_cache "none"
64+
vm_prompt_hostname "allstarlink"
65+
vm_prompt_cpu_model "kvm64"
66+
vm_prompt_cpu_cores "2"
67+
vm_prompt_ram "2048"
68+
vm_prompt_bridge "vmbr0"
69+
vm_prompt_mac "$GEN_MAC"
70+
vm_prompt_vlan
71+
vm_prompt_mtu
72+
vm_prompt_verbose "no"
73+
vm_prompt_start_vm "yes"
74+
75+
if vm_confirm_advanced_settings "Ready to create a AllStarLink VM?"; then
76+
echo -e "${CREATING}${BOLD}${DGN}Creating a AllStarLink VM using the above advanced settings${CL}"
23077
else
23178
header_info
232-
echo -e "${RD}Using Advanced Settings${CL}"
79+
echo -e "${ADVANCED}${BOLD}${RD}Using Advanced Settings${CL}"
23380
advanced_settings
23481
fi
23582
}
23683

237-
function start_script() {
238-
if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then
239-
header_info
240-
echo -e "${BL}Using Default Settings${CL}"
241-
default_settings
242-
else
243-
header_info
244-
echo -e "${RD}Using Advanced Settings${CL}"
245-
advanced_settings
246-
fi
247-
}
24884

24985
check_root
25086
arch_check
25187
pve_check
25288
ssh_check
253-
start_script
89+
vm_start_script "Use Default Settings?" 10 58
25490
post_to_api_vm
25591

256-
msg_info "Validating Storage"
257-
while read -r line; do
258-
TAG=$(echo $line | awk '{print $1}')
259-
TYPE=$(echo $line | awk '{printf "%-10s", $2}')
260-
FREE=$(echo $line | numfmt --field 4-6 --from-unit=K --to=iec --format %.2f | awk '{printf( "%9sB", $6)}')
261-
ITEM=" Type: $TYPE Free: $FREE "
262-
OFFSET=2
263-
if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then
264-
MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET))
265-
fi
266-
STORAGE_MENU+=("$TAG" "$ITEM" "OFF")
267-
done < <(pvesm status -content images | awk 'NR>1')
268-
VALID=$(pvesm status -content images | awk 'NR>1')
269-
if [ -z "$VALID" ]; then
270-
msg_error "Unable to detect a valid storage location."
271-
exit
272-
elif [ $((${#STORAGE_MENU[@]} / 3)) -eq 1 ]; then
273-
STORAGE=${STORAGE_MENU[0]}
274-
else
275-
while [ -z "${STORAGE:+x}" ]; do
276-
STORAGE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Storage Pools" --radiolist \
277-
"Which storage pool you would like to use for ${HN}?\nTo make a selection, use the Spacebar.\n" \
278-
16 $(($MSG_MAX_LENGTH + 23)) 6 \
279-
"${STORAGE_MENU[@]}" 3>&1 1>&2 2>&3) || exit
280-
done
281-
fi
282-
msg_ok "Using ${CL}${BL}$STORAGE${CL} ${GN}for Storage Location."
92+
vm_select_storage "$HN"
28393
msg_ok "Virtual Machine ID is ${CL}${BL}$VMID${CL}."
28494
msg_info "Retrieving the URL for the Debian 12 Qcow2 Disk Image"
28595
URL="https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-nocloud-$(dpkg --print-architecture).qcow2"

0 commit comments

Comments
 (0)