Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # This installs shellcheck and shfmt linters into your computer.
- # This script is shellcheck and "shfmt -i 2" compliant ;-)
- # Copyright (C) 2018 Saichovsky. All rights reserved
- ARCH=$(uname -m)
- if [[ $ARCH =~ .*386.* ]]; then
- ARCH=386
- elif [[ $ARCH == x86_64 ]]; then
- ARCH=amd64
- else
- echo "I only support 386 and amd64 platforms. Feel free to extend. Will exit now."
- exit 4
- fi
- what_os() {
- echo "Please use a more decent OS." >&2
- exit 1
- }
- download() {
- FNAME=$(echo "$1" | awk -F '/' '{print $NF}')
- if command -v curl >/dev/null; then
- curl -skLo "$FNAME" "$1" || (
- echo "Failed to download $FNAME"
- exit 2
- )
- elif command -v wget >/dev/null; then
- wget -q -O "$FNAME" "$1" || (
- echo "Failed to download $FNAME"
- exit 2
- )
- else
- echo "Couldn't find a suitable HTTP client"
- exit 2
- fi
- }
- get_shfmt() {
- CMD=
- command -v curl >/dev/null && CMD="curl -sL" || CMD="wget -q -O -"
- BINPATH=$($CMD "$1" | grep -oE '/mvdan/.*linux_'${ARCH} | head -1)
- RV=$?
- [ $RV -eq 0 ] || (
- echo "Failed to retrieve the shfmt URL"
- exit 3
- )
- (download "https://github.com/${BINPATH}" &&
- sudo install -m 0755 -o 0 -g 0 shfmt_v* /usr/bin/shfmt && rm -f shfmt_v* &&
- echo "Installed shfmt successfully") ||
- (
- echo "Error downloading shfmt."
- exit 3
- )
- }
- # Install shfmt and shellcheck
- printf 'Please wait while I install some dependencies... \n'
- if [ "$(uname)" = "Darwin" ]; then
- command -v shfmt >/dev/null || brew install shfmt
- command -v shellcheck >/dev/null || brew install shellcheck
- echo "Done!"
- elif [ "$(uname)" = "Linux" ]; then
- pushd /tmp || true
- # Install shellcheck
- if ! command -v shellcheck >/dev/null; then
- download "https://storage.googleapis.com/shellcheck/shellcheck-stable.linux.x86_64.tar.xz"
- tar -Jxvf shellcheck-stable.linux.x86_64.tar.xz >/dev/null 2>&1
- sudo cp shellcheck-stable/shellcheck /usr/bin/ && rm -fr shellcheck-stable* &&
- echo "Install shellcheck successfully"
- fi
- # Install shfmt
- if ! command -v shfmt >/dev/null; then
- get_shfmt "https://github.com/mvdan/sh/releases/latest/"
- fi
- popd >/dev/null || true
- echo "Done!"
- else
- what_os
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement