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 declare -r myname
='pacscripts'
28 declare -r myver
='@PACKAGE_VERSION@'
30 conf
="@sysconfdir@/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:-@localstatedir@/lib/pacman}/local"
40 pac_cache
="${CacheDir:-@localstatedir@/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: $myname pkgname|pkgfile"
53 echo " -h, --help Print this help message"
54 echo " -v, --version Print program name and version"
56 echo "Example: $myname gconf-editor"
57 echo "Example: $myname gconf-editor-2.24.1-1-x86_64.pkg.tar.gz"
61 printf "%s %s\n" "$myname" "$myver"
62 echo 'Copyright (c) 2009 Giulio "giulivo" Fidente <giulivo.navigante@gmail.com>'
63 echo 'Copyright (c) 2009 Xavier Chantry <shiningxc@gmail.com>'
67 if [ $EUID -eq 0 ]; then
70 if ! type -p sudo
; then
71 error
"Cannot find the sudo binary! Is sudo installed?"
72 error
"Otherwise try to run the program as root"
83 if [ -f $pac_db/$pkg*/install ]; then
84 cat $pac_db/$pkg*/install
88 error
"Package $1 does not include any .INSTALL script"
94 if ! bsdtar
-xOf "$1" .INSTALL
2>/dev
/null
; then
95 error
"Package $1 does not include any .INSTALL script"
103 if bsdtar tf
"$1" .PKGINFO
&>/dev
/null
; then
108 if pacman
-Q "$1" &>/dev
/null
; then
112 if ! pacman
-Si $1 &>/dev
/null
; then
113 error
"Package $1 not found"
116 url
=$
(spacman
-Sdp $1 |
tail -n1)
117 filename
=$
(basename $url)
118 if [ ! -f "$pac_cache/$filename" ]; then
119 if ! spacman
-Sdw --noconfirm $1 >&2; then
120 error
"Failed to download $1"
125 print_pkg
"$pac_cache/$filename"
129 if [ $# -ne 1 ] ; then
135 --help|
-h) usage
; exit 0 ;;
136 --version|
-V) version
; exit 0 ;;
137 *) print_scriptlet
$1 ;;