parent
6ad22d684f
commit
6eaf2cca28
@ -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 $@
|
@ -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…
Reference in new issue