2011-06-30 11:07:54 -04:00
|
|
|
#!/bin/bash
|
2009-03-02 13:13:08 -05:00
|
|
|
#
|
|
|
|
# pacscripts : tries to print out the {pre,post}_{install,remove,upgrade}
|
|
|
|
# scripts of a given package
|
|
|
|
#
|
|
|
|
# Copyright (c) 2009 Giulio "giulivo" Fidente <giulivo.navigante@gmail.com>
|
|
|
|
# Copyright (c) 2009 Xavier Chantry <shiningxc@gmail.com>
|
2016-01-02 22:48:43 -05:00
|
|
|
# Copyright (c) 2009-2016 Pacman Development Team <pacman-dev@archlinux.org>
|
2009-03-02 13:13:08 -05:00
|
|
|
#
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
# bash options
|
|
|
|
set -o nounset
|
|
|
|
set -o errexit
|
|
|
|
|
2011-12-06 16:29:32 -05:00
|
|
|
declare -r myname='pacscripts'
|
2011-12-12 16:36:57 -05:00
|
|
|
declare -r myver='@PACKAGE_VERSION@'
|
2009-03-02 13:13:08 -05:00
|
|
|
|
2010-10-11 19:23:16 -04:00
|
|
|
conf="@sysconfdir@/pacman.conf"
|
2009-03-02 13:13:08 -05:00
|
|
|
|
|
|
|
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")
|
2010-10-11 19:23:16 -04:00
|
|
|
pac_db="${DBPath:-@localstatedir@/lib/pacman}/local"
|
|
|
|
pac_cache="${CacheDir:-@localstatedir@/cache/pacman/pkg}"
|
2009-03-02 13:13:08 -05:00
|
|
|
|
|
|
|
error() {
|
|
|
|
local mesg=$1; shift
|
|
|
|
printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
2013-11-08 02:53:33 -05:00
|
|
|
echo "${myname} (pacman) v${myver}"
|
2009-03-02 13:13:08 -05:00
|
|
|
echo
|
2013-11-08 02:53:33 -05:00
|
|
|
echo "Prints the {pre,post}_{install,remove,upgrade} scripts of a given package."
|
|
|
|
echo
|
|
|
|
echo "Usage: ${myname} <pkgname|pkgfile>"
|
|
|
|
echo
|
|
|
|
echo " Options:"
|
2009-03-02 13:13:08 -05:00
|
|
|
echo " -h, --help Print this help message"
|
|
|
|
echo " -v, --version Print program name and version"
|
|
|
|
echo
|
2013-11-08 02:53:33 -05:00
|
|
|
echo "Example: ${myname} gconf-editor"
|
|
|
|
echo "Example: ${myname} gconf-editor-3.0.1-3-x86_64.pkg.tar.xz"
|
2009-03-02 13:13:08 -05:00
|
|
|
}
|
|
|
|
|
2011-12-12 16:36:57 -05:00
|
|
|
version() {
|
|
|
|
printf "%s %s\n" "$myname" "$myver"
|
|
|
|
echo 'Copyright (c) 2009 Giulio "giulivo" Fidente <giulivo.navigante@gmail.com>'
|
|
|
|
echo 'Copyright (c) 2009 Xavier Chantry <shiningxc@gmail.com>'
|
|
|
|
}
|
|
|
|
|
2009-03-02 13:13:08 -05:00
|
|
|
spacman() {
|
|
|
|
if [ $EUID -eq 0 ]; then
|
|
|
|
pacman "$@"
|
|
|
|
else
|
2011-03-24 10:10:05 -04:00
|
|
|
if ! type -p sudo; then
|
2013-11-15 23:56:05 -05:00
|
|
|
error "Cannot find the sudo binary!"
|
|
|
|
error "${myname} requires root privileges. Either install \"sudo\" or run as root."
|
2009-03-02 13:13:08 -05:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
sudo pacman "$@"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
print_db() {
|
|
|
|
pkg=$(pacman -Q "$1")
|
|
|
|
pkg=${pkg/ /-}
|
|
|
|
if [ -f $pac_db/$pkg*/install ]; then
|
|
|
|
cat $pac_db/$pkg*/install
|
|
|
|
echo
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
error "Package $1 does not include any .INSTALL script"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
print_pkg() {
|
2013-06-17 17:48:38 -04:00
|
|
|
if ! bsdtar -xqOf "$1" .INSTALL 2>/dev/null; then
|
2009-03-02 13:13:08 -05:00
|
|
|
error "Package $1 does not include any .INSTALL script"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
print_scriptlet() {
|
|
|
|
if [ -f "$1" ]; then
|
|
|
|
if bsdtar tf "$1" .PKGINFO &>/dev/null; then
|
|
|
|
print_pkg "$1"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if pacman -Q "$1" &>/dev/null; then
|
|
|
|
print_db "$1"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
if ! pacman -Si $1 &>/dev/null; then
|
|
|
|
error "Package $1 not found"
|
|
|
|
return 1
|
|
|
|
fi
|
2013-06-17 17:48:39 -04:00
|
|
|
url=$(pacman -Sddp $1)
|
2009-03-02 13:13:08 -05:00
|
|
|
filename=$(basename $url)
|
|
|
|
if [ ! -f "$pac_cache/$filename" ]; then
|
2013-06-17 17:48:39 -04:00
|
|
|
if ! spacman -Sddw --noconfirm $1 >&2; then
|
2009-03-02 13:13:08 -05:00
|
|
|
error "Failed to download $1"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
echo >&2
|
|
|
|
fi
|
|
|
|
print_pkg "$pac_cache/$filename"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -ne 1 ] ; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
--help|-h) usage; exit 0 ;;
|
2011-12-12 16:36:57 -05:00
|
|
|
--version|-V) version; exit 0 ;;
|
2009-03-02 13:13:08 -05:00
|
|
|
*) print_scriptlet $1 ;;
|
|
|
|
esac
|