summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2023-03-13 08:53:01 -0400
committerbill-auger <mr.j.spam.me@gmail.com>2023-12-14 17:13:11 -0500
commit1bad42dbfb2f51c8c04bccefa3d375b326c63f82 (patch)
treed8efc7410190cec4c0f20f9c78c99d1fc44de39e
parent8f4653db34f8ac8181e830325ea3a04e502fa785 (diff)
[blacklist-diffs]: initial script
-rwxr-xr-xblacklist-diffs130
1 files changed, 130 insertions, 0 deletions
diff --git a/blacklist-diffs b/blacklist-diffs
new file mode 100755
index 0000000..5720027
--- /dev/null
+++ b/blacklist-diffs
@@ -0,0 +1,130 @@
+#!/bin/bash
+
+# this script locates the upstream repo in which each blacklist entry exists;
+# and identifies blacklist entries which do not exist upstream
+#
+# TODO: determine which non-existing packages should exist on a per-arch basis,
+# perhaps with a cross-arch compare filter, or per-arch supplemental blacklists
+# (eg: blacklist.txt (all arches) , blacklist-armv7h.txt (armv7h only) , ...)
+
+
+## constants ##
+
+readonly DEBUG=0
+
+readonly BLACKLIST=/usr/share/doc/your-freedom/blacklist.txt
+readonly ARCH_MIRROR=http://mirror.cyberbits.eu/archlinux
+readonly ARCH_REPOS=( community{,-testing} core extra testing multilib{,-testing} )
+readonly TEMP_DB_NAME=blacklist-diffs
+
+readonly BLACKLIST_ERR_MSG="this script requires the 'your-freedom' package"
+readonly UNPRIVILEGED_ERR_MSG="this script requires super-user privileges"
+readonly CBLUE='\033[0;36m'
+readonly CRED='\033[0;31m'
+readonly CYELLOW='\033[0;33m'
+readonly CEND='\033[0m'
+
+BlacklistedPkgs=( $(sed 's|:.*||' ${BLACKLIST}) )
+DbTempdirs=() # Init()
+
+
+## helpers ##
+
+DBG() # (log_fmt [fmt_args]*)
+{
+ local log_fmt=$1
+ local fmt_args=( "${@:2}" )
+
+ (( DEBUG )) && printf "${CYELLOW}${log_fmt}${CEND}\n" "${fmt_args[@]}" >&2 || :
+}
+
+Log() # (log_fmt [fmt_args]*)
+{
+ local log_fmt=$1
+ local fmt_args=( "${@:2}" )
+
+ printf "${CBLUE}${log_fmt}${CEND}\n" "${fmt_args[@]}" >&2
+}
+
+LogError() # (log_fmt [fmt_args]*)
+{
+ local log_fmt=$1
+ local fmt_args=( "${@:2}" )
+
+ printf "${CRED}ERROR: ${log_fmt}${CEND}\n" "${fmt_args[@]}" >&2
+}
+
+Exit() # (log_fmt [fmt_args]*)
+{
+ LogError "$@" ; exit 1 ;
+}
+
+PacmanOpts() # (db_tempdir)
+{
+ local db_tempdir=$1
+
+ echo "--dbpath=${db_tempdir} --config=${db_tempdir}/pacman.conf"
+}
+
+
+## business ##
+
+Init() # (upstream_arch mirror_url repos*)
+{
+ local upstream_arch=$1
+ local mirror_url=$2
+ local repos=( ${@:3} )
+
+ # Setup the temporary directory
+ local db_tempdir="$(mktemp --tmpdir -d "${TEMP_DB_NAME}-${upstream_arch}.XXXXXXXXXX")"
+ DbTempdirs+=( ${db_tempdir} )
+
+ # populate the temporary package database
+ Log "updating database ...."
+ cd ${db_tempdir}
+ printf "[options]\nArchitecture = ${upstream_arch}\n" > pacman.conf
+ for repo in ${repos[@]}
+ do printf "[${repo}]\nServer = ${mirror_url}/\$repo/os/\$arch\n" >> pacman.conf
+ done
+ sudo pacman $(PacmanOpts ${db_tempdir}) -Sy &> /dev/null
+
+ echo ${db_tempdir}
+
+
+DBG "Init() db_tempdir=${db_tempdir}=$(printf "\n\t%s" $(ls ${db_tempdir}))"
+}
+
+Compare() # (db_tempdir)
+{
+ local db_tempdir=$1
+ local upstream_arch=$(sed "s|.*/${TEMP_DB_NAME}-\([^\.]*\)\..*|\1|" <<<${db_tempdir})
+ local upstream_pkgs=( $(pacman $(PacmanOpts ${db_tempdir}) -Ss | cut -d ' ' -f 1) )
+ local blacklisted_pkg upstream_pkg
+
+
+DBG "Compare() db_tempdir=${db_tempdir}"
+DBG "Compare() PacmanOpts=$(PacmanOpts ${db_tempdir})"
+DBG "Compare() upstream_arch=${upstream_arch}"
+DBG "Compare() upstream_pkgs=${upstream_pkgs[*]:0:4}"
+DBG "Compare() n_blacklisted_pkgs=${#BlacklistedPkgs[*]}"
+DBG "Compare() n_upstream_pkgs=${#upstream_pkgs[*]}"
+
+
+ Log "comparing (${#BlacklistedPkgs[*]}) blacklisted packages to (${#upstream_pkgs[*]}) ${upstream_arch} packages ...."
+ for blacklisted_pkg in ${BlacklistedPkgs[*]}
+ do upstream_pkg="$(grep ^[^/]*/${blacklisted_pkg}$ <(printf "%s\n" ${upstream_pkgs[*]}) || \
+ echo '<NONE>' | cut -d ' ' -f 1 )"
+ echo "${upstream_pkg} ${blacklisted_pkg}"
+ done | sort | column -t
+}
+
+
+trap "for tmpdir in ${DbTempdirs[*]} ; do rm -rf -- ${tmpdir} ; done ;" EXIT
+
+
+[[ -f "${BLACKLIST}" ]] || Exit "${BLACKLIST_ERR_MSG}"
+(( ${#BlacklistedPkgs[*]} )) || Exit "${BLACKLIST_ERR_MSG}"
+sudo pacman -Ss pacman &> /dev/null || Exit "${UNPRIVILEGED_ERR_MSG}"
+
+
+Compare $(Init x86_64 ${ARCH_MIRROR} ${ARCH_REPOS[*]})