Skip to content

Commit 287d85e

Browse files
authored
Merge pull request #17 from mdlmarkham/copilot/sub-pr-16
Fix robustness issues in Proxmox multi-container installation
2 parents 0a7df6d + 3eb3501 commit 287d85e

File tree

2 files changed

+56
-16
lines changed

2 files changed

+56
-16
lines changed

scripts/install/install-proxmox-multi.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ CONTAINER_START_TIMEOUT=30
6868
INSTALL_TIMEOUT=600
6969
NON_INTERACTIVE=false
7070

71+
# Tarball exclusions for deployment
72+
TARBALL_EXCLUDES=(
73+
'--exclude=.git'
74+
'--exclude=*.pyc'
75+
'--exclude=__pycache__'
76+
'--exclude=venv'
77+
'--exclude=.env'
78+
)
79+
7180
# Deployment tracking
7281
declare -A DEPLOYMENT_STATUS
7382
declare -A DEPLOYMENT_IPS
@@ -224,7 +233,7 @@ resolve_container_ids() {
224233

225234
# Merge with CONTAINERS if specified
226235
if [ -n "$CONTAINERS" ]; then
227-
CONTAINERS="$CONTAINERS,${resolved_ids[*]}"
236+
CONTAINERS="$CONTAINERS,$(IFS=,; echo "${resolved_ids[*]}")"
228237
else
229238
CONTAINERS=$(IFS=,; echo "${resolved_ids[*]}")
230239
fi
@@ -358,11 +367,7 @@ EOF
358367
# Create tarball and copy
359368
local tarball="$temp_dir/tailops.tar.gz"
360369
(cd "$PROJECT_ROOT" && tar czf "$tarball" \
361-
--exclude='.git' \
362-
--exclude='*.pyc' \
363-
--exclude='__pycache__' \
364-
--exclude='venv' \
365-
--exclude='.env' \
370+
"${TARBALL_EXCLUDES[@]}" \
366371
.)
367372

368373
copy_to_container "$ctid" "$tarball" "/tmp/tailops.tar.gz" || return 1

scripts/install/lib/proxmox-api.sh

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,27 @@ fix_container_features() {
132132
if ! grep -q "^features:" "$config_file"; then
133133
echo "features: nesting=1,keyctl=1" >> "$config_file"
134134
else
135-
# Update existing features line
136-
sed -i 's/^features:.*/&,nesting=1,keyctl=1/' "$config_file"
137-
# Remove duplicate features
138-
sed -i 's/nesting=1,nesting=1/nesting=1/g' "$config_file"
139-
sed -i 's/keyctl=1,keyctl=1/keyctl=1/g' "$config_file"
135+
# Update existing features line robustly (avoid duplicates)
136+
current_features=$(grep '^features:' "$config_file" | head -n1 | cut -d':' -f2- | tr -d ' ')
137+
new_features="$current_features"
138+
# Add nesting=1 if missing
139+
if ! echo ",$new_features," | grep -q ",nesting=1,"; then
140+
if [ -n "$new_features" ]; then
141+
new_features="$new_features,nesting=1"
142+
else
143+
new_features="nesting=1"
144+
fi
145+
fi
146+
# Add keyctl=1 if missing
147+
if ! echo ",$new_features," | grep -q ",keyctl=1,"; then
148+
if [ -n "$new_features" ]; then
149+
new_features="$new_features,keyctl=1"
150+
else
151+
new_features="keyctl=1"
152+
fi
153+
fi
154+
# Replace the features line with the updated one
155+
sed -i "s/^features:.*/features: $new_features/" "$config_file"
140156
fi
141157

142158
# Enable TUN device for Tailscale
@@ -194,7 +210,12 @@ get_container_ip() {
194210
local ip
195211

196212
# Try to get IP from container's network interface
197-
ip=$(pct exec "$ctid" -- ip -4 addr show eth0 2>/dev/null | grep -oP 'inet \K[\d.]+' | head -1)
213+
# Dynamically detect the primary network interface (excluding 'lo')
214+
local iface
215+
iface=$(pct exec "$ctid" -- ip -o -4 addr show 2>/dev/null | awk '!/ lo / {print $2; exit}')
216+
if [ -n "$iface" ]; then
217+
ip=$(pct exec "$ctid" -- ip -4 addr show "$iface" 2>/dev/null | grep -oP 'inet \K[\d.]+' | head -1)
218+
fi
198219

199220
if [ -n "$ip" ]; then
200221
echo "$ip"
@@ -354,10 +375,24 @@ validate_container_requirements() {
354375
local rootfs
355376
rootfs=$(get_container_config "$ctid" "rootfs")
356377
if [ -n "$rootfs" ]; then
357-
local disk_size
358-
disk_size=$(echo "$rootfs" | grep -oP 'size=\K\d+' || echo "0")
359-
if [ "$disk_size" -gt 0 ] && [ "$disk_size" -lt "$min_disk" ]; then
360-
issues+=("Disk space ($disk_size GB) is less than minimum ($min_disk GB)")
378+
local disk_size_raw disk_size_num disk_size_unit disk_size_gb
379+
disk_size_raw=$(echo "$rootfs" | grep -oP 'size=\K[0-9]+[KMGTP]?' || echo "0")
380+
disk_size_num=$(echo "$disk_size_raw" | grep -oP '^\d+')
381+
disk_size_unit=$(echo "$disk_size_raw" | grep -oP '[KMGTP]$')
382+
# Default to G if no unit is specified
383+
if [ -z "$disk_size_unit" ]; then
384+
disk_size_unit="G"
385+
fi
386+
case "$disk_size_unit" in
387+
K) disk_size_gb=$((disk_size_num / 1024 / 1024));;
388+
M) disk_size_gb=$((disk_size_num / 1024));;
389+
G) disk_size_gb=$((disk_size_num));;
390+
T) disk_size_gb=$((disk_size_num * 1024));;
391+
P) disk_size_gb=$((disk_size_num * 1024 * 1024));;
392+
*) disk_size_gb=$((disk_size_num));; # fallback, treat as GB
393+
esac
394+
if [ "$disk_size_gb" -gt 0 ] && [ "$disk_size_gb" -lt "$min_disk" ]; then
395+
issues+=("Disk space ($disk_size_gb GB) is less than minimum ($min_disk GB)")
361396
fi
362397
fi
363398

0 commit comments

Comments
 (0)