Skip to content

Commit

Permalink
Use shfmt to format all shell code
Browse files Browse the repository at this point in the history
  • Loading branch information
autarch committed May 11, 2024
1 parent 1960126 commit d0ba51f
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 94 deletions.
179 changes: 90 additions & 89 deletions bootstrap/bootstrap-ubi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,99 +22,100 @@ if [ -z "$FILENAME" ]; then
LIBC=""
EXT="tar.gz"
case "$KERNEL" in
Linux)
OS="Linux"
;;
Darwin)
OS="Darwin"
;;
FreeBSD)
OS="FreeBSD"
;;
NetBSD)
OS="NetBSD"
;;
MINGW*)
OS="Windows"
EXT="zip"
;;
*)
echo "boostrap-ubi.sh: Cannot determine what binary to download for your kernel: $KERNEL"
exit 3
;;
Linux)
OS="Linux"
;;
Darwin)
OS="Darwin"
;;
FreeBSD)
OS="FreeBSD"
;;
NetBSD)
OS="NetBSD"
;;
MINGW*)
OS="Windows"
EXT="zip"
;;
*)
echo "boostrap-ubi.sh: Cannot determine what binary to download for your kernel: $KERNEL"
exit 3
;;
esac

# I previous had uname -p but that reports all sorts of weird stuff. On one
# person's Linux x86_64 machine it reported "unknown". On macOS x86_64 you get
# "i386". Why? I have no idea.
ARCH=$(uname -m)
case "$ARCH" in
i386|i486|i586|i686)
CPU="i786"
if [ "$OS" = "Linux" ]; then
LIBC="-musl"
fi
;;
x86_64|amd64)
CPU="x86_64"
if [ "$OS" = "Linux" ]; then
LIBC="-musl"
fi
;;
arm|armv5*|armv6*|armv7*)
CPU="arm"
if [ "$OS" = "Linux" ]; then
LIBC="-musl"
fi
;;
aarch64|arm64)
CPU="aarch64"
if [ "$OS" = "Linux" ]; then
LIBC="-musl"
fi
;;
mips)
CPU="mips"
;;
mipsel|mipsle)
CPU="mipsel"
;;
mips64)
CPU="mips64"
;;
mips64el|mips64le)
CPU="mips64el"
;;
powerpc|ppc)
CPU="powerpc"
if [ "$OS" = "Linux" ]; then
LIBC="-gnu"
fi
;;
powerpc64|ppc64)
CPU="powerpc64"
if [ "$OS" = "Linux" ]; then
LIBC="-gnu"
fi
;;
powerpc64le|ppc64le)
CPU="powerpc64le"
;;
riscv64|rv64gc)
CPU="riscv64gc"
if [ "$OS" = "Linux" ]; then
LIBC="-gnu"
fi
;;
s390x)
CPU="s390x"
if [ "$OS" = "Linux" ]; then
LIBC="-gnu"
fi
;;
*)
echo "boostrap-ubi.sh: Cannot determine what binary to download for your CPU architecture: $ARCH"
exit 4
i386 | i486 | i586 | i686)
CPU="i786"
if [ "$OS" = "Linux" ]; then
LIBC="-musl"
fi
;;
x86_64 | amd64)
CPU="x86_64"
if [ "$OS" = "Linux" ]; then
LIBC="-musl"
fi
;;
arm | armv5* | armv6* | armv7*)
CPU="arm"
if [ "$OS" = "Linux" ]; then
LIBC="-musl"
fi
;;
aarch64 | arm64)
CPU="aarch64"
if [ "$OS" = "Linux" ]; then
LIBC="-musl"
fi
;;
mips)
CPU="mips"
;;
mipsel | mipsle)
CPU="mipsel"
;;
mips64)
CPU="mips64"
;;
mips64el | mips64le)
CPU="mips64el"
;;
powerpc | ppc)
CPU="powerpc"
if [ "$OS" = "Linux" ]; then
LIBC="-gnu"
fi
;;
powerpc64 | ppc64)
CPU="powerpc64"
if [ "$OS" = "Linux" ]; then
LIBC="-gnu"
fi
;;
powerpc64le | ppc64le)
CPU="powerpc64le"
;;
riscv64 | rv64gc)
CPU="riscv64gc"
if [ "$OS" = "Linux" ]; then
LIBC="-gnu"
fi
;;
s390x)
CPU="s390x"
if [ "$OS" = "Linux" ]; then
LIBC="-gnu"
fi
;;
*)
echo "boostrap-ubi.sh: Cannot determine what binary to download for your CPU architecture: $ARCH"
exit 4
;;
esac

