2023-11-13 09:33:28 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
2024-07-06 16:25:54 -04:00
|
|
|
## SPDX-FileCopyrightText: 2013 - 2018 Will Thames will@thames.id.au
|
2023-11-13 09:33:28 -05:00
|
|
|
## SPDX-FileCopyrightText: 2018 Ansible by Red Hat
|
|
|
|
## SPDX-FileCopyrightText: 2020 - 2023 Warpnet B.V.
|
2024-07-08 05:41:45 -04:00
|
|
|
## SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
2023-11-13 09:33:28 -05:00
|
|
|
##
|
|
|
|
## SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
## Credits: https://salt-lint.readthedocs.io/en/latest/#fix-common-issues
|
|
|
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
set -eu
|
|
|
|
|
2024-08-06 12:15:24 -04:00
|
|
|
command -v git >/dev/null ||
|
|
|
|
{ printf '%s\n' "Missing program: git" >&2; exit 1; }
|
2024-07-10 08:36:05 -04:00
|
|
|
repo_toplevel="$(git rev-parse --show-toplevel)"
|
|
|
|
test -d "${repo_toplevel}" || exit 1
|
2024-07-19 09:29:17 -04:00
|
|
|
cd "${repo_toplevel}"
|
2024-07-10 08:36:05 -04:00
|
|
|
unset repo_toplevel
|
2023-11-13 09:33:28 -05:00
|
|
|
|
2024-07-06 16:25:54 -04:00
|
|
|
find_tool="$(./scripts/best-program.sh fd fdfind find)"
|
2023-11-13 09:33:28 -05:00
|
|
|
|
|
|
|
case "${find_tool}" in
|
2024-07-09 11:42:07 -04:00
|
|
|
fd|fdfind)
|
2024-07-10 08:36:05 -04:00
|
|
|
conf_files="$(${find_tool} . minion.d/ -e conf)"
|
|
|
|
sls_files="$(${find_tool} . salt/ -d 2 -t f -e sls)"
|
2024-08-06 11:04:16 -04:00
|
|
|
set -- ${conf_files} ${sls_files}
|
2024-07-09 11:42:07 -04:00
|
|
|
;;
|
|
|
|
find)
|
2024-07-10 08:36:05 -04:00
|
|
|
conf_files="$(find minion.d/ -type f -name "*.conf")"
|
|
|
|
sls_files="$(find salt/ -maxdepth 2 -type f -name '*.sls')"
|
2024-08-06 11:04:16 -04:00
|
|
|
set -- ${conf_files} ${sls_files}
|
2024-07-09 11:42:07 -04:00
|
|
|
;;
|
2024-08-06 12:15:24 -04:00
|
|
|
*) printf '%s\n' "Unsupported find tool" >&2; exit 1;;
|
2023-11-13 09:33:28 -05:00
|
|
|
esac
|
|
|
|
|
|
|
|
## 201 - Fix trailing whitespace:
|
2024-08-06 11:04:16 -04:00
|
|
|
sed -i'' -e 's/[[:space:]]*$//' -- "${@}"
|
2023-11-13 09:33:28 -05:00
|
|
|
|
|
|
|
## 206 - Fix spacing around {{ var_name }}, eg. {{env}} --> {{ env }}:
|
2024-08-06 11:04:16 -04:00
|
|
|
sed -i'' -E -e "s/\{\{\s?([^}]*[^} ])\s?\}\}/\{\{ \1 \}\}/g" -- "${@}"
|
2023-11-13 09:33:28 -05:00
|
|
|
|
|
|
|
## 207 - Add quotes around numeric values that start with a 0:
|
2024-08-06 11:04:16 -04:00
|
|
|
sed -i'' -E -e "s/\b(minute|hour): (0[0-7]?)\$/\1: '\2'/" -- "${@}"
|
2023-11-13 09:33:28 -05:00
|
|
|
|
|
|
|
## 208 - Make dir_mode, file_mode and mode arguments in the desired syntax:
|
2024-08-06 11:04:16 -04:00
|
|
|
sed -i'' -E -e "s/\b(dir_|file_|)mode: 0?([0-7]{3})/\1mode: '0\2'/" -- "${@}"
|