Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Commit

Permalink
Add POSIX compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke committed Apr 24, 2020
1 parent edffea3 commit 43266d7
Show file tree
Hide file tree
Showing 4 changed files with 429 additions and 563 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/ci.yaml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

---
name: CI

env:
MAVEN_CLI_OPTS: '-Dspring.main.banner-mode=off --batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true'
MAVEN_OPTS: '-Dhttps.protocols=TLSv1.2 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true'

on:
pull_request:
push:
branches:
- master

jobs:
shellcheck:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: Lint check
uses: azohra/[email protected]
with:
path: "*.sh"

shfmt:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: Download shfmt
run: curl -sSL $SHFMT_URL -o ~/shfmt && chmod +x ~/shfmt
env:
SHFMT_URL: https://github.com/mvdan/sh/releases/download/v0.4.0/shfmt_v0.4.0_linux_amd64
- name: Run shfmt
run: ~/shfmt -l -w -i 2 .
- name: Test if syntax is correct
run: git diff --exit-code && echo "shfmt OK"
115 changes: 48 additions & 67 deletions install-binary.sh
Original file line number Diff line number Diff line change
@@ -1,85 +1,66 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

set -ueo pipefail
set -eu

SOPS_VERSION="3.0.4"
SOPS_DEB_URL="https://github.com/mozilla/sops/releases/download/${SOPS_VERSION}/sops_${SOPS_VERSION}_amd64.deb"
SOPS_DEB_SHA="9d9f319882ba05e7050be91bdfc396167ac9b00e2e6f634a647d55ac97915bb6"
SOPS_VERSION="3.5.0"
SOPS_LINUX_URL="https://github.com/mozilla/sops/releases/download/${SOPS_VERSION}/sops-${SOPS_VERSION}.linux"
SOPS_LINUX_SHA="e185d2752defdcb18c054f67682a6684c72d6a6bf2341f6bef1dd7d33a110459"
SOPS_LINUX_SHA="610fca9687d1326ef2e1a66699a740f5dbd5ac8130190275959da737ec52f096"

RED='\033[0;31m'
GREEN='\033[0;32m'
#GREEN='\033[0;32m'
#BLUE='\033[0;34m'
YELLOW='\033[1;33m'
#YELLOW='\033[1;33m'
NOC='\033[0m'

# Find some tools
case "${HELM_BIN}" in
helm)
HELM_DIR="$(dirname $(command -v helm))"
;;
*)
HELM_DIR="$(dirname ${HELM_BIN})"
;;
esac

get_sha_256 () {
if command -v sha256sum > /dev/null; then res=$(sha256sum $1)
elif command -v shasum > /dev/null; then res=$(shasum -a 256 $1)
else res=$(/usr/bin/shasum -a 256 $1)
fi
echo $res | cut -d ' ' -f 1
download() {
if command -v curl >/dev/null; then
curl -sSfL "$1"
elif command -v wget >/dev/null; then
wget -q -O- "$1"
else
return 1
fi
}

# Install the helm wrapper in the same dir as helm itself. That's not
# guaranteed to work, but it's better than hard-coding it.
HELM_WRAPPER="${HELM_DIR}/helm-wrapper"
get_sha_256() {
if command -v sha256sum >/dev/null; then
res=$(sha256sum "$1")
elif command -v shasum >/dev/null; then
res=$(shasum -a 256 "$1")
else
res=''
fi

echo "$res" | cut -d ' ' -f 1
}

if hash sops 2>/dev/null; then
echo "sops is already installed:"
sops --version
echo "sops is already installed: "
sops --version
else

# Try to install sops.

### Mozilla SOPS binary install
if [ "$(uname)" == "Darwin" ];
then
brew install sops
elif [ "$(uname)" == "Linux" ];
then
if which dpkg;
then
curl -sL "${SOPS_DEB_URL}" > /tmp/sops
if [ "$(get_sha_256 /tmp/sops)" == "${SOPS_DEB_SHA}" ];
then
sudo dpkg -i /tmp/sops;
else
echo -e "${RED}Wrong SHA256${NOC}"
fi
else
curl -sL "${SOPS_LINUX_URL}" > /tmp/sops
if [ "$(get_sha_256 /tmp/sops)" == "${SOPS_LINUX_SHA}" ];
then
chmod +x /tmp/sops
mv /tmp/sops /usr/local/bin/
else
echo -e "${RED}Wrong SHA256${NOC}"
fi
fi
rm /tmp/sops 2>/dev/null || true
# Try to install sops.
if [ "$(uname)" = "Darwin" ]; then
brew install sops
elif [ "$(uname)" = "Linux" ]; then
if ! download "${SOPS_LINUX_URL}" >/tmp/sops; then
printf "${RED}%s${NOC}\n" "Can't download SOPS ..."
else
echo -e "${RED}No SOPS package available${NOC}"
exit 1
SOPS_SHA256="$(get_sha_256 /tmp/sops)"
if [ "${SOPS_SHA256}" = "${SOPS_LINUX_SHA}" ] || [ "${SOPS_SHA256}" = "" ]; then
chmod +x /tmp/sops
mv /tmp/sops /usr/local/bin/
else
printf "${RED}%s${NOC}\n" "Wrong SHA256"
fi
rm -f /tmp/sops
fi
else
printf "${RED}%s${NOC}\n" "No SOPS package available"
exit 1
fi
fi

### git diff config
if [ -x "$(command -v git --version)" ];
then
git config --global diff.sopsdiffer.textconv "sops -d"
else
echo -e "${RED}[FAIL]${NOC} Install git command"
exit 1
# If git is no available, fail silent.
if hash git 2>/dev/null; then
git config --global diff.sopsdiffer.textconv "sops -d"
fi
Loading

0 comments on commit 43266d7

Please sign in to comment.