From e6f025c8b019412daeb7dab69ca9c79b181f4893 Mon Sep 17 00:00:00 2001 From: JLKwong <61807745+JLKwong@users.noreply.github.com> Date: Wed, 24 Mar 2021 21:21:38 -0700 Subject: [PATCH] `treehouses remote reverse` unique (fixes #2129) (#2135) Co-authored-by: dogi --- modules/remote.sh | 17 ++++++++++++----- package.json | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/remote.sh b/modules/remote.sh index 55d373de48..6d3a2a2f69 100644 --- a/modules/remote.sh +++ b/modules/remote.sh @@ -71,11 +71,18 @@ function remote { ;; "reverse") checkargn $# 2 - reverse=$(internet reverse | sed -e 's#",\ "#"\n"#g' | cut -d'"' -f 2,3,4 | sed 's#\:[[:space:]]\"#:\"#g') - while IFS= read -r line; do - cmd_str+="\"$line\"," - done <<< "$reverse" - printf "{%s}\n" "${cmd_str::-1}" + reverse=$(internet reverse | sed -e 's#",\ "#"\n"#g' | cut -d'"' -f 2,3,4 | sed 's#\:[[:space:]]\"#:\"#g' | awk '!x[$0]++') + while IFS= read -r line; do + cmd_str+="\"$line\"," + done <<< "$reverse" + ip=$(printf "%s\n" "${cmd_str::-1}" | cut -d',' -f 1) + org=$(printf "%s\n" "${cmd_str::-1}" | cut -d',' -f 5) + country=$(printf "%s\n" "${cmd_str::-1}" | cut -d',' -f 4) + city=$(printf "%s\n" "${cmd_str::-1}" | cut -d',' -f 3) + postal=$(printf "%s\n" "${cmd_str::-1}" | cut -d',' -f 2) + timezone=$(printf "%s\n" "${cmd_str::-1}" | cut -d',' -f 6) + + echo "{$ip,$org,$country,$city,$postal,$timezone}" ;; "allservices") checkargn $# 1 diff --git a/package.json b/package.json index fb7d9cae3d..9be1d3578e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@treehouses/cli", - "version": "1.25.34", + "version": "1.25.35", "remote": "4000", "description": "Thin command-line interface for Raspberry Pi low level configuration.", "main": "cli.sh",