mirror of
https://github.com/armbian/build
synced 2025-09-24 19:47:06 +07:00
armbian-next: lib/tools - shell - gen library and shellfmt
- armbian-next: `lib/tools/shellfmt.sh` - format only `lib` and `config/sources/`, `extensions` and `compile.sh`
This commit is contained in:
68
lib/tools/shellfmt.sh
Executable file
68
lib/tools/shellfmt.sh
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SHELLFMT_VERSION=${SHELLFMT_VERSION:-3.5.1} # 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="https://github.com/mvdan/sh/releases/download/v${SHELLFMT_VERSION}/${SHELLFMT_FN}"
|
||||
SHELLFMT_BIN="${DIR_SHELLFMT}/${SHELLFMT_FN}"
|
||||
|
||||
echo "MACHINE: ${MACHINE}"
|
||||
echo "Down 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
|
||||
|
||||
declare -a ALL_BASH_FILES=($(find config/sources -type f | grep -e "\.conf\$" -e "\.inc\$") $(find lib -type f | grep -e "\.sh\$" | grep -v -e "^lib\/tools\/") $(find extensions -type f | grep -e "\.sh\$") compile.sh)
|
||||
|
||||
echo "All files:" "${ALL_BASH_FILES[@]}"
|
||||
|
||||
echo "Shellfmt 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 "Doing for real:"
|
||||
"${SHELLFMT_BIN}" -w "${ALL_BASH_FILES[@]}"
|
||||
Reference in New Issue
Block a user