Changes to Config File Logic
This commit is contained in:
parent
2854a63c07
commit
5c648dd2ef
@ -697,18 +697,14 @@ config_file() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "$CT_ID" ]]; then
|
if [[ -n "$CT_ID" ]]; then
|
||||||
|
|
||||||
if [[ "$CT_ID" =~ ^([0-9]{3,4})-([0-9]{3,4})$ ]]; then
|
if [[ "$CT_ID" =~ ^([0-9]{3,4})-([0-9]{3,4})$ ]]; then
|
||||||
MIN_ID=${BASH_REMATCH[1]}
|
MIN_ID=${BASH_REMATCH[1]}
|
||||||
MAX_ID=${BASH_REMATCH[2]}
|
MAX_ID=${BASH_REMATCH[2]}
|
||||||
|
|
||||||
if ((MIN_ID >= MAX_ID)); then
|
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}"
|
msg_error "Invalid Container ID range. The first number must be smaller than the second number, was ${CT_ID}"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
LIST_OF_IDS=$(pvesh get /cluster/resources --type vm --output-format json | grep -oP '"vmid":\s*\K\d+')
|
LIST_OF_IDS=$(pvesh get /cluster/resources --type vm --output-format json | grep -oP '"vmid":\s*\K\d+')
|
||||||
|
|
||||||
if [[ ! -z "$LIST_OF_IDS" ]]; then
|
if [[ ! -z "$LIST_OF_IDS" ]]; then
|
||||||
for ((ID = MIN_ID; ID <= MAX_ID; ID++)); do
|
for ((ID = MIN_ID; ID <= MAX_ID; ID++)); do
|
||||||
if ! grep -q "^$ID$" <<<"$LIST_OF_IDS"; then
|
if ! grep -q "^$ID$" <<<"$LIST_OF_IDS"; then
|
||||||
@ -716,21 +712,23 @@ config_file() {
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
|
||||||
CT_ID=$MIN_ID
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${CONTAINERID}${BOLD}${DGN}Container ID: ${BGN}$CT_ID${CL}"
|
echo -e "${CONTAINERID}${BOLD}${DGN}Container ID: ${BGN}$CT_ID${CL}"
|
||||||
|
|
||||||
elif [[ "$CT_ID" =~ ^[0-9]+$ ]]; then
|
elif [[ "$CT_ID" =~ ^[0-9]+$ ]]; then
|
||||||
|
|
||||||
LIST_OF_IDS=$(pvesh get /cluster/resources --type vm --output-format json | grep -oP '"vmid":\s*\K\d+')
|
LIST_OF_IDS=$(pvesh get /cluster/resources --type vm --output-format json | grep -oP '"vmid":\s*\K\d+')
|
||||||
|
if [[ -n "$LIST_OF_IDS" ]]; then
|
||||||
|
|
||||||
if ! grep -q "^$CT_ID$" <<<"$LIST_OF_IDS"; then
|
if ! grep -q "^$CT_ID$" <<<"$LIST_OF_IDS"; then
|
||||||
echo -e "${CONTAINERID}${BOLD}${DGN}Container ID: ${BGN}$CT_ID${CL}"
|
echo -e "${CONTAINERID}${BOLD}${DGN}Container ID: ${BGN}$CT_ID${CL}"
|
||||||
else
|
else
|
||||||
msg_error "Container ID $CT_ID already exists"
|
msg_error "Container ID $CT_ID already exists"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo -e "${CONTAINERID}${BOLD}${DGN}Container ID: ${BGN}$CT_ID${CL}"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
msg_error "Invalid Container ID format. Needs to be 0000-9999 or 0-9999, was ${CT_ID}"
|
msg_error "Invalid Container ID format. Needs to be 0000-9999 or 0-9999, was ${CT_ID}"
|
||||||
exit
|
exit
|
||||||
|
Loading…
x
Reference in New Issue
Block a user