From 8f8588939ba8b40e8df8dcfcb88ff59abe3aa308 Mon Sep 17 00:00:00 2001
From: Bryan Joshua Pedini <bryan@pedini.dev>
Date: Thu, 13 Mar 2025 03:10:35 +0100
Subject: [PATCH] added push script

---
 push.sh | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100755 push.sh

diff --git a/push.sh b/push.sh
new file mode 100755
index 0000000..e815b16
--- /dev/null
+++ b/push.sh
@@ -0,0 +1,74 @@
+#!/usr/bin/env bash
+set -e
+
+# Temp file and PKGBUILD information
+TMPFILE=$(mktemp)
+grep -E "pkgname=|pkgver=|pkgrel=|url=|arch=" PKGBUILD > ${TMPFILE}
+sed -n -e '/source/,/)/ p' PKGBUILD >> ${TMPFILE}
+source ${TMPFILE}
+aur_url="ssh://aur@aur.archlinux.org/${pkgname}.git"
+
+# Get new version
+if [ $# -eq 1 ]; then
+  newver="${1}"
+else
+  echo "Old version: ${pkgver}"
+  read -p "New version: " newver
+fi
+# Check version
+if [ "${newver}" = "${pkgver}" ]; then
+  echo >/dev/stderr "Error: same (old) version specified - update aborted"
+  exit 1
+fi
+
+# Perform variable substitution
+sed -i -E "s/^pkgver=\"[^\"]+\"/pkgver=\"$newver\"/" ${TMPFILE}
+source ${TMPFILE}
+
+sednewline="n;"
+# Iterate over architectures
+for architecture in "${arch[@]}"; do
+  sednumlines=""
+  # Iterate over files listed in $source variable
+  eval "sources=(\${source_$architecture[@]})"
+  for file_url in "${sources[@]}"; do
+    # Remove potential file renaming in source file
+    file_url=$(echo ${file_url} | sed 's/.*:://')
+    # Perform action only on web links
+    if [[ $file_url == http* ]]; then
+      # Extract everything after last "/"
+      filename="${file_url##*/}"
+      # Download new file
+      wget -O ${filename} "${file_url}"
+
+      # Calculate checksums
+      sha1sum=$(sha1sum ${filename} | awk '{print $1}')
+      sha256sum=$(sha256sum ${filename} | awk '{print $1}')
+      md5sum=$(md5sum ${filename} | awk '{print $1}')
+
+      # Update PKGBUILD with new values
+      sednumlines="${sednumlines}${sednewline}"
+      sed -i "/sha1sums_${architecture}/{${sednumlines}s/\".*\"/\"${sha1sum}\"/}" PKGBUILD
+      sed -i "/sha256sums_${architecture}/{${sednumlines}s/\".*\"/\"${sha256sum}\"/}" PKGBUILD
+      sed -i "/md5sums_${architecture}/{${sednumlines}s/\".*\"/\"${md5sum}\"/}" PKGBUILD
+      # Yoink source - not necessary anymore
+      rm -f ${filename}
+    fi
+  done # Files loop
+done # Architectures loop
+
+# Update the last PKGBUILD value, the version
+sed -i -E "s/^pkgver=\"[^\"]+\"/pkgver=\"$newver\"/" PKGBUILD
+
+# Yoink temp file
+rm -f ${TMPFILE}
+
+# Update .SRCINFO
+makepkg --printsrcinfo > .SRCINFO
+
+# In case of fire, git commit, git push, leave building
+git add PKGBUILD .SRCINFO
+git commit -m "Updated ${pkgname} to ${pkgver}-${pkgrel}"
+git remote add aur ${aur_url}
+git push origin main
+git push aur main:master