From 9a0a01274373ef5229ca5f0a27bf82b189033a24 Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Fri, 14 Apr 2017 15:24:59 -0700 Subject: [PATCH] Add IP validation Prevent user from direct copy/paste --- deploy/common.sh | 10 ++++++++++ deploy/longhorn-deploy-node.sh | 3 +++ 2 files changed, 13 insertions(+) diff --git a/deploy/common.sh b/deploy/common.sh index b50d71b..93a74f9 100644 --- a/deploy/common.sh +++ b/deploy/common.sh @@ -27,3 +27,13 @@ get_container_ip() { fi echo $ip } + +validate_ip() { + ip=$1 + rx='([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])' + if [[ $ip =~ ^$rx\.$rx\.$rx\.$rx$ ]]; then + return 0 + fi + echo Invalid ip address ${ip} + return 1 +} diff --git a/deploy/longhorn-deploy-node.sh b/deploy/longhorn-deploy-node.sh index c9e1c23..f10b53e 100755 --- a/deploy/longhorn-deploy-node.sh +++ b/deploy/longhorn-deploy-node.sh @@ -38,6 +38,9 @@ if [ "$etcd_ip" == "" ]; then exit 1 fi +# will error out if fail since we have set -e +validate_ip ${etcd_ip} + network_option= if [ "$network" != "" ]; then network_option="--network ${network}"