office-gobmx/bin/removetooltip_markups.sh
Eli Schwartz 2a5ff80264 use portable "command -v" to detect installed programs, part 4
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 a couple build scripts to not rely on fixed paths
calculated upfront. Checking the location of a tool with cmd=$(which
foo) just to run it as `$cmd` is pointless. It's exactly equivalent to
run it as `foo`, but less error-prone and easier to read.

For one of the scripts, it also simplifies checking for their existence.
Personally, I am skeptical it even makes sense to check at all. POSIX
mandates they exist, and it's exceedingly unlikely they will not be
installed. However, unlike the shell interpreter itself, we don't *know*
they are installed, so leave the existing checks in but simplified.

Change-Id: I4703c1165eb3a5aeb45fbab18df3222e8f5f9551
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160665
Tested-by: Jenkins
Tested-by: Ilmari Lauhakangas <ilmari.lauhakangas@libreoffice.org>
Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakangas@libreoffice.org>
2024-01-22 14:12:18 +01:00

53 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Run the script in the core directory to remove all tooltip_markup
# properties from the .ui files
LOG_FILE="modified-$(date +%s).log"
removeTooltipMarkup()
{
LINE=$(grep -n "<property name=\"tooltip_markup\"" $1 | cut -f 1 -d ':')
TEXT=$(grep "<property name=\"tooltip_markup\"" $1)
grep -v "<property name=\"tooltip_markup\"" $1 > temp && mv temp $1
echo "removed $TEXT from $1 at line $LINE" >> $LOG_FILE
}
changeTooltipMarkup()
{
LINE=$(grep -n "<property name=\"tooltip_markup\"" $1 | cut -f 1 -d ':')
sed "s/tooltip_markup/tooltip_text/g" $i > temp && mv temp $1
echo "renamed tooltip_markup from $1 at line $LINE" >> $LOG_FILE
}
checkTooltipMarkup()
{
TEXT=`grep "<property name=\"tooltip_text\"" $1`
MARKUP=`grep "<property name=\"tooltip_markup\"" $1`
if [[ $MARKUP ]] && [[ $TEXT ]]
then
removeTooltipMarkup "$1"
fi
if [[ $MARKUP ]] && [[ ! $TEXT ]]
then
changeTooltipMarkup "$1"
fi
}
shopt -s globstar
echo " " > $LOG_FILE
for i in **/*.ui; do
echo -n "."
checkTooltipMarkup "$i"
done
echo
echo "Done!"