parent
6f0d3cb494
commit
9bb80370b8
48
tldinfo.sh
48
tldinfo.sh
|
@ -15,7 +15,7 @@ ME_DIR="/$0"; ME_DIR=${ME_DIR%/*}; ME_DIR=${ME_DIR:-.}; ME_DIR=${ME_DIR#/}/; ME_
|
||||||
ME_SHORTNAME='tldinfo'
|
ME_SHORTNAME='tldinfo'
|
||||||
|
|
||||||
#
|
#
|
||||||
# number of seconds before warning about needing an update
|
# number of seconds before warning about TLD database needing an update
|
||||||
# 2592000 seconds = 30 days
|
# 2592000 seconds = 30 days
|
||||||
#
|
#
|
||||||
CHECKED_TIME_TTL=2592000
|
CHECKED_TIME_TTL=2592000
|
||||||
|
@ -283,7 +283,6 @@ init_data_root() {
|
||||||
>&2 echo "$ME_NAME: (fatal error) failed set permissions on data root '$root_path', do you need sudo?"
|
>&2 echo "$ME_NAME: (fatal error) failed set permissions on data root '$root_path', do you need sudo?"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
#init_data_file "tlds.tsv"
|
|
||||||
init_data_file "checked-time"
|
init_data_file "checked-time"
|
||||||
init_data_file "release"
|
init_data_file "release"
|
||||||
}
|
}
|
||||||
|
@ -337,6 +336,9 @@ print_data_file_path() { file_basename=$1
|
||||||
echo $path
|
echo $path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# wheather to download TLDS database from CDN
|
||||||
|
#
|
||||||
INITIAL_TLDS_DOWNLOAD=0
|
INITIAL_TLDS_DOWNLOAD=0
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -358,11 +360,10 @@ if [ "$INSTALL_MODE" = 1 ]; then
|
||||||
}
|
}
|
||||||
init_data_root
|
init_data_root
|
||||||
INITIAL_TLDS_DOWNLOAD=1
|
INITIAL_TLDS_DOWNLOAD=1
|
||||||
#UPDATE_MODE=1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
# prepare tld database
|
||||||
#
|
#
|
||||||
TLDS_PATH=$(print_data_file_path tlds.tsv)
|
TLDS_PATH=$(print_data_file_path tlds.tsv)
|
||||||
PROJECT_TLDS_PATH=$ME_DIR/formats/tsv/tlds.tsv
|
PROJECT_TLDS_PATH=$ME_DIR/formats/tsv/tlds.tsv
|
||||||
|
@ -387,7 +388,7 @@ if ( [ "$INSTALL_MODE" = 0 ] && [ ! -f "$TLDS_PATH" ] ); then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# wheather to check for update
|
# determine wheather to check for update
|
||||||
#
|
#
|
||||||
CHECK_UPDATE=0
|
CHECK_UPDATE=0
|
||||||
LAST_CHECKED_TIME=$(print_data_file_contents checked-time)
|
LAST_CHECKED_TIME=$(print_data_file_contents checked-time)
|
||||||
|
@ -476,13 +477,17 @@ if ( [ "$INITIAL_TLDS_DOWNLOAD" = 1 ] || [ "$UPDATE_MODE" = 1 ] || [ "$CHECK_UPD
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# exit if install mode
|
||||||
|
#
|
||||||
if [ "$INSTALL_MODE" = 1 ]; then
|
if [ "$INSTALL_MODE" = 1 ]; then
|
||||||
echo "install '$(basename $SYS_INSTALL_PATH)' success"
|
echo "install '$(basename $SYS_INSTALL_PATH)' success"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#printf "%-25s %-12s\n" "CONTAINER" "IP-ADDR"
|
#
|
||||||
|
# show description and type if domain <SEARCH> singleton
|
||||||
|
#
|
||||||
if ( [ -n "$SEARCH" ] && [ "$STARTS_WITH" = 0 ] ); then
|
if ( [ -n "$SEARCH" ] && [ "$STARTS_WITH" = 0 ] ); then
|
||||||
SHOW_DESC=1; SHOW_TYPE=1
|
SHOW_DESC=1; SHOW_TYPE=1
|
||||||
fi
|
fi
|
||||||
|
@ -490,22 +495,40 @@ if [ "$STARTS_WITH" = 1 ]; then
|
||||||
MATCH_COUNT=0
|
MATCH_COUNT=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# configre IFS with {tab} delimiter
|
||||||
|
#
|
||||||
IFS_OLD=$IFS
|
IFS_OLD=$IFS
|
||||||
IFS=$(printf "\t")
|
IFS=$(printf "\t")
|
||||||
|
|
||||||
|
#
|
||||||
|
# read tlds.tsv database
|
||||||
|
#
|
||||||
while read domain desc type; do
|
while read domain desc type; do
|
||||||
|
#
|
||||||
|
# apply <SEARCH> arg
|
||||||
|
#
|
||||||
if [ -n "$SEARCH" ]; then
|
if [ -n "$SEARCH" ]; then
|
||||||
if [ "$STARTS_WITH" = 0 ]; then
|
if [ "$STARTS_WITH" = 0 ]; then
|
||||||
|
#
|
||||||
|
# match <SEARCH> singleton
|
||||||
|
#
|
||||||
if [ "$domain" != "$SEARCH" ]; then
|
if [ "$domain" != "$SEARCH" ]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
#
|
||||||
|
# match --starts-with <SEARCH>
|
||||||
|
#
|
||||||
case $domain in
|
case $domain in
|
||||||
$SEARCH*) MATCH_COUNT=$((MATCH_COUNT+1));;
|
$SEARCH*) MATCH_COUNT=$((MATCH_COUNT+1));;
|
||||||
*) continue;;
|
*) continue;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
#
|
||||||
|
# concatenate TLD info for display
|
||||||
|
#
|
||||||
line=
|
line=
|
||||||
if ( [ -z "$SEARCH" ] || [ "$STARTS_WITH" = 1 ] ); then
|
if ( [ -z "$SEARCH" ] || [ "$STARTS_WITH" = 1 ] ); then
|
||||||
line=$domain
|
line=$domain
|
||||||
|
@ -519,18 +542,27 @@ while read domain desc type; do
|
||||||
line="$line$type"
|
line="$line$type"
|
||||||
}
|
}
|
||||||
printf "$line\n"
|
printf "$line\n"
|
||||||
|
#
|
||||||
|
# exit on matched <SEARCH> singleton
|
||||||
|
#
|
||||||
if ( [ -n "$SEARCH" ] && [ "$STARTS_WITH" = 0 ] ); then
|
if ( [ -n "$SEARCH" ] && [ "$STARTS_WITH" = 0 ] ); then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
done < $TLDS_PATH
|
done < $TLDS_PATH
|
||||||
|
|
||||||
|
#
|
||||||
|
# set IFS to default delimiter
|
||||||
|
#
|
||||||
IFS=$IFS_OLD
|
IFS=$IFS_OLD
|
||||||
|
|
||||||
|
#
|
||||||
|
# display summary for results of --starts-with <SEARCH>
|
||||||
|
#
|
||||||
if ( [ -n "$SEARCH" ] && ( [ "$STARTS_WITH" = 0 ] || [ "$MATCH_COUNT" = 0 ] ) ); then
|
if ( [ -n "$SEARCH" ] && ( [ "$STARTS_WITH" = 0 ] || [ "$MATCH_COUNT" = 0 ] ) ); then
|
||||||
[ "$STARTS_WITH" = 0 ] && >&2 echo "domain '$SEARCH' not found"
|
[ "$STARTS_WITH" = 0 ] && >&2 echo "domain '$SEARCH' not found"
|
||||||
[ "$MATCH_COUNT" = 0 ] && >&2 echo "no domains starting with '$SEARCH' found"
|
[ "$MATCH_COUNT" = 0 ] && >&2 echo "no domains starting with '$SEARCH' found"
|
||||||
exit 20
|
exit 20
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$STARTS_WITH" = 1 ]; then
|
if [ "$STARTS_WITH" = 1 ]; then
|
||||||
>&2 echo ""
|
>&2 echo ""
|
||||||
if [ "$MATCH_COUNT" = "1" ]; then
|
if [ "$MATCH_COUNT" = "1" ]; then
|
||||||
|
|
Loading…
Reference in New Issue