summary refs log tree commit diff
diff options
context:
space:
mode:
authorManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2019-05-31 22:30:07 +0200
committerManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2019-05-31 22:30:07 +0200
commit53fb9b1fa593d1f7bdf759fc34c7953a73f508e9 (patch)
treec104eb878e80b1cef606e0dfb832d4cbd2078185
downloadgeolocate-53fb9b1fa593d1f7bdf759fc34c7953a73f508e9.tar.gz
geolocate-53fb9b1fa593d1f7bdf759fc34c7953a73f508e9.tar.bz2
geolocate-53fb9b1fa593d1f7bdf759fc34c7953a73f508e9.zip
test
-rw-r--r--PKGBUILD32
-rwxr-xr-xgeolocate77
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 "${@}"