summaryrefslogtreecommitdiff
path: root/pcr-vs-aur
diff options
context:
space:
mode:
authorEsteban Carnevale <alfplayer@mailoo.org>2014-11-05 11:33:35 -0300
committerEsteban Carnevale <alfplayer@mailoo.org>2014-11-05 11:33:35 -0300
commitfceeed2f1946ecc26610079d14867b2305fe0117 (patch)
treed4387b0173fab690af51380e80bb5752b2e5d668 /pcr-vs-aur
parent5dea1cb51b010830ecad0d4e2ba875eef9a6c4ba (diff)
pcr-vs-aur: Add script
Diffstat (limited to 'pcr-vs-aur')
-rwxr-xr-xpcr-vs-aur162
1 files changed, 162 insertions, 0 deletions
diff --git a/pcr-vs-aur b/pcr-vs-aur
new file mode 100755
index 0000000..a27a168
--- /dev/null
+++ b/pcr-vs-aur
@@ -0,0 +1,162 @@
+#!/bin/bash
+
+# alfplayer
+# 2014-06-12
+#
+# Prints Parabola PCR packages with the corresponding AUR
+# packages, only if the version of the Parabola package is older
+# than the Arch package version.
+
+set -e
+
+name="aur-vs-pcr"
+
+baseconfpath="/etc/libredbdiff"
+basedbpath="/var/lib/libredbdiff"
+
+conffile="$baseconfpath/pacman.conf.parabola"
+conffilearch="$baseconfpath/pacman.conf.archlinux"
+
+dbpath="$basedbpath/pacman.parabola"
+dbpatharch="$basedbpath/pacman.archlinux"
+
+field_pkgname=40
+field_version=40
+field_time=10
+
+
+error() { echo -e "Error. $@" > /dev/stderr ; exit 1; }
+
+verbose=1
+
+while true ; do
+ if [[ $1 =~ ^(-v|--verbose)$ ]] ; then
+ verbose=0
+ shift
+ elif [[ $# == 1 && $1 =~ ^(-h|--help)$ ]] ; then
+ echo -e "${name}. Show PCR repository packages that need to be updated from AUR.
+Usage:
+${name} [pattern]\t\tRegular output.
+${name} -v [pattern]\t\tAlso print package names of unmatched and updated packages.
+
+Specify [pattern] to filter package names. It can be empty to show all PCR packages.
+
+Examples:
+${name} pkgtool\t\tSearches for package names including the substring \"pkgtool\".
+${name} ^emacs.*\t\tSearches for package names starting with \"emacs\".
+${name} -v emacs.*\t\tSame as previous but it also prints unmatched and updated packages."
+ exit 0
+ else
+ pattern="$1"
+ if [[ $2 ]] ; then
+ error "Bad arguments. Nothing done. Run \"aur-vs-pcr -h\" for usage information."
+ else
+ break
+ fi
+ fi
+done
+
+if ! which jshon > /dev/null ; then
+ echo "jshon is not installed (package \"jshon\")"
+fi
+
+# Save PCR package information to a file
+expac -S '%r/%n %v %b %p' -t '%F' | grep "^pcr" | cut -b 5- | \
+ awk -v pattern="$pattern" "\$1 ~ pattern" > /tmp/aur-vs-pcr.tmp
+
+pkgname_list="$(head -c -1 /tmp/aur-vs-pcr.tmp | awk '{print $1}' | sed ':a;N;$!ba;s/\n/ /g')"
+
+declare -Ax ver_arch time_arch maintainer_arch ood_arch provides_string_arch desc_arch
+
+pkg_count="$(wc -w <<< "${pkgname_list}")"
+
+set +m
+shopt -s lastpipe
+
+# Query using the HTTP AUR RPC about 400 packages at a time. The request is denied using 500.
+for (( j=0 ; j<pkg_count ; j=j+400 )); do
+ arg="$(cut -f $((j+1))-$((j+400)) -d ' ' <<< ${pkgname_list})"
+
+ arg_url="$(sed -e '1s/^/\&arg[]=/' -e 's/ /\&arg[]=/g' <<< "${arg}")"
+
+ i=1
+
+ curl -Lkgs "https://aur.archlinux.org/rpc.php?type=multiinfo${arg_url}" |
+ jshon -e results -a -e Name -u -p -e Version -u -p \
+ -e LastModified -u -p -e OutOfDate -u -p \
+ -e Maintainer -u -p -e Description -u |
+ while read -r var ; do
+ if [[ $i == 1 ]] ; then
+ pkgname="$var"
+ elif [[ $i == 2 ]] ; then
+ ver_arch["$pkgname"]="$var"
+ elif [[ $i == 3 ]] ; then
+ time_arch["$pkgname"]="$(date -d @${var} +'%Y-%m-%d')"
+ elif [[ $i == 4 ]] ; then
+ ood_arch["$pkgname"]="$var"
+ elif [[ $i == 5 ]] ; then
+ maintainer_arch["$pkgname"]="$var"
+ elif [[ $i == 6 ]] ; then
+ desc_arch["$pkgname"]="$var"
+ i=0
+ fi
+ ((++i))
+ done
+done
+
+if [[ $verbose == 0 ]] ; then
+ printf_format="%s %-${field_pkgname}s%${field_version}s %${field_time}s %s\n"
+ printf_format_arch=" %-${field_pkgname}s%${field_version}s %${field_time}s %s\n"
+else
+ printf_format="%-$((field_pkgname+2))s%${field_version}s %${field_time}s %s\n"
+ printf_format_arch="%-$((field_pkgname+2))s%${field_version}s %${field_time}s %s\n"
+fi
+
+# Loop over PCR packages and print comparative information if the PCR version is older than AUR's version.
+while IFS= read -r line
+do
+ set -- ${line}
+ pkgname="$1"
+ ver="$2"
+ time="$3"
+ maintainer="${*:4}"
+
+ if [[ ${ver_arch["${pkgname}"]} ]] ; then
+ if [[ ${ver} < ${ver_arch["${pkgname}"]} ]] ; then
+ if [[ $verbose == 0 ]] ; then
+ # Print Parabola package data line
+ printf "${printf_format}" \
+ "<" \
+ "${pkgname}" \
+ "${ver}" \
+ "${time}" \
+ "${maintainer}"
+ else
+ # Print Parabola package data line
+ printf "${printf_format}" \
+ "${pkgname}" \
+ "${ver}" \
+ "${time}" \
+ "${maintainer}"
+ fi
+ # Print AUR package data line
+ printf "${printf_format_arch}" \
+ "" \
+ "${ver_arch["${pkgname}"]}" \
+ "${time_arch["${pkgname}"]}" \
+ "${maintainer_arch["${pkgname}"]}"
+ elif [[ ${ver} == ${ver_arch["${pkgname}"]} ]] ; then
+ if [[ $verbose == 0 ]] ; then
+ echo "= ${pkgname}"
+ fi
+ else
+ if [[ $verbose == 0 ]] ; then
+ echo "> ${pkgname}"
+ fi
+ fi
+ else
+ if [[ $verbose == 0 ]] ; then
+ echo "o ${pkgname}"
+ fi
+ fi
+done < /tmp/aur-vs-pcr.tmp