Created
October 8, 2023 22:01
-
-
Save arturmartins/0204a56be566e811b9252641848db37b to your computer and use it in GitHub Desktop.
Script to download and install etcd for linux amd64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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