@@ -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