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