summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShih-Yuan Lee (FourDollars) <[email protected]>2025-01-15 16:14:15 +0800
committerShih-Yuan Lee (FourDollars) <[email protected]>2025-01-15 16:14:54 +0800
commit1c4b489ec014ad916cc90a4bdcc7cd5c33c66761 (patch)
treea2c8d411de89449ff9f0d005b7fb3d8e8679ace6
parent00ca0864900007e2a275015bd8240369fc66770e (diff)
list-packages.sh: List published packages in the specific PPA.
-rw-r--r--debian/install1
-rwxr-xr-xlist-packages.sh68
2 files changed, 69 insertions, 0 deletions
diff --git a/debian/install b/debian/install
index 9f4aa8e..6a7b8e4 100644
--- a/debian/install
+++ b/debian/install
@@ -23,3 +23,4 @@ c3-v2-api.py /usr/bin
put-dell-embargo.sh /usr/bin
trigger_sanity_c3.py /usr/bin
onesshup.sh /usr/bin
+list-packages.sh /usr/bin
diff --git a/list-packages.sh b/list-packages.sh
new file mode 100755
index 0000000..67371c8
--- /dev/null
+++ b/list-packages.sh
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+set -euo pipefail
+
+OPTS="$(getopt -o a:c:h --long arch:,codename:,help -n 'list-packages.sh' -- "$@")"
+
+ARCH=$(dpkg --print-architecture)
+CODENAME=$(lsb_release -c -s)
+PPA=
+eval set -- "${OPTS}"
+
+help() {
+ cat <<ENDLINE
+USAGE:
+
+ This command will list published packages for the specified arch in a given PPA.
+
+ $0 ppa:whatever/you-like [OPTIONS]
+
+OPTIONS:
+
+ -a | --arch
+ If not specified, it will use the output of \`dpkg --print-architecture\`.
+ -c | --codename ${CODENAME}
+ If not specified, it will use the output of \`lsb_release -c -s\`.
+ENDLINE
+}
+
+while :; do
+ case "$1" in
+ ('-h'|'--help')
+ help
+ exit ;;
+ ('-a'|'--arch')
+ ARCH="$2"
+ shift 2;;
+ ('-c'|'--codename')
+ CODENAME="$2"
+ shift 2;;
+ ('--') shift; break ;;
+ (*) break ;;
+ esac
+done
+
+if [ "$#" -ne 1 ]; then
+ help
+ exit 1
+fi
+
+PPA="$1"
+
+if [[ "$PPA" =~ ^ppa: ]]; then
+ GROUP=$(echo "${PPA//[:\/]/ }" | awk '{print $2}')
+ ARCHIVE=$(echo "${PPA//[:\/]/ }" | awk '{print $3}')
+else
+ echo "Please give a valid PPA name. '$PPA' is not a valid PPA name."
+ help
+ exit 1
+fi
+
+lp-api get "~$GROUP/+archive/ubuntu/$ARCHIVE" ws.op==getPublishedBinaries "distro_arch_series==https://api.launchpad.net/devel/ubuntu/$CODENAME/$ARCH" pocket==Release status==Published order_by_date==true > /tmp/payload.json
+jq -r .entries.[].binary_package_name < /tmp/payload.json
+link=$(jq -r .next_collection_link < /tmp/payload.json)
+while [ "$link" != "null" ]; do
+ lp-api get "$link" > /tmp/payload.json
+ jq -r .entries.[].binary_package_name < /tmp/payload.json
+ link=$(jq -r .next_collection_link < /tmp/payload.json)
+done