#!/bin/bash # blacklist-diffs - locates the upstream repo in which each blacklist entry exists; # and identifies blacklist entries which do not exist upstream # # Copyright (C) 2023 bill-auger # # SPDX-License-Identifier: AGPL-3.0-or-later # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # # # 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 '' | 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[*]})