detect-old-perl-modules.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. basedir=/usr/lib/perl5
  3. perlver=$(perl -e '$v = $^V->{version}; print $v->[0].".".($v->[1]);')
  4. dir_empty() {
  5. local dir=$1
  6. [[ $(find $dir -maxdepth 0 -empty -exec echo empty \;) = "empty" ]] && return 0 || return 1
  7. }
  8. print_unowned_files() {
  9. local dir=$1
  10. LC_ALL=C find "$dir" -type f -exec pacman -Qqo {} + |& sed -n 's/^error: No package owns \(.*\)$/\1/p'
  11. }
  12. for dir in "$basedir/"*; do
  13. if [[ "${dir##*/}" != "$perlver" ]]; then
  14. if [[ -d "$dir" ]] && ! dir_empty "$dir"; then
  15. pkgcount=$(pacman -Qqo "$dir" | wc -l)
  16. if ((pkgcount > 0)); then
  17. printf "WARNING: '%s' contains data from at least %d packages which will NOT be used by the installed perl interpreter.\n" "$dir" "$pkgcount"
  18. printf " -> Run the following command to get a list of affected packages: pacman -Qqo '%s'\n" "$dir"
  19. fi
  20. unowned_count=$(print_unowned_files "$dir" | wc -l)
  21. if ((unowned_count > 0)); then
  22. printf "WARNING: %d file(s) in %s are not tracked by pacman and need to be rebuilt.\n" "$unowned_count" "$dir"
  23. printf " -> These were most likely installed directly by cpan or a similar tool.\n"
  24. printf " Run the following command to get a list of these files:\n"
  25. printf " LC_ALL=C find \"%s\" -type f -exec pacman -Qqo {} + |& sed -n 's/^error: No package owns \(.*\)$/\\\1/p'\n" "$dir"
  26. fi
  27. fi
  28. fi
  29. done