Skip to content

Commit

Permalink
Use enhanced Bash-style conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Aug 7, 2024
1 parent c6fe556 commit 1f77105
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions bin/check-file-permissions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/usr/bin/env bash
set -eu

FILES_WITH_WRONG_PERMISSIONS=$(
Expand All @@ -12,28 +12,28 @@ BIN_FILES_WITH_WRONG_PERMISSIONS=$(
| sort -fh
)

if [ -n "$FILES_WITH_WRONG_PERMISSIONS" ]; then
printf '\033[31mFAIL\033[0m Non-executable files with +x permissions were detected!\n'
[ -z "${GITHUB_ACTIONS+x}" ] || echo '::group::Non-executable files'
if [[ -n "$FILES_WITH_WRONG_PERMISSIONS" ]]; then
printf '\033[41m FAIL \033[0m Non-executable files with +x permissions were detected!\n'
[[ -z "${GITHUB_ACTIONS+x}" ]] || echo '::group::Non-executable files'
echo "$FILES_WITH_WRONG_PERMISSIONS"
echo ''
echo "$FILES_WITH_WRONG_PERMISSIONS" | awk '{print $4}' | xargs -n1 printf 'Please run "\033[32msudo chmod\033[0m -x %s".\n'
[ -z "${GITHUB_ACTIONS+x}" ] || echo '::endgroup::'
[[ -z "${GITHUB_ACTIONS+x}" ]] || echo '::endgroup::'
fi

if [ -n "$BIN_FILES_WITH_WRONG_PERMISSIONS" ]; then
printf '\033[31mFAIL\033[0m Executable files with -x permissions were detected!\n'
[ -z "${GITHUB_ACTIONS+x}" ] || echo '::group::Executable files'
if [[ -n "$BIN_FILES_WITH_WRONG_PERMISSIONS" ]]; then
printf '\033[41m FAIL \033[0m Executable files with -x permissions were detected!\n'
[[ -z "${GITHUB_ACTIONS+x}" ]] || echo '::group::Executable files'
echo "$BIN_FILES_WITH_WRONG_PERMISSIONS"
echo ''
echo $BIN_FILES_WITH_WRONG_PERMISSIONS | awk '{print $4}' | xargs -n1 printf 'Please run "\033[32msudo chmod\033[0m +x %s".\n'
[ -z "${GITHUB_ACTIONS+x}" ] || echo '::endgroup::'
[[ -z "${GITHUB_ACTIONS+x}" ]] || echo '::endgroup::'
fi

if [ -n "$FILES_WITH_WRONG_PERMISSIONS" ]; then
if [[ -n "$FILES_WITH_WRONG_PERMISSIONS" ]]; then
exit 3
elif [ -n "$BIN_FILES_WITH_WRONG_PERMISSIONS" ]; then
elif [[ -n "$BIN_FILES_WITH_WRONG_PERMISSIONS" ]]; then
exit 4
fi

printf '\033[32mOK\033[0m No wrong permissions were detected.\n'
printf '\033[42m OK \033[0m No wrong permissions were detected.\n'

0 comments on commit 1f77105

Please sign in to comment.