Skip to content

Commit c755844

Browse files
committed
Use shfmt as formatter for shell scripts
1 parent 1e11fff commit c755844

14 files changed

+113
-141
lines changed

.editorconfig

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[*.sh]
2+
space_redirects = true

.github/workflows/style.yml

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
sudo apt-get install clang-format imagemagick ddnet-tools shellcheck pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev python3-clang libvulkan-dev glslang-tools spirv-tools -y
2424
rustup default stable
2525
pip3 install pylint
26+
wget -O ~/.local/bin/shfmt https://github.com/mvdan/sh/releases/download/v3.8.0/shfmt_v3.8.0_linux_amd64
27+
chmod +x ~/.local/bin/shfmt
2628
git clone https://gitlab.com/Patiga/twmap.git/
2729
cd twmap/twmap-tools
2830
cargo install --locked --path=.
@@ -60,6 +62,8 @@ jobs:
6062
# fi
6163
- name: Shellcheck
6264
run: find . -type f -name '*.sh' -print0 | xargs -0 shellcheck
65+
- name: Shell format (shfmt)
66+
run: find . -type f -name '*.sh' -print0 | xargs -0 shfmt -d
6367
- name: Check log error case
6468
run: |
6569
if grep -Eqr '(msg|Print).*\(.*"[Ee]rror:' src/;

man/generate.sh

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env bash
22

3-
command -v a2x >/dev/null 2>&1 || {
4-
echo >&2 "You need asciidoc installed";
5-
echo >&2 "Debian/Ubuntu: sudo apt install asciidoc";
6-
echo >&2 "http://asciidoc.org/";
7-
exit 1;
3+
command -v a2x > /dev/null 2>&1 || {
4+
echo >&2 "You need asciidoc installed"
5+
echo >&2 "Debian/Ubuntu: sudo apt install asciidoc"
6+
echo >&2 "http://asciidoc.org/"
7+
exit 1
88
}
99

1010
set -ex
@@ -20,4 +20,3 @@ EOF
2020

2121
a2x --doctype manpage --format manpage DDNet.adoc
2222
a2x --doctype manpage --format manpage DDNetServer.adoc
23-

other/config_directory.sh

+22-19
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
#!/bin/sh
22
case "$(uname -s)" in
3-
CYGWIN*|MINGW*|MSYS*)
4-
if [ -d "$APPDATA/DDNet/" ]; then
5-
explorer "$APPDATA/DDNet/"
6-
else
7-
explorer "$APPDATA/Teeworlds/"
8-
fi;;
9-
Darwin*)
10-
if [ -d "$HOME/Library/Application Support/DDNet/" ]; then
11-
open "$HOME/Library/Application Support/DDNet/"
12-
else
13-
open "$HOME/Library/Application Support/Teeworlds/"
14-
fi;;
15-
*)
16-
DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
17-
if [ -d "$DATA_HOME/ddnet/" ]; then
18-
xdg-open "$DATA_HOME/ddnet/"
19-
else
20-
xdg-open "$HOME/.teeworlds/"
21-
fi;;
3+
CYGWIN* | MINGW* | MSYS*)
4+
if [ -d "$APPDATA/DDNet/" ]; then
5+
explorer "$APPDATA/DDNet/"
6+
else
7+
explorer "$APPDATA/Teeworlds/"
8+
fi
9+
;;
10+
Darwin*)
11+
if [ -d "$HOME/Library/Application Support/DDNet/" ]; then
12+
open "$HOME/Library/Application Support/DDNet/"
13+
else
14+
open "$HOME/Library/Application Support/Teeworlds/"
15+
fi
16+
;;
17+
*)
18+
DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
19+
if [ -d "$DATA_HOME/ddnet/" ]; then
20+
xdg-open "$DATA_HOME/ddnet/"
21+
else
22+
xdg-open "$HOME/.teeworlds/"
23+
fi
24+
;;
2225
esac

scripts/android/cmake_android.sh

+10-10
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,35 @@ _ANDROID_SUB_BUILD_DIR=build_arch
2424
_SHOW_USAGE_INFO=0
2525

2626
if [ -z ${1+x} ]; then
27-
printf "\e[31m%s\e[30m\n" "Did not pass android build type, using default: ${_DEFAULT_ANDROID_BUILD}"
27+
printf "\e[31m%s\e[30m\n" "Did not pass android build type, using default: ${_DEFAULT_ANDROID_BUILD}"
2828
_SHOW_USAGE_INFO=1
2929
else
3030
_DEFAULT_ANDROID_BUILD=$1
3131
fi
3232

