From cd6352b895d94e0d82d999ef78331f8a19047284 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Fri, 2 Dec 2022 14:26:46 -0500
Subject: linhes-dev: chk_aur_pkg.py: initial inclusion

---
 linhes/linhes-dev/PKGBUILD       |  5 ++-
 linhes/linhes-dev/chk_aur_pkg.py | 79 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 2 deletions(-)
 create mode 100755 linhes/linhes-dev/chk_aur_pkg.py

diff --git a/linhes/linhes-dev/PKGBUILD b/linhes/linhes-dev/PKGBUILD
index 3c6287e..88d34b9 100644
--- a/linhes/linhes-dev/PKGBUILD
+++ b/linhes/linhes-dev/PKGBUILD
@@ -1,14 +1,15 @@
 pkgname=linhes-dev
 pkgver=9.0.0
-pkgrel=9
+pkgrel=10
 pkgdesc="Scripts to develop LinHES"
 arch=('x86_64')
 license=('GPL2')
 depends=('clean-chroot-manager' 'git' 'pacman-contrib' 'package-query' 'pigz'
          'python-gitpython' 'rclone' 'yaah')
 url="http://linhes.org/"
-source=('lh_sync.sh' 'mp.py' 'lh_setup_dev.sh' 'lh_update_db_repo.sh')
+source=('lh_sync.sh' 'chk_aur_pkg.py' 'mp.py' 'lh_setup_dev.sh' 'lh_update_db_repo.sh')
 sha256sums=('3a64b4125b56c6f95cc9dc85ce58ebd1c0612b22fb27c3e76d4d9a5570f2d61e'
+            '864192e9fe627c5a85d4c33ba30df7c870783a450f5fea7c550dd9490d48f2ab'
             'ae515d0ef707daf5565b828b5e16e3812bcbe5060754ad06f783173b3fa1dedd'
             '24310eb2e957d2ac56739ca8286fcf8bd87776f0daa1f7e7bc67d7e39018e8db'
             '86c9ebe77228f7e3cc07cb05f480e5584e0e3cad1b889b63a50821f7323bf449')
diff --git a/linhes/linhes-dev/chk_aur_pkg.py b/linhes/linhes-dev/chk_aur_pkg.py
new file mode 100755
index 0000000..6dc7fa5
--- /dev/null
+++ b/linhes/linhes-dev/chk_aur_pkg.py
@@ -0,0 +1,79 @@
+#!/usr/bin/python
+#Checks the aur version and compares it to the /data/dev/linhes_pkgbuild/linhes directory.
+
+
+import os,sys
+import shutil
+import urllib.request, urllib.error, urllib.parse
+import re
+import subprocess
+import glob
+
+def getArchVer():
+    try:
+        archVer = subprocess.check_output(["package-query", "-A", "-i", "-f %v", "--nocolor", currDirName])
+        archVer = archVer.strip().decode('utf-8')
+        return archVer
+    except:
+        return "None"
+
+def getLHVer():
+    pkgfile = currDir + "/PKGBUILD"
+    if not os.path.isfile(pkgfile):
+        print(currDirName + " version in LH PKGBUILD is:   Unknown")
+        print("    Can't find",pkgfile)
+        #sys.exit(2)
+    else:
+        LHVer=""
+        variables=["pkgbase", "pkgname", "pkgver", "pkgrel", "epoch"]
+        # Loop over contents to get our variables
+        # Use bash to do it because PKGBUILDs are very loose with their format
+        for item in variables:
+            v = subprocess.Popen(['/bin/bash','-c', 'source ' +
+                                 pkgfile +
+                                 '; echo ${' + item + '[@]}'],
+                                 stdout = subprocess.PIPE,)
+            value = v.communicate()[0].strip(b'\n')
+            value = value.decode('utf-8')
+            if item == "pkgbase":
+                pkgbase = value
+            elif item == "pkgname":
+                pkgname = value
+                pkglist = list(value.split())
+            elif item == "epoch":
+                if value:
+                    epoch = "%s:" %value
+                    LHVer=epoch
+            elif item == "pkgver":
+                pkgver = value
+            elif item == "pkgrel":
+                pkgrel = value
+        LHVer=LHVer + pkgver + "-" + pkgrel
+        return LHVer
+#        print(currDirName + " version in LH PKGBUILD is:   " + LHVer)
+
+def main():
+    global currDirName
+    global currDir
+
+    LHdir="/data/dev/linhes_pkgbuild/linhes/*"
+
+    for currDir in glob.glob(LHdir):
+        if os.path.isdir(currDir):
+            currDirName = os.path.basename(currDir)
+            if currDirName == "mythtv":
+                continue
+            archVer = getArchVer()
+            if archVer == "None":
+                continue
+            #print("Searching for " + currDirName + " on archlinux.org...")
+            #print("AUR:",archVer)
+            LHVer = getLHVer()
+            #print("LH:",LHVer)
+            if archVer != LHVer:
+                print(currDirName,"needs update: [AUR]:",archVer,"[LH]:",LHVer)
+
+if __name__ == "__main__":
+    print("--------------------------")
+    main()
+    print("--------------------------")
-- 
cgit v0.12