diff --git a/misc/build.func b/misc/build.func index cd3d68a..2cb6e58 100644 --- a/misc/build.func +++ b/misc/build.func @@ -697,18 +697,14 @@ config_file() { fi if [[ -n "$CT_ID" ]]; then - if [[ "$CT_ID" =~ ^([0-9]{3,4})-([0-9]{3,4})$ ]]; then MIN_ID=${BASH_REMATCH[1]} MAX_ID=${BASH_REMATCH[2]} - if ((MIN_ID >= MAX_ID)); then msg_error "Invalid Container ID range. The first number must be smaller than the second number, was ${CT_ID}" exit fi - LIST_OF_IDS=$(pvesh get /cluster/resources --type vm --output-format json | grep -oP '"vmid":\s*\K\d+') - if [[ ! -z "$LIST_OF_IDS" ]]; then for ((ID = MIN_ID; ID <= MAX_ID; ID++)); do if ! grep -q "^$ID$" <<<"$LIST_OF_IDS"; then @@ -716,20 +712,22 @@ config_file() { break fi done - else - CT_ID=$MIN_ID fi - echo -e "${CONTAINERID}${BOLD}${DGN}Container ID: ${BGN}$CT_ID${CL}" elif [[ "$CT_ID" =~ ^[0-9]+$ ]]; then LIST_OF_IDS=$(pvesh get /cluster/resources --type vm --output-format json | grep -oP '"vmid":\s*\K\d+') - if ! grep -q "^$CT_ID$" <<<"$LIST_OF_IDS"; then - echo -e "${CONTAINERID}${BOLD}${DGN}Container ID: ${BGN}$CT_ID${CL}" + if [[ -n "$LIST_OF_IDS" ]]; then + + if ! grep -q "^$CT_ID$" <<<"$LIST_OF_IDS"; then + echo -e "${CONTAINERID}${BOLD}${DGN}Container ID: ${BGN}$CT_ID${CL}" + else + msg_error "Container ID $CT_ID already exists" + exit + fi else - msg_error "Container ID $CT_ID already exists" - exit + echo -e "${CONTAINERID}${BOLD}${DGN}Container ID: ${BGN}$CT_ID${CL}" fi else msg_error "Invalid Container ID format. Needs to be 0000-9999 or 0-9999, was ${CT_ID}"