diff options
author | Eli Schwartz <eschwartz93@gmail.com> | 2023-12-13 00:01:39 -0500 |
---|---|---|
committer | Ilmari Lauhakangas <ilmari.lauhakangas@libreoffice.org> | 2024-01-22 14:11:47 +0100 |
commit | cf02724e5101801d0a316f6b099c14c4fce77d9a (patch) | |
tree | fff9ab25680633928fcd811897fa793166412719 /sysui | |
parent | 12ea98fe637eda5f038b6447a5f0c5ea7104f448 (diff) |
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>
Diffstat (limited to 'sysui')
-rwxr-xr-x | sysui/desktop/debian/postinst | 2 | ||||
-rwxr-xr-x | sysui/desktop/debian/postrm | 2 | ||||
-rw-r--r-- | sysui/desktop/freedesktop/freedesktop-menus.spec | 18 |
3 files changed, 11 insertions, 11 deletions
diff --git a/sysui/desktop/debian/postinst b/sysui/desktop/debian/postinst index f3220f311fdf..e07ad7fa0649 100755 --- a/sysui/desktop/debian/postinst +++ b/sysui/desktop/debian/postinst @@ -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) diff --git a/sysui/desktop/debian/postrm b/sysui/desktop/debian/postrm index 0e6099ea5b43..2e53e6062352 100755 --- a/sysui/desktop/debian/postrm +++ b/sysui/desktop/debian/postrm @@ -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) diff --git a/sysui/desktop/freedesktop/freedesktop-menus.spec b/sysui/desktop/freedesktop/freedesktop-menus.spec index 203d1a881bd3..ff083d71fe9c 100644 --- a/sysui/desktop/freedesktop/freedesktop-menus.spec +++ b/sysui/desktop/freedesktop/freedesktop-menus.spec @@ -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) |