FILENAME="ubi-$OS-$CPU$LIBC.$EXT"
Expand All @@ -126,12 +127,12 @@ else
URL="https://github.com/houseabsolute/ubi/releases/download/$TAG/$FILENAME"
fi

TEMPDIR=$( mktemp -d )
TEMPDIR=$(mktemp -d)
trap 'rm -rf -- "$TEMPDIR"' EXIT
LOCAL_FILE="$TEMPDIR/$FILENAME"

echo "downloading $URL"
STATUS=$( curl --silent --output "$LOCAL_FILE" --write-out "%{http_code}" --location "$URL" )
STATUS=$(curl --silent --output "$LOCAL_FILE" --write-out "%{http_code}" --location "$URL")
if [ -z "$STATUS" ]; then
>&2 echo "curl failed to download $URL and did not print a status code"
exit 5
Expand All @@ -152,7 +153,7 @@ echo ""
echo "boostrap-ubi.sh: ubi has been installed to $TARGET."

set +e
TARGET_IS_IN_PATH=$( echo ":$PATH:" | grep --extended-regexp ":$TARGET:" 2> /dev/null )
TARGET_IS_IN_PATH=$(echo ":$PATH:" | grep --extended-regexp ":$TARGET:" 2>/dev/null)
if [ -z "$TARGET_IS_IN_PATH" ]; then
echo "boostrap-ubi.sh: It looks like $TARGET is not in your PATH. You may want to add it to use ubi."
fi
Expand Down
11 changes: 6 additions & 5 deletions dev/bin/install-dev-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

set -eo pipefail

function run () {
function run() {
echo "$1"
eval "$1"
}

function install_tools () {
function install_tools() {
curl --silent --location \
https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh |
https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh |
sh
run "rustup component add clippy"
run "ubi --project houseabsolute/precious --in ~/bin"
run "ubi --project houseabsolute/omegasort --in ~/bin"
run "ubi --project koalaman/shellcheck --in ~/bin"
run "ubi --project mvdan/sh --in ~/bin --exe shfmt"
run "npm install [email protected]"
}

Expand All @@ -25,7 +26,7 @@ fi
mkdir -p "$HOME/bin"

set +e
if echo ":$PATH:" | grep --extended-regexp ":$HOME/bin:" >& /dev/null; then
if echo ":$PATH:" | grep --extended-regexp ":$HOME/bin:" >&/dev/null; then
path_has_home_bin=1
fi
set -e
Expand All @@ -38,7 +39,7 @@ install_tools

echo "Tools were installed into $HOME/bin."
if [ -z "$path_has_home_bin" ]; then
echo "You should add $HOME/bin to your PATH."
echo "You should add $HOME/bin to your PATH."
fi

exit 0
10 changes: 10 additions & 0 deletions precious.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ include = "**/*.sh"
cmd = "shellcheck"
ok_exit_codes = 0
lint_failure_exit_codes = 1

[commands.shfmt]
type = "both"
include = "**/*.sh"
cmd = [ "shfmt", "--simplify", "--indent", "4" ]
lint_flags = "--diff"
tidy_flags = "--write"
ok_exit_codes = 0
lint_failure_exit_codes = 1

0 comments on commit d0ba51f

Please sign in to comment.