Skip to content

Commit 175164a

Browse files
committed
check-scripts.sh: added script to check linting and formatting
Ticket: ENT-12601 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
1 parent 698716b commit 175164a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

user-scripts/check-scripts.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash -e
2+
3+
#
4+
# Interactively lint & format shell scripts in the build-scripts directory.
5+
#
6+
# Dependencies:
7+
# * shfmt
8+
# * shellcheck
9+
#
10+
# This script takes no arguments can be executed from anywhere, e.g.:
11+
# $ ./user-scripts/check-scripts.sh
12+
#
13+
14+
BUILD_SCRIPTS="$(dirname "$0")"/../build-scripts
15+
16+
grep -Erl '^(#!/(bin|usr/bin)/(env )?(sh|bash))' "$BUILD_SCRIPTS" | sort | while read -r filepath; do
17+
filename=$(basename "$filepath")
18+
19+
if ! shfmt --diff --indent=4 "$filepath"; then
20+
echo
21+
echo "File '$filename' requires formatting."
22+
read -r -p "Do you wish to format '$filename'? [y/N] " answer </dev/tty
23+
case $answer in
24+
[yY] | [yY][eE][sS])
25+
echo "Formatting file '$filename'..."
26+
shfmt --write --indent=4 "$filepath"
27+
;;
28+
*)
29+
echo "Skipping formatting of file '$filename'..."
30+
;;
31+
esac
32+
fi
33+
34+
if ! shellcheck --external-sources --source-path="$BUILD_SCRIPTS" "$filepath"; then
35+
echo
36+
echo "File '$filename' requires manual intervention."
37+
read -n 1 -s -r -p "Press any key to continue..." </dev/tty
38+
echo
39+
fi
40+
done

0 commit comments

Comments
 (0)