|
1 | | -#!/usr/bin/env bash |
| 1 | +#!/usr/bin/env sh |
2 | 2 |
|
3 | | -set -ueo pipefail |
| 3 | +set -eu |
4 | 4 |
|
5 | | -SOPS_VERSION="3.0.4" |
6 | | -SOPS_DEB_URL="https://github.com/mozilla/sops/releases/download/${SOPS_VERSION}/sops_${SOPS_VERSION}_amd64.deb" |
7 | | -SOPS_DEB_SHA="9d9f319882ba05e7050be91bdfc396167ac9b00e2e6f634a647d55ac97915bb6" |
| 5 | +SOPS_VERSION="3.5.0" |
8 | 6 | SOPS_LINUX_URL="https://github.com/mozilla/sops/releases/download/${SOPS_VERSION}/sops-${SOPS_VERSION}.linux" |
9 | | -SOPS_LINUX_SHA="e185d2752defdcb18c054f67682a6684c72d6a6bf2341f6bef1dd7d33a110459" |
| 7 | +SOPS_LINUX_SHA="610fca9687d1326ef2e1a66699a740f5dbd5ac8130190275959da737ec52f096" |
10 | 8 |
|
11 | 9 | RED='\033[0;31m' |
12 | | -GREEN='\033[0;32m' |
| 10 | +#GREEN='\033[0;32m' |
13 | 11 | #BLUE='\033[0;34m' |
14 | | -YELLOW='\033[1;33m' |
| 12 | +#YELLOW='\033[1;33m' |
15 | 13 | NOC='\033[0m' |
16 | 14 |
|
17 | | -# Find some tools |
18 | | -case "${HELM_BIN}" in |
19 | | - helm) |
20 | | - HELM_DIR="$(dirname $(command -v helm))" |
21 | | - ;; |
22 | | - *) |
23 | | - HELM_DIR="$(dirname ${HELM_BIN})" |
24 | | - ;; |
25 | | -esac |
26 | | - |
27 | | -get_sha_256 () { |
28 | | - if command -v sha256sum > /dev/null; then res=$(sha256sum $1) |
29 | | - elif command -v shasum > /dev/null; then res=$(shasum -a 256 $1) |
30 | | - else res=$(/usr/bin/shasum -a 256 $1) |
31 | | - fi |
32 | | - echo $res | cut -d ' ' -f 1 |
| 15 | +download() { |
| 16 | + if command -v curl >/dev/null; then |
| 17 | + curl -sSfL "$1" |
| 18 | + elif command -v wget >/dev/null; then |
| 19 | + wget -q -O- "$1" |
| 20 | + else |
| 21 | + return 1 |
| 22 | + fi |
33 | 23 | } |
34 | 24 |
|
35 | | -# Install the helm wrapper in the same dir as helm itself. That's not |
36 | | -# guaranteed to work, but it's better than hard-coding it. |
37 | | -HELM_WRAPPER="${HELM_DIR}/helm-wrapper" |
| 25 | +get_sha_256() { |
| 26 | + if command -v sha256sum >/dev/null; then |
| 27 | + res=$(sha256sum "$1") |
| 28 | + elif command -v shasum >/dev/null; then |
| 29 | + res=$(shasum -a 256 "$1") |
| 30 | + else |
| 31 | + res='' |
| 32 | + fi |
| 33 | + |
| 34 | + echo "$res" | cut -d ' ' -f 1 |
| 35 | +} |
38 | 36 |
|
39 | 37 | if hash sops 2>/dev/null; then |
40 | | - echo "sops is already installed:" |
41 | | - sops --version |
| 38 | + echo "sops is already installed: " |
| 39 | + sops --version |
42 | 40 | else |
43 | | - |
44 | | - # Try to install sops. |
45 | | - |
46 | | - ### Mozilla SOPS binary install |
47 | | - if [ "$(uname)" == "Darwin" ]; |
48 | | - then |
49 | | - brew install sops |
50 | | - elif [ "$(uname)" == "Linux" ]; |
51 | | - then |
52 | | - if which dpkg; |
53 | | - then |
54 | | - curl -sL "${SOPS_DEB_URL}" > /tmp/sops |
55 | | - if [ "$(get_sha_256 /tmp/sops)" == "${SOPS_DEB_SHA}" ]; |
56 | | - then |
57 | | - sudo dpkg -i /tmp/sops; |
58 | | - else |
59 | | - echo -e "${RED}Wrong SHA256${NOC}" |
60 | | - fi |
61 | | - else |
62 | | - curl -sL "${SOPS_LINUX_URL}" > /tmp/sops |
63 | | - if [ "$(get_sha_256 /tmp/sops)" == "${SOPS_LINUX_SHA}" ]; |
64 | | - then |
65 | | - chmod +x /tmp/sops |
66 | | - mv /tmp/sops /usr/local/bin/ |
67 | | - else |
68 | | - echo -e "${RED}Wrong SHA256${NOC}" |
69 | | - fi |
70 | | - fi |
71 | | - rm /tmp/sops 2>/dev/null || true |
| 41 | + # Try to install sops. |
| 42 | + if [ "$(uname)" = "Darwin" ]; then |
| 43 | + brew install sops |
| 44 | + elif [ "$(uname)" = "Linux" ]; then |
| 45 | + if ! download "${SOPS_LINUX_URL}" >/tmp/sops; then |
| 46 | + printf "${RED}%s${NOC}\n" "Can't download SOPS ..." |
72 | 47 | else |
73 | | - echo -e "${RED}No SOPS package available${NOC}" |
74 | | - exit 1 |
| 48 | + SOPS_SHA256="$(get_sha_256 /tmp/sops)" |
| 49 | + if [ "${SOPS_SHA256}" = "${SOPS_LINUX_SHA}" ] || [ "${SOPS_SHA256}" = "" ]; then |
| 50 | + chmod +x /tmp/sops |
| 51 | + mv /tmp/sops /usr/local/bin/ |
| 52 | + else |
| 53 | + printf "${RED}%s${NOC}\n" "Wrong SHA256" |
| 54 | + fi |
| 55 | + rm -f /tmp/sops |
75 | 56 | fi |
| 57 | + else |
| 58 | + printf "${RED}%s${NOC}\n" "No SOPS package available" |
| 59 | + exit 1 |
| 60 | + fi |
76 | 61 | fi |
77 | 62 |
|
78 | | -### git diff config |
79 | | -if [ -x "$(command -v git --version)" ]; |
80 | | -then |
81 | | - git config --global diff.sopsdiffer.textconv "sops -d" |
82 | | -else |
83 | | - echo -e "${RED}[FAIL]${NOC} Install git command" |
84 | | - exit 1 |
| 63 | +# If git is no available, fail silent. |
| 64 | +if hash git 2>/dev/null; then |
| 65 | + git config --global diff.sopsdiffer.textconv "sops -d" |
85 | 66 | fi |
0 commit comments