#!/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 . # progname=$(basename $0) progver="0.4" conf="/etc/pacman.conf" if [ ! -r "$conf" ]; then echo "ERROR: unable to read $conf" exit 1 fi eval $(awk '/DBPath/ {print $1$2$3}' "$conf") eval $(awk '/CacheDir/ {print $1$2$3}' "$conf") 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: $progname pkgname" echo echo " OPTIONS:" echo " -h, --help Print this help message" echo " -v, --version Print program name and version" echo echo "Example: $progname gconf-editor" } print_scriptlet() { if pacman -Q "$1" &>/dev/null; then pkg=$(pacman -Q "$1") pkg=${pkg/ /-} if [ -f $pac_db/$pkg*/install ]; then cat $pac_db/$pkg*/install echo return 0 else echo "Package $1 does not include any .INSTALL script" return 1 fi fi if ! pacman -Si $1 &>/dev/null; then echo "Package $1 not found" return 1 fi if ! sudo pacman -Sdw --noconfirm $1 > /dev/null; then echo "Failed to download $1" return 1 fi url=$(sudo pacman -Sdp $1 || tail -n1) filename=$(basename $url) if ! tar -xOf $pac_cache/$filename .INSTALL 2> /dev/null; then echo "Package $1 does not include any .INSTALL script" return 1 fi echo return 0 } if [ $# -ne 1 ] ; then usage exit 1 fi case "$1" in --help|-h) usage; exit 0 ;; --version|-v) echo "$progname version $progver"; exit 0 ;; *) print_scriptlet $1 ;; esac