diff --git a/misc/build.func b/misc/build.func index 061ccaee8..1945677e6 100644 --- a/misc/build.func +++ b/misc/build.func @@ -250,6 +250,17 @@ write_config() { if whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "Write configfile" --yesno "Do you want to write the selections to a config file?" 10 60; then FILEPATH="/opt/community-scripts/${NSAPP}.conf" [[ "$GATE" =~ ",gw=" ]] && local GATE="${GATE##,gw=}" + + # Strip prefixes from parameters for config file storage + local SD_VALUE="${SD}" + local NS_VALUE="${NS}" + local MAC_VALUE="${MAC}" + local VLAN_VALUE="${VLAN}" + [[ "$SD" =~ ^-searchdomain= ]] && SD_VALUE="${SD#-searchdomain=}" + [[ "$NS" =~ ^-nameserver= ]] && NS_VALUE="${NS#-nameserver=}" + [[ "$MAC" =~ ^,hwaddr= ]] && MAC_VALUE="${MAC#,hwaddr=}" + [[ "$VLAN" =~ ^,tag= ]] && VLAN_VALUE="${VLAN#,tag=}" + if [[ ! -f $FILEPATH ]]; then cat <"$FILEPATH" # ${NSAPP} Configuration File @@ -272,10 +283,10 @@ IPV6_METHOD="${IPV6_METHOD:-none}" GATE="${GATE:-none}" APT_CACHER_IP="${APT_CACHER_IP:-none}" MTU="${MTU:-1500}" -SD="${SD:-none}" -NS="${NS:-none}" -MAC="${MAC:-none}" -VLAN="${VLAN:-none}" +SD="${SD_VALUE:-none}" +NS="${NS_VALUE:-none}" +MAC="${MAC_VALUE:-none}" +VLAN="${VLAN_VALUE:-none}" SSH="${SSH}" SSH_AUTHORIZED_KEY="${SSH_AUTHORIZED_KEY}" TAGS="${TAGS:-none}" @@ -310,10 +321,10 @@ IPV6_METHOD="${IPV6_METHOD:-none}" GATE="${GATE:-none}" APT_CACHER_IP="${APT_CACHER_IP:-none}" MTU="${MTU:-1500}" -SD="${SD:-none}" -NS="${NS:-none}" -MAC="${MAC:-none}" -VLAN="${VLAN:-none}" +SD="${SD_VALUE:-none}" +NS="${NS_VALUE:-none}" +MAC="${MAC_VALUE:-none}" +VLAN="${VLAN_VALUE:-none}" SSH="${SSH}" SSH_AUTHORIZED_KEY="${SSH_AUTHORIZED_KEY}" TAGS="${TAGS:-none}" @@ -807,7 +818,36 @@ advanced_settings() { if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" 10 58); then echo -e "${CREATING}${BOLD}${RD}Creating a ${APP} LXC using the above advanced settings${CL}" + + # Strip prefixes from DNS parameters for config file storage + local SD_VALUE="$SD" + local NS_VALUE="$NS" + local MAC_VALUE="$MAC" + local VLAN_VALUE="$VLAN" + [[ "$SD" =~ ^-searchdomain= ]] && SD_VALUE="${SD#-searchdomain=}" + [[ "$NS" =~ ^-nameserver= ]] && NS_VALUE="${NS#-nameserver=}" + [[ "$MAC" =~ ^,hwaddr= ]] && MAC_VALUE="${MAC#,hwaddr=}" + [[ "$VLAN" =~ ^,tag= ]] && VLAN_VALUE="${VLAN#,tag=}" + + # Temporarily store original values + local SD_ORIG="$SD" + local NS_ORIG="$NS" + local MAC_ORIG="$MAC" + local VLAN_ORIG="$VLAN" + + # Set clean values for config file writing + SD="$SD_VALUE" + NS="$NS_VALUE" + MAC="$MAC_VALUE" + VLAN="$VLAN_VALUE" + write_config + + # Restore original formatted values for container creation + SD="$SD_ORIG" + NS="$NS_ORIG" + MAC="$MAC_ORIG" + VLAN="$VLAN_ORIG" else clear header_info diff --git a/misc/config-file.func b/misc/config-file.func index ed72aa219..9799b4a4b 100644 --- a/misc/config-file.func +++ b/misc/config-file.func @@ -469,8 +469,11 @@ config_file() { SD="" echo -e "${SEARCH}${BOLD}${DGN}DNS Search Domain: ${BGN}Host${CL}" else - echo -e "${SEARCH}${BOLD}${DGN}DNS Search Domain: ${BGN}$SD${CL}" - SD="-searchdomain=$SD" + # Strip prefix if present for config file storage + local SD_VALUE="$SD" + [[ "$SD" =~ ^-searchdomain= ]] && SD_VALUE="${SD#-searchdomain=}" + echo -e "${SEARCH}${BOLD}${DGN}DNS Search Domain: ${BGN}$SD_VALUE${CL}" + SD="-searchdomain=$SD_VALUE" fi else if SD=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" 3>&1 1>&2 2>&3); then @@ -492,11 +495,14 @@ config_file() { NS="" echo -e "${NETWORK}${BOLD}${DGN}DNS Server IP Address: ${BGN}Host${CL}" else - if [[ "$NS" =~ $ip_regex ]]; then - echo -e "${NETWORK}${BOLD}${DGN}DNS Server IP Address: ${BGN}$NS${CL}" - NS="-nameserver=$NS" + # Strip prefix if present for config file storage + local NS_VALUE="$NS" + [[ "$NS" =~ ^-nameserver= ]] && NS_VALUE="${NS#-nameserver=}" + if [[ "$NS_VALUE" =~ $ip_regex ]]; then + echo -e "${NETWORK}${BOLD}${DGN}DNS Server IP Address: ${BGN}$NS_VALUE${CL}" + NS="-nameserver=$NS_VALUE" else - msg_error "Invalid IP Address format for DNS Server. Needs to be 0.0.0.0, was ${NS}" + msg_error "Invalid IP Address format for DNS Server. Needs to be 0.0.0.0, was ${NS_VALUE}" exit fi fi @@ -519,11 +525,14 @@ config_file() { MAC="" echo -e "${MACADDRESS}${BOLD}${DGN}MAC Address: ${BGN}Host${CL}" else - if [[ "$MAC" =~ ^([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}$ ]]; then - echo -e "${MACADDRESS}${BOLD}${DGN}MAC Address: ${BGN}$MAC${CL}" - MAC=",hwaddr=$MAC" + # Strip prefix if present for config file storage + local MAC_VALUE="$MAC" + [[ "$MAC" =~ ^,hwaddr= ]] && MAC_VALUE="${MAC#,hwaddr=}" + if [[ "$MAC_VALUE" =~ ^([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}$ ]]; then + echo -e "${MACADDRESS}${BOLD}${DGN}MAC Address: ${BGN}$MAC_VALUE${CL}" + MAC=",hwaddr=$MAC_VALUE" else - msg_error "MAC Address must be in the format xx:xx:xx:xx:xx:xx, was ${MAC}" + msg_error "MAC Address must be in the format xx:xx:xx:xx:xx:xx, was ${MAC_VALUE}" exit fi fi @@ -546,11 +555,14 @@ config_file() { VLAN="" echo -e "${VLANTAG}${BOLD}${DGN}Vlan: ${BGN}Host${CL}" else - if [[ "$VLAN" =~ ^-?[0-9]+$ ]]; then - echo -e "${VLANTAG}${BOLD}${DGN}Vlan: ${BGN}$VLAN${CL}" - VLAN=",tag=$VLAN" + # Strip prefix if present for config file storage + local VLAN_VALUE="$VLAN" + [[ "$VLAN" =~ ^,tag= ]] && VLAN_VALUE="${VLAN#,tag=}" + if [[ "$VLAN_VALUE" =~ ^-?[0-9]+$ ]]; then + echo -e "${VLANTAG}${BOLD}${DGN}Vlan: ${BGN}$VLAN_VALUE${CL}" + VLAN=",tag=$VLAN_VALUE" else - msg_error "VLAN must be an integer, was ${VLAN}" + msg_error "VLAN must be an integer, was ${VLAN_VALUE}" exit fi fi