Useful CLI tools (bash) for Arch Linux administration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.0 KiB

  1. #!/bin/env bash
  2. #
  3. # pacmankeycheck - Check age of Pacman PGP/GPG public key ring files and update if wanted
  4. #
  5. # Copyright (C) 2021 Pekka Helenius <pekka.helenius@fjordtek.com>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. LIBRARY=${LIBRARY:-'/usr/share/makepkg'}
  20. source "$LIBRARY/util/message.sh"
  21. source "$LIBRARY/util/pkgbuild.sh"
  22. colorize
  23. function keyringcheck() {
  24. keyfilepath="/etc/pacman.d/gnupg"
  25. keyfiles=(
  26. 'pubring.gpg'
  27. # 'secring.gpg'
  28. 'trustdb.gpg'
  29. )
  30. # Deadline in days
  31. deadline=30
  32. expiredkeys=0
  33. deadlineseconds=$(($deadline * 24 * 60 * 60))
  34. for i in ${keyfiles[@]}; do
  35. file="${keyfilepath}/${i}"
  36. age=$(( $(date "+%s") - $(stat -c %Z "${file}") ))
  37. lastupdated=$(date --date=@$(stat -c %Z "${file}"))
  38. if [[ $age -gt $deadlineseconds ]]; then
  39. expiredkeys=1
  40. warning "$(gettext "Pacman PGP/GPG public key ring file %s is over %s days old. Last updated: %s")" "${i}" "${deadline}" "${lastupdated}"
  41. fi
  42. done
  43. if [[ $expiredkeys -eq 1 ]]; then
  44. msg "$(gettext "Outdated pacman public key ring files may cause issues on package installations.")"
  45. msg "$(gettext "Do you wish to update the pacman key ring files before proceeding with the pacman command? [Y/n]")"
  46. read response
  47. if [[ $(echo $response) =~ ^([yY][eE][sS]|[yY])$ ]]; then
  48. su root -c 'pacman-key --populate archlinux; pacman-key --refresh'
  49. fi
  50. fi
  51. }