Skip to content

Commit

Permalink
hotfix : regex for private ip
Browse files Browse the repository at this point in the history
  • Loading branch information
kdgyun committed Jul 19, 2023
1 parent 43792d2 commit 1a09cca
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions install-k8s-1.24-for-ubuntu18-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ printstyle() {
# Return true if we pass in an IPv4 pattern.
valid_ip() {
rx="([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"
echo "hn"
if [[ $1 =~ ^$rx\.$rx\.$rx\.$rx$ ]]; then
if [[ $WITH_CNI == true ]]; then
#valid CIDR
Expand All @@ -36,14 +35,12 @@ valid_ip() {
printstyle "The host ip and private ip cannot be in the same range. \n" "danger"
return 0
fi

#172.16
elif [[ "$1" == *172.16.*.* ]]; then
if [[ "$2" == *172.16.*.* ]]; then
printstyle "The host ip and private ip cannot be in the same range. \n" "danger"
return 0
fi

#10.0
elif [[ "$1" == *10.0.*.* ]]; then
if [[ "$2" == *10.0.*.* ]]; then
Expand All @@ -52,9 +49,10 @@ valid_ip() {
fi
fi
# check a private ip range
if [[ "$2" == *192.168.*.* ]] || [[ "$1" == *172.16.*.* ]] || [[ "$1" == *10.0.*.* ]]; then
if [[ "$2" == *192.168.*.*/* ]] || [[ "$2" == *172.16.*.*/* ]] || [[ "$2" == *10.0.*.*/* ]]; then
return 1
else
printstyle "Incorrect format private IP address : $2 \n" "danger"
return 0
fi
else
Expand Down Expand Up @@ -215,7 +213,7 @@ elif [[ $VALID_WORKER == true ]] && [[ $VALID_PWD == false ]]; then
fi
# check Host-IP
if [[ $VALID_MASTER == true ]] || [[ $VALID_WORKER == true ]]; then
if [[ "$HOST_IP" -eq 1 ]]; then
if [[ -z "$HOST_IP" ]]; then
printstyle "No IP argument supplied. \n" "danger"
printstyle "Please run with IP address like x.x.x.x \n" "danger"
fi
Expand Down Expand Up @@ -483,5 +481,9 @@ if [[ $VALID_WORKER == true ]]; then
TOKENCOMM=$(</tmp/k8stkfile.kstk)
printstyle "excute command: $TOKENCOMM ... \n" 'info'
eval "$TOKENCOMM"
printstyle "Success! \n" 'success'
if [[ -n "$TOKENCOMM" ]]; then
printstyle "Success! \n" 'success'
else
printstyle "Failed! \n" 'danger'
fi
fi

0 comments on commit 1a09cca

Please sign in to comment.