Skip to content

Instantly share code, notes, and snippets.

@arturmartins
Created October 8, 2023 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arturmartins/0204a56be566e811b9252641848db37b to your computer and use it in GitHub Desktop.
Save arturmartins/0204a56be566e811b9252641848db37b to your computer and use it in GitHub Desktop.
Script to download and install etcd for linux amd64
#!/bin/bash
# Utility to download latest etcd version for linux
SYSTEM_VERSION="linux-amd64"
fail(){
echo "[${0##*/}]: FATAL: ${@}"
exit 1
}
# Change to the /tmp directory
cd /tmp || fail "Failed to change directory to /tmp."
# Fetch the latest etcd release
RELEASE=$(curl -s https://api.github.com/repos/etcd-io/etcd/releases/latest \
| jq -r '.tag_name')
if [ -z "${RELEASE}" ]; then
fail "Failed to fetch the latest etcd release."
fi
# Download the tarball
TARBALL="etcd-${RELEASE}-linux-amd64.tar.gz"
DOWNLOAD_URL="https://github.com/etcd-io/etcd/releases/download/${RELEASE}/${TARBALL}"
wget "${DOWNLOAD_URL}" || fail "Failed to download ${TARBALL}."
# Extract the tarball
tar xvf "${TARBALL}" || fail "Failed to extract $TARBALL."
# Move the binaries
cd "etcd-${RELEASE}-${SYSTEM_VERSION}" || fail "Failed to change directory to etcd-${RELEASE}-${SYSTEM_VERSION}."
mv etcd etcdctl /usr/local/bin/ || fail "Failed to move etcd binaries."
# Cleanup
cd /tmp
rm -rf "etcd-${RELEASE}-${SYSTEM_VERSION}" || fail "Failed to delete directory to etcd-${RELEASE}-${SYSTEM_VERSION}."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment