forked from armbian/build
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshellfmt.sh
executable file
·83 lines (65 loc) · 2.5 KB
/
shellfmt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
#
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2013-2023 Igor Pecovnik, [email protected]
#
# This file is a part of the Armbian Build Framework
# https://github.com/armbian/build/
SHELLFMT_VERSION=${SHELLFMT_VERSION:-3.10.0} # https://github.com/mvdan/sh/releases/
SRC="$(
cd "$(dirname "$0")/../.."
pwd -P
)"
echo "SRC: ${SRC}"
DIR_SHELLFMT="${SRC}/cache/tools/shellfmt"
mkdir -p "${DIR_SHELLFMT}"
MACHINE="${BASH_VERSINFO[5]}"
case "$MACHINE" in
*darwin*) SHELLFMT_OS="darwin" ;;
*linux*) SHELLFMT_OS="linux" ;;
*)
echo "unknown os: $MACHINE"
exit 3
;;
esac
case "$MACHINE" in
*aarch64*) SHELLFMT_ARCH="arm64" ;;
*x86_64*) SHELLFMT_ARCH="amd64" ;;
*)
echo "unknown arch: $MACHINE"
exit 2
;;
esac
SHELLFMT_FN="shfmt_v${SHELLFMT_VERSION}_${SHELLFMT_OS}_${SHELLFMT_ARCH}"
DOWN_URL="${GITHUB_SOURCE:-"https://github.com"}/mvdan/sh/releases/download/v${SHELLFMT_VERSION}/${SHELLFMT_FN}"
SHELLFMT_BIN="${DIR_SHELLFMT}/${SHELLFMT_FN}"
echo "MACHINE: ${MACHINE}"
echo "Download URL: ${DOWN_URL}"
echo "SHELLFMT_BIN: ${SHELLFMT_BIN}"
if [[ ! -f "${SHELLFMT_BIN}" ]]; then
echo "Cache miss, downloading..."
wget -O "${SHELLFMT_BIN}" "${DOWN_URL}"
chmod +x "${SHELLFMT_BIN}"
fi
ACTUAL_VERSION="$("${SHELLFMT_BIN}" -version)"
echo "Running shellfmt ${ACTUAL_VERSION}"
cd "${SRC}"
#"${SHELLFMT_BIN}" --help
#"${SHELLFMT_BIN}" -f "${SRC}"
#"${SHELLFMT_BIN}" -d "${SRC}"
# Should match the .editorconfig
# Aggregate all files that should be formatted
board_config_files=$(find config/boards -type f \( -name "*.conf" -o -name "*.csc" -o -name "*.tvb" \)) # All board config files
family_config_files=$(find config/sources -type f \( -name "*.conf" -o -name "*.inc" -o -name "*.sh" \)) # All family config files
lib_files=$(find lib -type f -name "*.sh") # All build framework shell files
extensions_files=$(find extensions -type f -name "*.sh") # All extension shell files
declare -a ALL_BASH_FILES=(compile.sh ${board_config_files} ${family_config_files} ${lib_files} ${extensions_files})
echo -e "\nAll files:" "${ALL_BASH_FILES[@]}"
echo -e "\nShellfmt files differing:"
"${SHELLFMT_BIN}" -l "${ALL_BASH_FILES[@]}" | sort -h # list all formatted files
#echo "Diff with current:"
# "${SHELLFMT_BIN}" -d "${ALL_BASH_FILES[@]}" # list files that have different formatting than they should
echo -e "\nFormatting files..."
"${SHELLFMT_BIN}" -w "${ALL_BASH_FILES[@]}"
echo "Shellfmt finished!"