3333
if [ -z ${2+x} ]; then
34-
printf "\e[31m%s\e[30m\n" "Did not pass game name, using default: ${_DEFAULT_GAME_NAME}"
34+
printf "\e[31m%s\e[30m\n" "Did not pass game name, using default: ${_DEFAULT_GAME_NAME}"
3535
_SHOW_USAGE_INFO=1
3636
else
3737
_DEFAULT_GAME_NAME=$2
3838
fi
3939

4040
if [ -z ${3+x} ]; then
41-
printf "\e[31m%s\e[30m\n" "Did not pass package name, using default: ${_DEFAULT_PACKAGE_NAME}"
41+
printf "\e[31m%s\e[30m\n" "Did not pass package name, using default: ${_DEFAULT_PACKAGE_NAME}"
4242
_SHOW_USAGE_INFO=1
4343
else
4444
_DEFAULT_PACKAGE_NAME=$3
4545
fi
4646

4747
if [ -z ${4+x} ]; then
48-
printf "\e[31m%s\e[30m\n" "Did not pass build type, using default: ${_DEFAULT_BUILD_TYPE}"
48+
printf "\e[31m%s\e[30m\n" "Did not pass build type, using default: ${_DEFAULT_BUILD_TYPE}"
4949
_SHOW_USAGE_INFO=1
5050
else
5151
_DEFAULT_BUILD_TYPE=$4
5252
fi
5353

5454
if [ -z ${5+x} ]; then
55-
printf "\e[31m%s\e[30m\n" "Did not pass build folder, using default: ${_DEFAULT_BUILD_FOLDER}"
55+
printf "\e[31m%s\e[30m\n" "Did not pass build folder, using default: ${_DEFAULT_BUILD_FOLDER}"
5656
_SHOW_USAGE_INFO=1
5757
else
5858
_DEFAULT_BUILD_FOLDER=$5
@@ -63,17 +63,17 @@ _ANDROID_JAR_KEY_PW=android
6363
_ANDROID_JAR_KEY_ALIAS=androiddebugkey
6464

6565
if [ -z ${TW_KEY_NAME+x} ]; then
66-
printf "\e[31m%s\e[30m\n" "Did not pass a key for the jar signer, using default: ${_ANDROID_JAR_KEY_NAME}"
66+
printf "\e[31m%s\e[30m\n" "Did not pass a key for the jar signer, using default: ${_ANDROID_JAR_KEY_NAME}"
6767
else
6868
_ANDROID_JAR_KEY_NAME=$TW_KEY_NAME
6969
fi
7070
if [ -z ${TW_KEY_PW+x} ]; then
71-
printf "\e[31m%s\e[30m\n" "Did not pass a key pw for the jar signer, using default: ${_ANDROID_JAR_KEY_PW}"
71+
printf "\e[31m%s\e[30m\n" "Did not pass a key pw for the jar signer, using default: ${_ANDROID_JAR_KEY_PW}"
7272
else
7373
_ANDROID_JAR_KEY_PW=$TW_KEY_PW
7474
fi
7575
if [ -z ${TW_KEY_ALIAS+x} ]; then
76-
printf "\e[31m%s\e[30m\n" "Did not pass a key alias for the jar signer, using default: ${_ANDROID_JAR_KEY_ALIAS}"
76+
printf "\e[31m%s\e[30m\n" "Did not pass a key alias for the jar signer, using default: ${_ANDROID_JAR_KEY_ALIAS}"
7777
else
7878
_ANDROID_JAR_KEY_ALIAS=$TW_KEY_ALIAS
7979
fi
@@ -110,8 +110,8 @@ export TW_VERSION_NAME=$_ANDROID_VERSION_NAME
110110

111111
printf "\e[31m%s\e[1m\n" "Building with setting, for arch: ${_DEFAULT_ANDROID_BUILD}, with build type: ${_DEFAULT_BUILD_TYPE}, with name: ${_DEFAULT_GAME_NAME} (${_DEFAULT_PACKAGE_NAME})"
112112

113-
if [ $_SHOW_USAGE_INFO == 1 ]; then
114-
printf "\e[31m%s\e[1m\n" "Usage: ./cmake_android.sh <x86/x86_64/arm/arm64/all> <Game name> <Package name> <Debug/Release> <Build folder>"
113+
if [ $_SHOW_USAGE_INFO == 1 ]; then
114+
printf "\e[31m%s\e[1m\n" "Usage: ./cmake_android.sh <x86/x86_64/arm/arm64/all> <Game name> <Package name> <Debug/Release> <Build folder>"
115115
fi
116116

117117
printf "\e[33mBuilding cmake\e[0m\n"

scripts/android/files/build.sh

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#!/bin/bash
22

