From 5fb4390fadf19ad61cc6e24695e8f8f68bb3635c Mon Sep 17 00:00:00 2001 From: Franz Luther Neulist Carroll Date: Wed, 11 Sep 2024 18:37:29 +1000 Subject: [PATCH] Add formatting and CI --- .github/workflows/lint.yaml | 7 +++++++ scripts/format-all | 6 ++++++ scripts/format-shell-scripts | 5 +++++ scripts/format-terraform | 5 +++++ scripts/lint-all | 6 ++++++ scripts/lint-shell-scripts | 7 +++++++ scripts/lint-terraform | 5 +++++ terraform/setup.bash | 38 +++++++++++++++++------------------- 8 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/lint.yaml create mode 100755 scripts/format-all create mode 100755 scripts/format-shell-scripts create mode 100755 scripts/format-terraform create mode 100755 scripts/lint-all create mode 100755 scripts/lint-shell-scripts create mode 100755 scripts/lint-terraform diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..e7d079f --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,7 @@ +name: Lint +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: ./scripts/lint-all diff --git a/scripts/format-all b/scripts/format-all new file mode 100755 index 0000000..05bdb4a --- /dev/null +++ b/scripts/format-all @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +./scripts/format-terraform +./scripts/format-shell-scripts diff --git a/scripts/format-shell-scripts b/scripts/format-shell-scripts new file mode 100755 index 0000000..7d2a33e --- /dev/null +++ b/scripts/format-shell-scripts @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +shfmt --write . diff --git a/scripts/format-terraform b/scripts/format-terraform new file mode 100755 index 0000000..d128771 --- /dev/null +++ b/scripts/format-terraform @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +terraform fmt -recursive diff --git a/scripts/lint-all b/scripts/lint-all new file mode 100755 index 0000000..21b5f46 --- /dev/null +++ b/scripts/lint-all @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +./scripts/lint-terraform +./scripts/lint-shell-scripts diff --git a/scripts/lint-shell-scripts b/scripts/lint-shell-scripts new file mode 100755 index 0000000..1d506ed --- /dev/null +++ b/scripts/lint-shell-scripts @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +shellcheck --exclude=SC1091 terraform/setup.bash +find scripts -type f -exec shellcheck --exclude=SC1091 {} \; +shfmt --diff . diff --git a/scripts/lint-terraform b/scripts/lint-terraform new file mode 100755 index 0000000..c2191d5 --- /dev/null +++ b/scripts/lint-terraform @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +terraform fmt -recursive -check diff --git a/terraform/setup.bash b/terraform/setup.bash index c921262..bde4d8b 100644 --- a/terraform/setup.bash +++ b/terraform/setup.bash @@ -15,9 +15,9 @@ curl \ --silent \ --show-error \ --location \ - https://tailscale.com/install.sh \ - | sh -cat < /etc/sysctl.d/99-tailscale.conf + https://tailscale.com/install.sh | + sh +cat </etc/sysctl.d/99-tailscale.conf net.ipv4.ip_forward = 1 net.ipv6.conf.all.forwarding = 1 EOF @@ -32,30 +32,28 @@ tailscale serve --bg 8082 echo "--> Mount storage volume" # shellcheck disable=SC2154 -storage_name=$( \ +storage_name=$( lsblk \ - --output name,size \ - | grep "${storage_volume_size}G" \ - | awk '{ print $1 }' \ + --output name,size | + grep "${storage_volume_size}G" | + awk '{ print $1 }' ) # shellcheck disable=SC2154 -storage_uuid=$( \ +storage_uuid=$( lsblk \ - --output name,size,UUID \ - | grep "${storage_volume_size}G" \ - | awk '{ print $3 }' \ + --output name,size,UUID | + grep "${storage_volume_size}G" | + awk '{ print $3 }' ) -if ! \ - file \ +if ! file \ --special-files \ --dereference \ - "/dev/$storage_name" \ - | grep --silent ext4; \ -then + "/dev/$storage_name" | + grep --silent ext4; then mkfs.ext4 "/dev/$storage_name" fi mkdir /storage -echo "UUID=$storage_uuid /storage ext4 defaults,nofail 0 2" >> /etc/fstab +echo "UUID=$storage_uuid /storage ext4 defaults,nofail 0 2" >>/etc/fstab systemctl daemon-reload mount "/dev/$storage_name" /storage mount --all @@ -70,9 +68,9 @@ curl \ --show-error \ --location \ https://github.com/containers/common/raw/main/pkg/seccomp/seccomp.json \ - > /etc/containers/seccomp.json + >/etc/containers/seccomp.json mkdir --parents /home/ubuntu/.config/containers/ -cat < /home/ubuntu/.config/containers/storage.conf +cat </home/ubuntu/.config/containers/storage.conf [storage] driver = "overlay" runroot = "/run/user/1000/containers" @@ -92,7 +90,7 @@ systemctl --machine=ubuntu@ --user --now enable podman.socket echo "--> Install and start traccar systemd unit" mkdir --parents /home/ubuntu/.config/containers/systemd -cat < /home/ubuntu/.config/containers/systemd/traccar.kube +cat </home/ubuntu/.config/containers/systemd/traccar.kube [Install] WantedBy=default.target