[profiles/base] change check_ip script
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/bin/bash
|
||||
|
||||
readonly SCRIPT_NAME=${0##*/}
|
||||
SCRIPT_NAME="${0##*/}"
|
||||
readonly SCRIPT_NAME
|
||||
|
||||
check_deps() {
|
||||
command -v curl >/dev/null 2>&1 || die "curl: command not found"
|
||||
@@ -22,34 +23,40 @@ EOF
|
||||
}
|
||||
|
||||
shell_quote() {
|
||||
local -r string=$1
|
||||
printf "'%s'" "${string//'/'\\''}"
|
||||
local -r string="$1"
|
||||
printf "'%s'" "${string//'/'\\''/}"
|
||||
}
|
||||
|
||||
die() {
|
||||
local -r message=$1
|
||||
local -r message="$1"
|
||||
printf "%s: %b\n" "${SCRIPT_NAME}" "${message}" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
invalid_option() {
|
||||
local -r option=$1
|
||||
die "invalid option $(shell_quote "${option}")\nTry '${SCRIPT_NAME} --help' for usage."
|
||||
local -r option="$1"
|
||||
die "invalid option $(shell_quote "${option}")
|
||||
Try '${SCRIPT_NAME} --help' for usage."
|
||||
}
|
||||
|
||||
parse_args() {
|
||||
family="auto"
|
||||
while (($# > 0)); do
|
||||
case "$1" in
|
||||
-h|--help) usage; exit 0 ;;
|
||||
-h | --help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
--family)
|
||||
( (( $# < 2 )) || [[ -z "$2" ]] ) && die "--family requires an argument (auto, 4 or 6)"
|
||||
family=$2
|
||||
( (($# < 2)) || [[ -z "$2" ]]) &&
|
||||
die "--family requires an argument (auto, 4 or 6)"
|
||||
family="$2"
|
||||
shift 2
|
||||
;;
|
||||
--family=*)
|
||||
family=${1#*=}
|
||||
[[ -z "${family}" ]] && die "--family requires an argument (auto, 4 or 6)"
|
||||
family="${1#*=}"
|
||||
[[ -z "${family}" ]] &&
|
||||
die "--family requires an argument (auto, 4 or 6)"
|
||||
shift
|
||||
;;
|
||||
*) invalid_option "$1" ;;
|
||||
@@ -59,9 +66,9 @@ parse_args() {
|
||||
}
|
||||
|
||||
validate_args() {
|
||||
case ${family} in
|
||||
case "${family}" in
|
||||
auto | 4 | 6) ;;
|
||||
*) die "invalid value for family: '${family}' (expected auto, 4 or 6)"
|
||||
*) die "invalid value for family: '${family}' (expected auto, 4 or 6)" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user