33
[ "$1" == "" ] && {
4-
printf '\e[31mDid not pass APK name to build script\e[30m\n'
4+
printf '\e[31mDid not pass APK name to build script\e[30m\n'
55
exit 1
66
}
77

88
[ "$2" == "" ] && {
9-
printf '\e[31mDid not pass package name to build script\e[30m\n'
9+
printf '\e[31mDid not pass package name to build script\e[30m\n'
1010
exit 1
1111
}
1212

1313
[ "$3" == "" ] && {
14-
printf '\e[31mDid not pass build type to build script\e[30m\n'
14+
printf '\e[31mDid not pass build type to build script\e[30m\n'
1515
exit 1
1616
}
1717

1818
_APK_BASENAME="$1"
1919
_APK_PACKAGE_NAME="$2"
2020
_APK_BUILD_TYPE="$3"
2121

22-
_APK_PACKAGE_FOLDER=$(echo "$_APK_PACKAGE_NAME"|sed 's/\./\//g')
22+
_APK_PACKAGE_FOLDER=$(echo "$_APK_PACKAGE_NAME" | sed 's/\./\//g')
2323

2424
sed -i "s/DDNet/${_APK_BASENAME}/g" settings.gradle
2525

2626
sed -i "s/org.ddnet.client/${_APK_PACKAGE_NAME}/g" build.gradle
2727

28-
TW_KEY_NAME_ESCAPED=$(echo "$TW_KEY_NAME"|sed 's/\//\\\//g')
29-
TW_KEY_PW_ESCAPED=$(echo "$TW_KEY_PW"|sed 's/\//\\\//g')
30-
TW_KEY_ALIAS_ESCAPED=$(echo "$TW_KEY_ALIAS"|sed 's/\//\\\//g')
28+
TW_KEY_NAME_ESCAPED=$(echo "$TW_KEY_NAME" | sed 's/\//\\\//g')
29+
TW_KEY_PW_ESCAPED=$(echo "$TW_KEY_PW" | sed 's/\//\\\//g')
30+
TW_KEY_ALIAS_ESCAPED=$(echo "$TW_KEY_ALIAS" | sed 's/\//\\\//g')
3131

3232
sed -i "s/TW_KEY_NAME/${TW_KEY_NAME_ESCAPED}/g" build.gradle
3333
sed -i "s/TW_KEY_PW/${TW_KEY_PW_ESCAPED}/g" build.gradle
@@ -65,7 +65,7 @@ if [[ -z ${GE_NO_APK_BUILD} || "${GE_NO_APK_BUILD}" != "1" ]]; then
6565
_RELEASE_TYPE_NAME=release
6666
_RELEASE_TYPE_APK_NAME=
6767
fi
68-
68+
6969
APP_BASE_NAME=Gradle
7070
CLASSPATH=gradle-wrapper.jar
7171
java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all
@@ -77,11 +77,10 @@ if [[ -z ${GE_NO_APK_BUILD} || "${GE_NO_APK_BUILD}" != "1" ]]; then
7777
java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all assembleRelease
7878
fi
7979
cp build/outputs/apk/"$_RELEASE_TYPE_NAME"/"$_APK_BASENAME"-"$_RELEASE_TYPE_NAME""$_RELEASE_TYPE_APK_NAME".apk "$_APK_BASENAME".apk
80-
81-
80+
8281
if [[ "${_APK_BUILD_TYPE}" == "Release" ]]; then
8382
java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all bundleRelease
84-
83+
8584
cp build/outputs/bundle/"$_RELEASE_TYPE_NAME"/"$_APK_BASENAME"-"$_RELEASE_TYPE_NAME""$_RELEASE_TYPE_APK_NAME".aab "$_APK_BASENAME".aab
8685
fi
8786
fi

