Browse Source

added json location getter

pull/1/head
Jeffrey Paul 4 years ago
parent
commit
6eaf2cca28
2 changed files with 47 additions and 0 deletions
  1. +15
    -0
      Makefile
  2. +32
    -0
      update-workstation-location/update-location-json.sh

+ 15
- 0
Makefile View File

@@ -0,0 +1,15 @@
TARGETS := \
$(HOME)/Library/Local/bin/update-location-json.sh

.PHONY: install $(TARGETS)

default: install

install: $(TARGETS)

$(HOME)/Library/Local/bin:
mkdir -p $@

$(HOME)/Library/Local/bin/update-location-json.sh:
cp $(PWD)/update-workstation-location/update-location-json.sh $@
chmod +x $@

+ 32
- 0
update-workstation-location/update-location-json.sh View File

@@ -0,0 +1,32 @@
#!/bin/bash

set -x

LOCFILE="$HOME/.location.json"
IP_REGEX='((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])'

URL="http://freegeoip.net/json/"


if [[ -e $LOCFILE ]]; then
LOCFILE_AGE=$(($(date +%s) - $(date -r "$LOCFILE" +%s)))
else
LOCFILE_AGE=999999
fi

if [[ $LOCFILE_AGE -gt 21600 ]]; then #6h
UPDATE=1
else
UPDATE=0
fi

if [[ $UPDATE -eq 0 ]]; then
exit 0
fi

#CUR_IP=$(curl -sq http://checkip.dyndns.org | grep -oE $IP_REGEX)
#echo "CUR_IP=$CUR_IP" > $LOCFILE.new

curl -fsSL https://freegeoip.net/json > $LOCFILE.new && \
mv $LOCFILE.new $LOCFILE && \
jq . $LOCFILE

Loading…
Cancel
Save