find-deprecated 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. #!/bin/bash
  2. # Copyright (C) 2018-2021 David P. <megver83@parabola.nu>
  3. # Find deprecated Arch packages that are still in our blacklists.
  4. # shellcheck disable=SC2154
  5. usage(){
  6. # NOTE: the package architecture is always specified with 'parabola', and
  7. # in 'arch' only when there's an uneeded replacement. This is because your-freedom
  8. # is for any architecture and no matter if you use Parabola x86_64 or i686, it
  9. # will always conflict packages that are even for armv7h only (and vice versa).
  10. # The 'parabola' argument compares with our repositories and Arch's
  11. # since in blacklists like your-privacy and your-initfreedom we also block
  12. # some packages from [pcr] (like jitsi) and [libre] (like icedove), and
  13. # probably also from their -multilib, -testing and -multilib-testing derivatives.
  14. cat <<EOM
  15. Usage: ${0##*/} [arch|parabola]
  16. Check if there are inexistent packages in the blacklists.
  17. Arguments:
  18. arch Compares ArchLinux{32,ARM} blacklists with their
  19. repositories.
  20. parabola Compares Arch & Parabola blacklists with Parabola's
  21. and Arch's repos.
  22. Configuration is read from a file called find-deprecated.conf in the same directory
  23. as this script.
  24. To easily remove a package from a blacklist, you can use the following sed expresion:
  25. sed '/^pkgname:/d' -i blacklist.txt
  26. EOM
  27. }
  28. err(){
  29. printf '%s==> Error:%s %s\n' \
  30. "$(tput bold;tput setaf 1)" \
  31. "$(tput sgr0)" \
  32. "$1"
  33. exit 1
  34. }
  35. msg(){
  36. printf '%s==>%s %s\n' \
  37. "$(tput bold;tput setaf 2)" \
  38. "$(tput sgr0)" \
  39. "$1"
  40. }
  41. submsg(){
  42. printf ' %s->%s %s\n' \
  43. "$(tput bold;tput setaf 4)" \
  44. "$(tput sgr0)" \
  45. "$1"
  46. }
  47. add(){
  48. list="$(( list + 1 ))"
  49. }
  50. compare_pkgs(){
  51. # $1 is the pkgname and replacement (used when checking Arch pkgs)
  52. # $2 is the packages file list
  53. local to_be_removed
  54. local is_not_for
  55. local to_be_deleted
  56. local isnt_for
  57. local arches
  58. local arch
  59. # First check if the pkg is available for
  60. # a specific architecture, if not, check
  61. # if it's for 'any'
  62. local package="${1%%:*}"
  63. local replacement
  64. replacement="$(echo "$1" | cut -d ":" -f2)"
  65. for arch in x86_64 i686 armv7h; do
  66. grep $arch$ "$2" | awk '{print $1}' | grep -xw ^"$package" &> /dev/null || \
  67. grep any$ "$2" | awk '{print $1}' | grep -xw ^"$package" &> /dev/null || \
  68. if [ "$2" = "$arch_pkgs" ]; then
  69. get_libre_pkgs
  70. # Check if the package has a replacement, and
  71. # if such replacement is available for the same
  72. # architectures
  73. if ! [[ $replacement = "" ]]; then
  74. # If this works, it means the pkg doesn't exist for $arch in Arch,
  75. # but we have the [libre] replacement which should be deprecated.
  76. grep $arch$ "$libre_pkgs" | awk '{print $1}' | grep -xw ^"$replacement" &> /dev/null || \
  77. grep any$ "$libre_pkgs" | awk '{print $1}' | grep -xw ^"$replacement" &> /dev/null
  78. case $? in
  79. 0) to_be_removed+=("$arch")
  80. ;;
  81. *) is_not_for+=("$arch")
  82. ;;
  83. esac
  84. else
  85. # However if this fails, it means the pkg doesn't have a replacement
  86. # for $arch, or it simply doesn't have a replacement.
  87. is_not_for+=("$arch")
  88. fi
  89. elif [ "$2" = "$parabola_pkgs" ]; then
  90. if [[ -n $replacement ]]; then
  91. # Look for the replacement
  92. grep $arch$ "$parabola_pkgs" | awk '{print $1}' | grep -xw ^"$replacement" &> /dev/null || \
  93. grep any$ "$parabola_pkgs" | awk '{print $1}' | grep -xw ^"$replacement" &> /dev/null
  94. case $? in
  95. 0) to_be_deleted+=("$arch")
  96. ;;
  97. *) isnt_for+=("$arch")
  98. ;;
  99. esac
  100. else
  101. isnt_for+=("$arch")
  102. fi
  103. fi
  104. done
  105. # Arch
  106. if [[ "${is_not_for[*]}" = "x86_64 i686 armv7h" ]]; then
  107. submsg "$package was not found"
  108. add
  109. elif [[ "${to_be_removed[*]}" = "x86_64 i686 armv7h" ]]; then
  110. submsg "$package was not found, but we've [libre] replacements which should be removed"
  111. add
  112. elif [[ -n "${is_not_for[*]}" ]] || [[ -n "${to_be_removed[*]}" ]]; then
  113. for arch in "${to_be_removed[@]}"; do
  114. # If the replacement is available for the three arch'es supported
  115. # by Parabola, then shut up
  116. for a in x86_64 i686 armv7h; do
  117. grep -xw "^$replacement $a$" "$libre_pkgs" &> /dev/null && arches+=("$a")
  118. done
  119. if ! [[ "${arches[*]}" = "x86_64 i686 armv7h" ]]; then
  120. submsg "$package ($arch) was not found, but we've a [libre] replacement which should be removed"
  121. add
  122. fi
  123. unset arches
  124. done
  125. fi
  126. # Parabola
  127. if [[ "${isnt_for[*]}" = "x86_64 i686 armv7h" ]]; then
  128. submsg "$package was not found"
  129. add
  130. elif [[ -n "${isnt_for[*]}" ]]; then
  131. for arch in "${to_be_deleted[@]}"; do
  132. submsg "$package ($arch) was not found, but we've $replacement as replacement and should be removed"
  133. add
  134. done
  135. fi
  136. }
  137. mkpkglist_from_mirror(){
  138. # $1 is the temporary package list file
  139. local _mirror
  140. local arch
  141. # Clean ${1}.1 just in case...
  142. test -e "${1}.1" && echo > "${1}.1"
  143. for _mirror in "${mirrors[@]}"; do
  144. curl -sLf "$_mirror" >> "${1}.1" || err "Connection failed for $_mirror"
  145. done
  146. # Create the parsed package list
  147. grep '".*.pkg.tar.xz"\|".*.pkg.tar.zst"' "${1}.1" | sed "$sedexp" > "$1"
  148. rm "${1}.1"
  149. # Separate packages by architecture
  150. for arch in $supported_architectures; do
  151. grep "$arch$" "$1" | for f in $(</dev/stdin); do
  152. echo "${f%-*-*-*} $arch" >> "$1-$arch"
  153. done
  154. done
  155. cat "$1"-{x86_64,i686,armv7h,any} | sort -u > "$1"
  156. rm "$1"-{x86_64,i686,armv7h,any}
  157. }
  158. check_packages(){
  159. local pkg_list
  160. local pkgs
  161. # shellcheck disable=SC2068
  162. pkgs="$(grep -hv ^# $@ | awk '{print $1}')"
  163. pkg_list="$(mktemp)"
  164. eval "${distro}_pkgs=$pkg_list" # required for compare_pkgs
  165. msg "Comparing blacklists with ${distro^} packages, this might take a while..."
  166. case $distro in
  167. parabola)
  168. add_parabola_mirrors
  169. mkpkglist_from_mirror "$parabola_pkgs"
  170. ;;
  171. arch)
  172. mkpkglist_from_mirror "$arch_pkgs"
  173. ;;
  174. esac
  175. # Here the magic begins
  176. for p in $pkgs; do
  177. compare_pkgs "$p" "$pkg_list"
  178. done
  179. rm "$pkg_list"
  180. }
  181. main(){
  182. mkmirrorlist
  183. local distro="$1"
  184. case $distro in
  185. parabola)
  186. check_packages "$blacklists_parabola"
  187. ;;
  188. arch)
  189. check_packages "$blacklists"
  190. rm "$libre_pkgs"
  191. ;;
  192. *)
  193. err "$1 is not a valid argument"
  194. ;;
  195. esac
  196. if ! [[ $list -gt 0 ]]; then
  197. submsg 'No packages to show'
  198. fi
  199. msg 'done'
  200. unset list
  201. }
  202. # We'll use this when we check Arch's pkgs only
  203. get_libre_pkgs(){
  204. local mirrors
  205. if ! [[ -e $libre_pkgs ]]; then
  206. libre_pkgs=$(mktemp)
  207. for r in $repos_libre; do
  208. mirrors+=("$mirror_parabola/$r/os/x86_64/")
  209. mirrors+=("$mirror_parabola/$r/os/i686/")
  210. mirrors+=("$mirror_parabola/$r/os/armv7h/")
  211. done
  212. mkpkglist_from_mirror "$libre_pkgs"
  213. fi
  214. }
  215. # Parabola mirrors, used to check [libre] and [pcr] packages
  216. add_parabola_mirrors(){
  217. for r in $repos_parabola; do
  218. mirrors+=("$mirror_parabola/$r/os/x86_64/")
  219. mirrors+=("$mirror_parabola/$r/os/i686/")
  220. mirrors+=("$mirror_parabola/$r/os/armv7h/")
  221. done
  222. }
  223. # Create mirrors lists
  224. mkmirrorlist(){
  225. unset mirrors
  226. for r in $repos_x86_64; do
  227. mirrors+=("$mirror_x86_64/$r/os/x86_64/")
  228. done
  229. for r in $repos_i686; do
  230. mirrors+=("$mirror_i686/i686/$r/")
  231. done
  232. for r in $repos_armv7h; do
  233. mirrors+=("$mirror_armv7h/armv7h/$r/")
  234. done
  235. }
  236. conf="$(dirname "$(readlink -f "$0")")/find-deprecated.conf"
  237. if test -e "$conf"; then
  238. # shellcheck disable=SC1090
  239. . "$conf"
  240. else
  241. usage
  242. err "Configuration file not found: $conf"
  243. fi
  244. if [ "$#" -eq 0 ]; then
  245. usage
  246. else
  247. for arg in "$@"; do
  248. main "$arg"
  249. done
  250. fi