scripts/check_standard_headers.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ c_headers=(assert complex ctype errno fenv float inttypes iso646 limits locale m
55
c_headers_map=(cassert complex cctype cerrno cfenv cfloat cinttypes ciso646 climits clocale cmath csetjmp csignal cstdarg cstdbool cstddef cstdint cstdio cstdlib cstring ctgmath ctime cwchar cwctype)
66

77
# Create regex dynamically from the array to match any C header
8-
c_headers_regex=$(IFS="|"; echo "${c_headers[*]}")
8+
c_headers_regex=$(printf "%s" "${c_headers[*]}" | tr ' ' '|')
99

1010
# Find all C++ source and header files
1111
files=$(find ./src -type f \( -name '*.cpp' -o -name '*.hpp' -o -name '*.h' \) ! -path "./src/engine/external/*")
@@ -15,10 +15,10 @@ error_found=0
1515
# Check each source file for C headers
1616
for file in $files; do
1717
# First check if the file includes any C headers for more efficiency when no C header is used
18-
if grep -E "#include\s+<($c_headers_regex)\.h>" "$file" >/dev/null; then
18+
if grep -E "#include\s+<($c_headers_regex)\.h>" "$file" > /dev/null; then
1919
# Check each C header individually to print an error message with the appropriate replacement C++ header
20-
for (( i=0; i < ${#c_headers[@]}; i++ )); do
21-
if grep -E "#include\s+<${c_headers[i]}\.h>" "$file" >/dev/null; then
20+
for ((i = 0; i < ${#c_headers[@]}; i++)); do
21+
if grep -E "#include\s+<${c_headers[i]}\.h>" "$file" > /dev/null; then
2222
echo "Error: '$file' includes C header '${c_headers[i]}.h'. Include the C++ header '${c_headers_map[i]}' instead."
2323
fi
2424
done

scripts/compile_libs/cmake_lib_compile.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if [[ "${2}" == "webasm" ]]; then
1111
COMPILEFLAGS="-pthread -O3 -g -s USE_PTHREADS=1"
1212
LINKFLAGS="-pthread -O3 -g -s USE_PTHREADS=1 -s ASYNCIFY=1"
1313
fi
14-
14+
1515
COMPILEFLAGS=$3
1616
LINKFLAGS=$4
1717

scripts/compile_libs/gen_libs.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/bin/bash
22

33
CURDIR="$PWD"
4-
if [ -z ${1+x} ]; then
4+
if [ -z ${1+x} ]; then
55
echo "Give a destination path where to run this script, please choose a path other than in the source directory"
66
exit 1
77
fi
88

9-
if [ -z ${2+x} ]; then
9+
if [ -z ${2+x} ]; then
1010
echo "Specify the target system"
1111
exit 1
1212
fi
1313

1414
OS_NAME=$2
15-
15+
1616
COMPILEFLAGS="-fPIC"
1717
LINKFLAGS="-fPIC"
1818
if [[ "${OS_NAME}" == "webasm" ]]; then

scripts/compile_libs/make_lib_openssl.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function buid_openssl() {
2525
if [[ "$_EXISTS_PROJECT" == "0" ]]; then
2626
if [[ "${4}" == "webasm" ]]; then
2727
emconfigure ../Configure "$2" -no-tests -no-asm -static -no-afalgeng -DOPENSSL_SYS_NETWARE -DSIG_DFL=0 -DSIG_IGN=0 -DHAVE_FORK=0 -DOPENSSL_NO_AFALGENG=1 --with-rand-seed=getrandom
28-
28+
2929
sed -i 's|^CROSS_COMPILE.*$|CROSS_COMPILE=|g' Makefile
3030
else
3131
../Configure "$2" no-asm no-shared

scripts/compile_libs/make_lib_opusfile.sh

-1
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,3 @@ function compile_all_opusfile() {
7777
}
7878

7979
compile_all_opusfile "$1" "$2"
80-

scripts/compile_libs/make_lib_sqlite3.sh

+11-12
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ function make_sqlite3() {
3232
LDFLAGS="${LINKER_FLAGS} -L./" \
3333
LD_LIBRARY_PATH="$_LD_LIBRARY_PATH" \
3434
${TMP_COMPILER} \
35-
-c \
36-
-fPIC \
37-
-DSQLITE_ENABLE_ATOMIC_WRITE=1 \
38-
-DSQLITE_ENABLE_BATCH_ATOMIC_WRITE=1 \
39-
-DSQLITE_ENABLE_MULTITHREADED_CHECKS=1 \
40-
-DSQLITE_THREADSAFE=1 \
41-
../sqlite3.c \
42-
-o sqlite3.o
35+
-c \
36+
-fPIC \
37+
-DSQLITE_ENABLE_ATOMIC_WRITE=1 \
38+
-DSQLITE_ENABLE_BATCH_ATOMIC_WRITE=1 \
39+
-DSQLITE_ENABLE_MULTITHREADED_CHECKS=1 \
40+
-DSQLITE_THREADSAFE=1 \
41+
../sqlite3.c \
42+
-o sqlite3.o
4343

4444
LDFLAGS="${LINKER_FLAGS} -L./" \
4545
LD_LIBRARY_PATH="$_LD_LIBRARY_PATH" \
4646
${TMP_AR} \
47-
rvs \
48-
sqlite3.a \
49-
sqlite3.o
47+
rvs \
48+
sqlite3.a \
49+
sqlite3.o
5050
)
5151
}
5252

@@ -62,4 +62,3 @@ function compile_all_sqlite3() {
6262
}
6363

6464
compile_all_sqlite3 "$1" "$2"
65-

0 commit comments

Comments
 (0)