#!/bin/bash # Copyright (C) 2018 David P. # Find deprecated Arch packages that are still in our blacklists. set -e # Repositories for specific arch'es. # Common repos are in 'repos' variable. repos="core extra community" repos_x86_64="$repos testing multilib multilib-testing" repos_i686="$repos testing build-support" repos_armv7h="$repos alarm" # although we don't sync [alarm] we blacklist its packages to conflict with your-freedom # Parabola repos for checking blacklists like your-privacy, # which sometimes block [libre] and [pcr] packages. # [nonprism] and [nonsystemd] are not listened because # we do not blacklists those packages anywhere repos_parabola="pcr pcr-multilib pcr-multilib-testing pcr-testing libre libre-multilib libre-multilib-testing libre-testing" # Set the blacklist files. The packages here always have a [libre] replacement if there's one. # aur-blacklist.txt is not here since we want to check Arch's official repos blacklists="blacklist.txt" # List here files that may also blacklist Parabola packages. # These are intended to be used with $repos_parabola blacklists_parabola="your-initfreedom-blacklist.txt your-privacy-blacklist.txt your-freedom_emu-blacklist.txt" # Mirrors. Please choose HTTPS over HTTP when possible # x86_64 mirrors for r in $repos_x86_64; do mirrors+=(https://mirrors.edge.kernel.org/archlinux/$r/os/x86_64/) done # i686 mirrors for r in $repos_i686; do mirrors+=(https://mirror.archlinux32.org/i686/$r/) done # armv7h mirrors for r in $repos_armv7h; do mirrors+=(https://fl.us.mirror.archlinuxarm.org/armv7h/$r/) done # Parabola mirrors, used to check [libre] and [pcr] packages if [[ $1 = parabola ]]; then for r in $repos_parabola; do mirrors+=(https://mirror.grapentin.org/parabola/$r/os/x86_64/) mirrors+=(https://mirror.grapentin.org/parabola/$r/os/i686/) mirrors+=(https://mirror.grapentin.org/parabola/$r/os/armv7h/) done fi # Sed expresion tested for Nginx, change if needed sedexp='s/.*href="//;s/\.pkg.tar.xz.*//' # extra sedexps for special characters/symbols sedexp+=';s/%2B/+/g;s/%3A/:/g;s/%40/@/g' usage() { cat < $parabola_pkgs # Separate packages by architecture for arch in x86_64 i686 armv7h any; do grep $arch$ $parabola_pkgs | for f in $(> $parabola_pkgs-$arch done done cat $parabola_pkgs-{x86_64,i686,armv7h,any} | sort -u > $parabola_pkgs ;; arch) curl -s ${mirrors[@]} | grep '".*.pkg.tar.xz"' | sed $sedexp > $arch_pkgs # Separate packages by architecture for arch in x86_64 i686 armv7h any; do grep $arch$ $arch_pkgs | for f in $(> $arch_pkgs-$arch done done cat $arch_pkgs-{x86_64,i686,armv7h,any} | sort -u > $arch_pkgs ;; esac } err() { printf '%s==> Error:%s %s\n' \ "$(tput bold;tput setaf 1)" \ "$(tput sgr0)" \ "$1" false } msg() { printf '%s==>%s %s\n' \ "$(tput bold;tput setaf 2)" \ "$(tput sgr0)" \ "$1" } submsg() { printf ' %s->%s %s\n' \ "$(tput bold;tput setaf 4)" \ "$(tput sgr0)" \ "$1" } compare_pkgs(){ # $1 is the pkgname and replacement (used when checking Arch pkgs) # $2 is the packages file list # We'll use this when we check Arch's pkgs only if ! [[ -e $libre_pkgs ]]; then libre_pkgs=$(mktemp) for r in libre libre-multilib libre-testing libre-multilib-testing; do mirrors_parabola+=(https://mirror.grapentin.org/parabola/$r/os/x86_64/) mirrors_parabola+=(https://mirror.grapentin.org/parabola/$r/os/i686/) mirrors_parabola+=(https://mirror.grapentin.org/parabola/$r/os/armv7h/) done curl -s ${mirrors[@]} | grep '".*.pkg.tar.xz"' | sed $sedexp > $libre_pkgs for arch in x86_64 i686 armv7h any; do grep $arch$ $libre_pkgs | for f in $(> $libre_pkgs-$arch done done cat $libre_pkgs-{x86_64,i686,armv7h,any} | sort -u > $libre_pkgs fi # First check if the pkg is available for # a specific architecture, if not, check # if it's for 'any' package="${1%%:*}" replacement="$(cut -d ":" -f1 <(echo $1))" for arch in x86_64 i686 armv7h; do grep $arch$ $2 | awk '{print $1}' | grep -xw ^$package &> /dev/null || \ grep any$ $2 | awk '{print $1}' | grep -xw ^$package &> /dev/null || \ if [ $2 = $arch_pkgs ]; then # Check if the package has a replacement, and # if such replacement is available for the same # architectures if ! [[ $replacement = "" ]]; then # If this works, it means the pkg doesn't exist for $arch in Arch, # but we have the [libre] replacement which should be deprecated. grep $arch$ $libre_pkgs | awk '{print $1}' | grep -xw ^$replacement &> /dev/null || \ grep any$ $libre_pkgs | awk '{print $1}' | grep -xw ^$replacement &> /dev/null && \ to_be_removed+=($arch) || is_not_for+=($arch) else # However if this fails, it means the pkg doesn't have a replacement # for $arch, or it simply doesn't have a replacement. is_not_for+=($arch) fi elif [ $2 = $parabola_pkgs ]; then if ! [[ $replacement = "" ]]; then # Look for the replacement grep $arch$ $parabola_pkgs | awk '{print $1}' | grep -xw ^$replacement &> /dev/null || \ grep any$ $parabola_pkgs | awk '{print $1}' | grep -xw ^$replacement &> /dev/null && \ to_be_deleted+=($arch) || isnt_for+=($arch) else isnt_for+=($arch) fi fi done for arch in ${to_be_removed[@]}; do submsg "$p ($arch) was not found, but we've a [libre] replacement which should be removed" done for arch in ${to_be_deleted[@]}; do submsg "$p ($arch) was not found, but we've $replacement as replacement and should be removed" done if [[ ${is_not_for[@]} = "x86_64 i686 armv7h" ]]; then submsg "$p was not found" fi if [[ ${isnt_for[@]} = "x86_64 i686 armv7h" ]]; then submsg "$p was not found" fi } check(){ mkpkglist $1 case $1 in parabola) msg 'Comparing blacklists with Parabola packages ...' pkgs=$(cut -d ":" -f1 $blacklists_parabola | grep -v ^#) for p in $pkgs; do compare_pkgs $p $parabola_pkgs done rm -f $parabola_pkgs msg 'done' ;; arch) msg 'Comparing blacklists with Arch packages ...' pkgs=$(grep -v ^# $blacklists | awk '{print $1}') for p in $pkgs; do compare_pkgs $p $arch_pkgs done rm -f $arch_pkgs msg 'done' ;; *) err "$1 is not a valid argument" ;; esac } if [[ $@ = "" ]]; then usage else ip r | grep ^default | awk '{print $3}' | ping -q -w 1 -c 1 $(tail -n1 /dev/stdin) &> /dev/null || err 'You must have internet connection to run this program' for arg in $@; do check $arg; done fi