use portable "command -v" to detect installed programs, part 3
The "which" utility is not guaranteed to be installed either, and if it is, its behavior is not portable either. This means that when various programs are installed, the `which` check will report a fatal error because the which tool did not exist and the shell returned a nonzero status when attempting to fork+exec. If it did exist, it might not be an implementation of `which` that returns nonzero when commands do not exist. The general scripting suggestion is to use the "command -v" shell builtin; this is required to exist in all POSIX 2008 compliant shells, and is thus guaranteed to work everywhere. For some in-depth discussions on the topic, see: - https://mywiki.wooledge.org/BashFAQ/081 - https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then/85250#85250 Examples of open-source shells likely to be installed as /bin/sh on Linux, which implement the 15-year-old standard: ash, bash, busybox, dash, ksh, mksh and zsh. This commit updates packaging recipes. Change-Id: I934863f6c8e05728e85278568899f581d749e0ea Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160664 Tested-by: Ilmari Lauhakangas <ilmari.lauhakangas@libreoffice.org> Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakangas@libreoffice.org>
This commit is contained in:
committed by
Ilmari Lauhakangas
parent
12ea98fe63
commit
cf02724e51
@@ -34,7 +34,7 @@ if [ "$1" = "configure" ] ; then # first install
|
||||
if [ -e /usr/share/icons/hicolor/icon-theme.cache ] ; then
|
||||
# touch it, just in case we cannot find the binary...
|
||||
touch /usr/share/icons/hicolor
|
||||
if (which gtk-update-icon-cache); then
|
||||
if command -v gtk-update-icon-cache; then
|
||||
gtk-update-icon-cache /usr/share/icons/hicolor
|
||||
fi
|
||||
# ignore errors (e.g. when there is a cache, but no index.theme)
|
||||
|
@@ -14,7 +14,7 @@ if [ "$1" != "purge" ]; then
|
||||
if [ -e /usr/share/icons/hicolor/icon-theme.cache ] ; then
|
||||
# touch it, just in case we cannot find the binary...
|
||||
touch /usr/share/icons/hicolor
|
||||
if (which gtk-update-icon-cache); then
|
||||
if command -v gtk-update-icon-cache; then
|
||||
gtk-update-icon-cache /usr/share/icons/hicolor
|
||||
fi
|
||||
# ignore errors (e.g. when there is a cache, but no index.theme)
|
||||
|
@@ -86,7 +86,7 @@ rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
if [ -x /opt/gnome/bin/update-desktop-database ]; then
|
||||
/opt/gnome/bin/update-desktop-database -q
|
||||
elif (which update-desktop-database); then
|
||||
elif command -v update-desktop-database; then
|
||||
update-desktop-database -q /usr/share/applications
|
||||
fi
|
||||
|
||||
@@ -99,7 +99,7 @@ if [ "$2" = "0" ] ; then
|
||||
# the triggering package gets removed
|
||||
if [ -x /opt/gnome/bin/update-desktop-database ]; then
|
||||
/opt/gnome/bin/update-desktop-database -q
|
||||
elif (which update-desktop-database); then
|
||||
elif command -v update-desktop-database; then
|
||||
update-desktop-database -q /usr/share/applications
|
||||
fi
|
||||
fi
|
||||
@@ -111,11 +111,11 @@ fi
|
||||
if [ "$1" = "1" ] ; then # first install
|
||||
if [ -x /opt/gnome/bin/update-desktop-database ]; then
|
||||
/opt/gnome/bin/update-desktop-database -q
|
||||
elif (which update-desktop-database); then
|
||||
elif command -v update-desktop-database; then
|
||||
update-desktop-database -q /usr/share/applications
|
||||
fi
|
||||
|
||||
if (which update-mime-database); then
|
||||
if command -v update-mime-database; then
|
||||
update-mime-database /usr/share/mime
|
||||
fi
|
||||
fi
|
||||
@@ -165,7 +165,7 @@ if [ -e /usr/share/icons/hicolor/icon-theme.cache ] ; then
|
||||
touch /usr/share/icons/hicolor
|
||||
if [ -x /opt/gnome/bin/gtk-update-icon-cache ]; then
|
||||
/opt/gnome/bin/gtk-update-icon-cache -q /usr/share/icons/hicolor
|
||||
elif (which gtk-update-icon-cache); then
|
||||
elif command -v gtk-update-icon-cache; then
|
||||
gtk-update-icon-cache -q /usr/share/icons/hicolor
|
||||
fi
|
||||
# ignore errors (e.g. when there is a cache, but no index.theme)
|
||||
@@ -329,7 +329,7 @@ fi
|
||||
|
||||
if [ -x /opt/gnome/bin/update-desktop-database ]; then
|
||||
/opt/gnome/bin/update-desktop-database -q
|
||||
elif (which update-desktop-database); then
|
||||
elif command -v update-desktop-database; then
|
||||
update-desktop-database -q /usr/share/applications
|
||||
fi
|
||||
|
||||
@@ -348,11 +348,11 @@ fi
|
||||
if [ "$1" = 0 ] ; then # only run when erasing the package - other cases handled by the triggers
|
||||
if [ -x /opt/gnome/bin/update-desktop-database ]; then
|
||||
/opt/gnome/bin/update-desktop-database -q
|
||||
elif (which update-desktop-database); then
|
||||
elif command -v update-desktop-database; then
|
||||
update-desktop-database -q
|
||||
fi
|
||||
# run always - both when upgrading as well as when erasing the package
|
||||
if (which update-mime-database); then
|
||||
if command -v update-mime-database; then
|
||||
update-mime-database /usr/share/mime
|
||||
fi
|
||||
fi
|
||||
@@ -363,7 +363,7 @@ if [ -e /usr/share/icons/hicolor/icon-theme.cache ] ; then
|
||||
touch /usr/share/icons/hicolor
|
||||
if [ -x /opt/gnome/bin/gtk-update-icon-cache ]; then
|
||||
/opt/gnome/bin/gtk-update-icon-cache -q /usr/share/icons/hicolor
|
||||
elif (which gtk-update-icon-cache); then
|
||||
elif command -v gtk-update-icon-cache; then
|
||||
gtk-update-icon-cache -q /usr/share/icons/hicolor
|
||||
fi
|
||||
# ignore errors (e.g. when there is a cache, but no index.theme)
|
||||
|
Reference in New Issue
Block a user