generic-ci.sh 2.33 KB
Newer Older
1
#!/bin/bash
2
set -x
3
4
5

case $1 in

Christian Rebischke's avatar
Christian Rebischke committed
6
  install-packer)
7
8
9
10
11
12
    PACKER_CURRENT_VERSION="$(curl -s https://checkpoint-api.hashicorp.com/v1/check/packer | jq -r -M '.current_version')"
    PACKER_URL="https://releases.hashicorp.com/packer/$PACKER_CURRENT_VERSION/packer_${PACKER_CURRENT_VERSION}_linux_amd64.zip"
    PACKER_SHA256="https://releases.hashicorp.com/packer/$PACKER_CURRENT_VERSION/packer_${PACKER_CURRENT_VERSION}_SHA256SUMS"
    PACKER_SHA256_SIG="https://releases.hashicorp.com/packer/$PACKER_CURRENT_VERSION/packer_${PACKER_CURRENT_VERSION}_SHA256SUMS.sig"
    HASHICORP_FINGERPRINT=91a6e7f85d05c65630bef18951852d87348ffc4c
    HASHICORP_KEY="https://keybase.io/hashicorp/pgp_keys.asc?fingerprint=${HASHICORP_FINGERPRINT}"
13
14
15
16
    curl -LO "${PACKER_URL}"
    curl -LO "${PACKER_SHA256}"
    curl -LO "${PACKER_SHA256_SIG}"
    wget -Lo hashicorp.key "${HASHICORP_KEY}"
17
18
19
    gpg --with-fingerprint --with-colons hashicorp.key | grep ${HASHICORP_FINGERPRINT^^}
    gpg --import hashicorp.key
    gpg --verify "packer_${PACKER_CURRENT_VERSION}_SHA256SUMS.sig" "packer_${PACKER_CURRENT_VERSION}_SHA256SUMS"
20
    grep linux_amd64 "packer_${PACKER_CURRENT_VERSION}_SHA256SUMS" >packer_SHA256SUM_linux_amd64
21
22
    sha256sum --check --status packer_SHA256SUM_linux_amd64
    unzip "packer_${PACKER_CURRENT_VERSION}_linux_amd64.zip"
Christian Rebischke's avatar
Christian Rebischke committed
23
    ./packer --version
24
25
    ;;

Christian Rebischke's avatar
Christian Rebischke committed
26
  install-shfmt)
Ju's avatar
Ju committed
27
28
    SHFMT_VERSION="$(curl -s https://api.github.com/repos/mvdan/sh/releases/latest | jq -r -M '.tag_name')"
    curl -Lo shfmt https://github.com/mvdan/sh/releases/download/"${SHFMT_VERSION}"/shfmt_"${SHFMT_VERSION}"_linux_amd64
Christian Rebischke's avatar
Christian Rebischke committed
29
    chmod +x ./shfmt
Ju's avatar
Ju committed
30
    ./shfmt --version
Christian Rebischke's avatar
Christian Rebischke committed
31
32
33
34
35
36
37
38
39
40
41
    ;;

  install-yapf)
    pip3 install yapf --user
    ;;

  install-flake8)
    pip3 install flake8 --user
    ;;

  verify-official)
juadde's avatar
juadde committed
42
    ./packer validate -var "iso_checksum_url=https://mirror.pkgbuild.com/iso/latest/sha1sums.txt" -except=vagrant-cloud vagrant.json
43
44
    ;;

Christian Rebischke's avatar
Christian Rebischke committed
45
  verify-local)
juadde's avatar
juadde committed
46
    ./packer validate local.json
Christian Rebischke's avatar
Christian Rebischke committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    ;;

  # We use + instead of \; here because find doesn't pass
  # the exit code through when used with \;
  shellcheck)
    find . -iname "*.sh" -exec shellcheck {} +
    ;;

  shfmt)
    find . -iname "*.sh" -exec ./shfmt -i 2 -ci -d {} +
    ;;

  yapf)
    find . -iname "*.py" -exec python3 -m yapf -d {} +
    ;;

  flake8)
    find . -iname "*.py" -exec python3 -m flake8 {} +
    ;;

67
68
69
70
  *)
    exit 1
    ;;
esac