Skip to content

Commit

Permalink
Improve install script of terraform-backend-git feature
Browse files Browse the repository at this point in the history
  • Loading branch information
schroedan committed Jan 31, 2025
1 parent 12dc1b6 commit fa7aa5c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/terraform-backend-git/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "terraform-backend-git",
"version": "1.1.0",
"version": "1.1.1",
"name": "Terraform State management using Git",
"documentationURL": "https://github.com/skriptfabrik/devcontainer-features/tree/main/src/terraform-backend-git",
"description": "Installs terraform-backend-git binary.",
Expand Down
36 changes: 12 additions & 24 deletions src/terraform-backend-git/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,28 @@

set -e

ADJUSTED_VERSION="${VERSION:-"latest"}"

# Debian / Ubuntu packages
install_debian_packages() {
# Install prerequisites
apt-get -y update
apt-get -y install --no-install-recommends curl ca-certificates

# Clean up
apt-get -y clean
rm -rf /var/lib/apt/lists/*
}
CLI_VERSION="${VERSION:-"latest"}"

# Bring in ID, ID_LIKE, VERSION_ID, VERSION_CODENAME
. /etc/os-release

# Get an adjusted ID independent of distro variants
if [ "${ID}" = "debian" ] || [ "${ID_LIKE}" = "debian" ]; then
ADJUSTED_ID="debian"
else
if [ "${ID}" != "debian" ] && [ "${ID_LIKE}" != "debian" ]; then
echo "Linux distro ${ID} not supported."
exit 1
fi

# Install packages for appropriate OS
case "${ADJUSTED_ID}" in
"debian")
install_debian_packages
;;
esac
# Install prerequisites
apt-get -y update
apt-get -y install --no-install-recommends curl ca-certificates jq

# Clean up
apt-get -y clean
rm -rf /var/lib/apt/lists/*

# Fetch latest version if needed
if [ "${ADJUSTED_VERSION}" = "latest" ]; then
ADJUSTED_VERSION=$(curl -s https://api.github.com/repos/plumber-cd/terraform-backend-git/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4)}')
if [ "${CLI_VERSION}" = "latest" ]; then
CLI_VERSION=$(curl -s https://api.github.com/repos/plumber-cd/terraform-backend-git/releases/latest | jq -r '.tag_name' | awk '{print substr($1, 2)}')
fi

# Detect current machine architecture
Expand All @@ -46,7 +34,7 @@ else
fi

# Download URL
DOWNLOAD_URL="https://github.com/plumber-cd/terraform-backend-git/releases/download/v${ADJUSTED_VERSION}/terraform-backend-git-linux-${ARCH}"
DOWNLOAD_URL="https://github.com/plumber-cd/terraform-backend-git/releases/download/v${CLI_VERSION}/terraform-backend-git-linux-${ARCH}"

# Download and install terraform-backend-git
echo "Downloading terraform-backend-git from ${DOWNLOAD_URL}"
Expand Down

0 comments on commit fa7aa5c

Please sign in to comment.