Archlinux basic installation configuration scripts
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.

117 lines
3.0 KiB

  1. #!/usr/bin/bash
  2. #
  3. # checkupdates: Safely print a list of pending updates.
  4. #
  5. # Copyright (c) 2013 Kyle Keen <keenerd@gmail.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. #
  20. declare -r myname='checkupdates'
  21. declare -r myver='1.0.0'
  22. plain() {
  23. (( QUIET )) && return
  24. local mesg=$1; shift
  25. printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1
  26. }
  27. msg() {
  28. (( QUIET )) && return
  29. local mesg=$1; shift
  30. printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1
  31. }
  32. msg2() {
  33. (( QUIET )) && return
  34. local mesg=$1; shift
  35. printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1
  36. }
  37. ask() {
  38. local mesg=$1; shift
  39. printf "${BLUE}::${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}" "$@" >&1
  40. }
  41. warning() {
  42. local mesg=$1; shift
  43. printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
  44. }
  45. error() {
  46. local mesg=$1; shift
  47. printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
  48. }
  49. # check if messages are to be printed using color
  50. unset ALL_OFF BOLD BLUE GREEN RED YELLOW
  51. if [[ -t 2 && ! $USE_COLOR = "n" ]]; then
  52. # prefer terminal safe colored and bold text when tput is supported
  53. if tput setaf 0 &>/dev/null; then
  54. ALL_OFF="$(tput sgr0)"
  55. BOLD="$(tput bold)"
  56. BLUE="${BOLD}$(tput setaf 4)"
  57. GREEN="${BOLD}$(tput setaf 2)"
  58. RED="${BOLD}$(tput setaf 1)"
  59. YELLOW="${BOLD}$(tput setaf 3)"
  60. else
  61. ALL_OFF="\e[1;0m"
  62. BOLD="\e[1;1m"
  63. BLUE="${BOLD}\e[1;34m"
  64. GREEN="${BOLD}\e[1;32m"
  65. RED="${BOLD}\e[1;31m"
  66. YELLOW="${BOLD}\e[1;33m"
  67. fi
  68. fi
  69. readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
  70. if (( $# > 0 )); then
  71. echo "${myname} v${myver}"
  72. echo
  73. echo "Safely print a list of pending updates"
  74. echo
  75. echo "Usage: ${myname}"
  76. echo
  77. echo 'Note: Export the "CHECKUPDATES_DB" variable to change the path of the temporary database.'
  78. exit 0
  79. fi
  80. if ! type -P fakeroot >/dev/null; then
  81. error 'Cannot find the fakeroot binary.'
  82. exit 1
  83. fi
  84. if [[ -z $CHECKUPDATES_DB ]]; then
  85. CHECKUPDATES_DB="${TMPDIR:-/tmp}/checkup-db-${USER}/"
  86. fi
  87. trap 'rm -f $CHECKUPDATES_DB/db.lck' INT TERM EXIT
  88. DBPath="$(pacman-conf DBPath)"
  89. if [[ -z "$DBPath" ]] || [[ ! -d "$DBPath" ]]; then
  90. DBPath="/var/lib/pacman/"
  91. fi
  92. mkdir -p "$CHECKUPDATES_DB"
  93. ln -s "${DBPath}/local" "$CHECKUPDATES_DB" &> /dev/null
  94. if ! fakeroot -- pacman -Sy --dbpath "$CHECKUPDATES_DB" --logfile /dev/null &> /dev/null; then
  95. error 'Cannot fetch updates'
  96. exit 1
  97. fi
  98. pacman -Qu --dbpath "$CHECKUPDATES_DB" 2> /dev/null | grep -v '\[.*\]'
  99. exit 0
  100. # vim: set noet: