3 # pacscripts : tries to print out the {pre,post}_{install,remove,upgrade}
4 # scripts of a given package
6 # Copyright (c) 2009 Giulio "giulivo" Fidente <giulivo.navigante@gmail.com>
7 # Copyright (c) 2009 Xavier Chantry <shiningxc@gmail.com>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 progname
=$
(basename $0)
30 conf
="/etc/pacman.conf"
32 if [ ! -r "$conf" ]; then
33 echo "ERROR: unable to read $conf"
37 eval $
(awk '/DBPath/ {print $1$2$3}' "$conf")
38 eval $
(awk '/CacheDir/ {print $1$2$3}' "$conf")
39 pac_db
="${DBPath:-/var/lib/pacman}/local"
40 pac_cache
="${CacheDir:-/var/cache/pacman/pkg}"
44 printf "==> $(gettext "ERROR
:") ${mesg}\n" "$@" >&2
48 echo "This program prints out the {pre,post}_{install,remove,upgrade} scripts"
49 echo "of a given package."
50 echo "Usage: $progname pkgname|pkgfile"
53 echo " -h, --help Print this help message"
54 echo " -v, --version Print program name and version"
56 echo "Example: $progname gconf-editor"
57 echo "Example: $progname gconf-editor-2.24.1-1-x86_64.pkg.tar.gz"
61 if [ $EUID -eq 0 ]; then
64 if [ ! "$(type -p sudo)" ]; then
65 error
"Cannot find the sudo binary! Is sudo installed?"
66 error
"Otherwise try to run the program as root"
77 if [ -f $pac_db/$pkg*/install ]; then
78 cat $pac_db/$pkg*/install
82 error
"Package $1 does not include any .INSTALL script"
88 if ! bsdtar
-xOf "$1" .INSTALL
2>/dev
/null
; then
89 error
"Package $1 does not include any .INSTALL script"
97 if bsdtar tf
"$1" .PKGINFO
&>/dev
/null
; then
102 if pacman
-Q "$1" &>/dev
/null
; then
106 if ! pacman
-Si $1 &>/dev
/null
; then
107 error
"Package $1 not found"
110 url
=$
(spacman
-Sdp $1 |
tail -n1)
111 filename
=$
(basename $url)
112 if [ ! -f "$pac_cache/$filename" ]; then
113 if ! spacman
-Sdw --noconfirm $1 >&2; then
114 error
"Failed to download $1"
119 print_pkg
"$pac_cache/$filename"
123 if [ $# -ne 1 ] ; then
129 --help|
-h) usage
; exit 0 ;;
130 --version|
-v) echo "$progname version $progver"; exit 0 ;;
131 *) print_scriptlet
$1 ;;