#!/bin/bash # pacscripts : tries to print out the {pre,post}_{install,remove,upgrade} scripts of a given package # # Copyright (c) 2009 Giulio "giulivo" Fidente # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # prog_ver="0.2" if [ ! -r /etc/pacman.conf ]; then echo "ERROR: unable to read /etc/pacman.conf" exit 1 else eval $(awk '/DBPath/ {print $1$2$3}' /etc/pacman.conf) eval $(awk '/CacheDir/ {print $1$2$3}' /etc/pacman.conf) fi pac_db="${DBPath:-/var/lib/pacman}/local" pac_cache="${CacheDir:-/var/cache/pacman/pkg}" usage() { echo "This program prints out the {pre,post}_{install,remove,upgrade} scripts" echo "of a given package, even if it's not installed yet, without installing it!" echo "Usage: `basename $0` package..." echo echo " OPTIONS:" echo " -h, --help Print this help message" echo " -v, --version Print program name and version" echo echo "Example: `basename $0` gconf-editor" } print_scriptlet() { (cat $pac_db/$1-*/install 2> /dev/null) || (pacman -Sw --nodeps --noconfirm $1 > /dev/null && (tar -xOf $pac_cache/$1*.pkg.tar.gz .INSTALL 2> /dev/null || echo "Package did not include any .INSTALL script")) } if [ $# -ne 1 ] ; then usage exit 1 fi if [ "$1" = "--help" -o "$1" = "-h" ] ; then usage exit 0 elif [ "$1" = "--version" -o "$1" = "-v" ] ; then echo "`basename $0` version $prog_ver" exit 0 else print_scriptlet $1 fi