git » base-pkgbuilds.git » commit 29d6f65

srclist: utility with hopefully a future purpose

author Urja (ARMLFS builder)
2025-11-02 21:58:54 UTC
committer Urja (ARMLFS builder)
2025-11-02 21:58:54 UTC
parent 56e95d22ad9339952f03acbdb2c9249233134114

srclist: utility with hopefully a future purpose

the plan is to use this to help automate cleanup of old source
archives (but we do want to keep more than the most recent one, ofc)

srclist.sh +71 -0

diff --git a/srclist.sh b/srclist.sh
new file mode 100755
index 0000000..532fa36
--- /dev/null
+++ b/srclist.sh
@@ -0,0 +1,71 @@
+#!/bin/bash
+
+# extract the protocol from a source entry - return "local" for local sources
+get_protocol() {
+	if [[ $1 = *://* ]]; then
+		# strip leading filename
+		local proto="${1#*::}"
+		proto="${proto%%://*}"
+		# strip proto+uri://
+		printf "%s\n" "${proto%%+*}"
+	elif [[ $1 = *lp:* ]]; then
+		local proto="${1#*::}"
+		printf "%s\n" "${proto%%+lp:*}"
+	else
+		printf "%s\n" local
+	fi
+}
+
+# extract the filename from a source entry
+get_filename() {
+	local netfile=$1
+
+	# if a filename is specified, use it
+	if [[ $netfile = *::* ]]; then
+		printf "%s\n" "${netfile%%::*}"
+		return
+	fi
+
+	local proto=$(get_protocol "$netfile")
+
+	case $proto in
+		bzr|fossil|git|hg|svn)
+			filename=${netfile%%#*}
+			filename=${filename%%\?*}
+			filename=${filename%/}
+			filename=${filename##*/}
+			if [[ $proto = bzr ]]; then
+				filename=${filename#*lp:}
+			fi
+			if [[ $proto = fossil ]]; then
+				filename=$filename.fossil
+			fi
+			if [[ $proto = git ]]; then
+				filename=${filename%%.git*}
+			fi
+			;;
+		*)
+			# if it is just an URL, we only keep the last component
+			filename="${netfile##*/}"
+			;;
+	esac
+	printf "%s\n" "${filename}"
+}
+
+
+for arg; do
+  if [ ! -e $arg/PKGBUILD ]; then
+    continue
+  fi
+
+  (cd $arg;
+  for src in $(su builder -c "makepkg --printsrcinfo" | grep "^	source = " | cut -d ' ' -f 3-); do
+    p=$(get_protocol "$src")
+    if [ "$p" = "local" ]; then
+      continue
+    fi
+    name=$(get_filename "$src")
+    echo $(basename `pwd`) $name
+  done
+  )
+done