diff options
-rw-r--r-- | PKGBUILD | 32 | ||||
-rwxr-xr-x | geolocate | 77 |
2 files changed, 109 insertions, 0 deletions
diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..20cf474 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,32 @@ +# Maintainer Manuel Palenzuela <sadshinobi@protonmail.com> + +author=Baitinq +pkgname=geolocate-git +pkgbase=geolocate +pkgver=r13.3c5f8a1 +pkgrel=1 +pkgdesc="Obtain an ip's approximate latitude and longitude in a simplistic format (latitude:longitude)" +url="https://github.com/Baitinq/geolocate" +depends=('bash' 'curl' 'jq' 'gnu-netcat') +makedepends=('git') +license=('GPL') +arch=('any') +source=("git+https://github.com/$author/$pkgbase.git") + +md5sums=('SKIP') +sha1sums=('SKIP') +sha256sums=('SKIP') + +pkgver() { + cd "${srcdir}/${pkgbase}" + + # Get the version number. + printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" +} + +package() { + cd "${srcdir}/${pkgbase}" + + # Install the program. + install -Dm755 geolocate "${pkgdir}/usr/bin/geolocate" +} diff --git a/geolocate b/geolocate new file mode 100755 index 0000000..b11846f --- /dev/null +++ b/geolocate @@ -0,0 +1,77 @@ +#!/bin/bash + +# Check for an internet connection +echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null 2>&1 + +if [ $? -eq 0 ]; then + : +else + echo "You are offline, this script requires an internet connection." + exit 1 +fi + +usage() { + echo -e "Usage: 'geolocate COMMAND'\n" + echo -e "A script to obtain the approximate latitude and longitude given an ip adress.\n" + echo -e "Commands:" + echo -e " help - print a summary of the script's function and usage." + echo -e " version - print the scripts version." + echo -e " ip:" + echo -e " ip 'blank' - print your public ip adress." + echo -e " ip 'IP' - get coordinates of a non-personal ip." +} + +getIp() { + PUBLIC_IP=`curl -s https://ipinfo.io/ip` + echo ${PUBLIC_IP} +} + +getCoord() { +curl -s https://ipvigilante.com/ | \ + jq '.data.latitude, .data.longitude' | \ + while read -r LATITUDE; do + read -r LONGITUDE + echo "${LATITUDE}:${LONGITUDE}" | tr -d '"' + done +} + + main() { + + case "$1" in + --help|-h|help|h) + usage + exit 0 + ;; + version) + version + exit 0 + ;; + ip|i) + case "$2" in + "") + getIp + exit 0 + ;; + *) + IP="$2" + curl -s https://ipvigilante.com/$IP | \ + jq '.data.latitude, .data.longitude' | \ + while read -r LATITUDE; do + read -r LONGITUDE + echo "${LATITUDE}:${LONGITUDE}" | tr -d '"' + done + exit 0 + ;; + esac + exit 0 + ;; + *) + getCoord + exit 0 + ;; + esac + exit 0 + } + + # call main function + main "${@}" |