Skip to content

Commit 50d388f

Browse files
committed
check-scripts.sh: added script to check linting and formatting
Ticket: ENT-12601 Signed-off-by: Lars Erik Wik <[email protected]>
1 parent 75968eb commit 50d388f

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

build-scripts/produce-debug-symbols

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
. detect-environment
55
. compile-options
66

7-
if [ "$BUILD_TYPE" != "RELEASE" ]; then
7+
if [ $BUILD_TYPE != "RELEASE" ]; then
88
echo "Debug symbols not requested"
99
exit 0
1010
else
@@ -60,7 +60,7 @@ done
6060

6161
# Write the installation script
6262
log_debug "Writing the installation script"
63-
cat <<EOF >> $PAYLOAD_DIR/install-ds.sh
63+
cat <<EOF >>$PAYLOAD_DIR/install-ds.sh
6464
#!/bin/sh
6565
# Install debug symbols for executables
6666
for i in \`ls exe/*.gz\`; do
@@ -77,7 +77,7 @@ EOF
7777

7878
# Write the decompression script
7979
log_debug "Writing the decompression script"
80-
cat <<EOF >> decompress-ds.sh
80+
cat <<EOF >>decompress-ds.sh
8181
#!/bin/sh
8282
echo "Installing debug symbols"
8383
TMPDIR=\`mktemp -d /tmp/ds.XXXXXX\`; export TMPDIR
@@ -97,7 +97,7 @@ EOF
9797

9898
# Write the uninstall script
9999
log_debug "Writing the uninstall script"
100-
cat <<EOF >> $PAYLOAD_DIR/uninstall-ds.sh
100+
cat <<EOF >>$PAYLOAD_DIR/uninstall-ds.sh
101101
#!/bin/sh
102102
echo "Uninstalling debug symbols"
103103
rm -f "$PREFIX"/bin/*.\$DEBUG_SUFFIX

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)