You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
Plaintext
65 lines
1.5 KiB
Plaintext
5 years ago
|
#!/usr/bin/env bash
|
||
|
|
||
|
set -e
|
||
|
|
||
|
VERSION=${VERSION:-v3.4.4}
|
||
|
|
||
|
PREFIX_DIR=/usr/local
|
||
|
BIN_DIR=${PREFIX_DIR}/bin
|
||
|
|
||
|
APP=etcd
|
||
|
|
||
|
APP_PREFIX_DIR=${PREFIX_DIR}/${APP}
|
||
|
APP_DEST_DIR=${APP_PREFIX_DIR}/${VERSION}
|
||
|
APP_CURRENT=${APP_PREFIX_DIR}/current
|
||
|
|
||
|
OS=
|
||
|
if [[ $OSTYPE =~ linux ]]; then
|
||
|
OS=linux
|
||
|
elif [[ $OSTYPE =~ darwin ]]; then
|
||
|
OS=darwin
|
||
|
else
|
||
4 years ago
|
echo unknown os: "$OSTYPE"
|
||
5 years ago
|
exit 1
|
||
|
fi
|
||
|
|
||
|
ARCH=
|
||
|
if [[ $(uname -m) == x86_64 ]]; then
|
||
|
ARCH=amd64
|
||
|
else
|
||
4 years ago
|
echo arch not yet supported: "$(uname -m)"
|
||
5 years ago
|
exit 1
|
||
|
fi
|
||
|
URL=https://github.com/etcd-io/etcd/releases/download/${VERSION}/etcd-${VERSION}-${OS}-${ARCH}.tar.gz
|
||
|
|
||
4 years ago
|
[[ -d ${APP_DEST_DIR} ]] || sudo mkdir -p "${APP_DEST_DIR}"
|
||
5 years ago
|
|
||
|
TMP_DIR=
|
||
|
if [[ ! -d ${APP_DEST_DIR}/bin ]]; then
|
||
|
TMP_DIR=$(mktemp --directory)
|
||
|
DEST_FILE=$TMP_DIR/${APP}.tar.gz
|
||
4 years ago
|
echo downloading "${APP}" "${VERSION}" to temp directory "${TMP_DIR}"
|
||
|
curl --silent --location --output "${DEST_FILE}" "${URL}"
|
||
5 years ago
|
|
||
4 years ago
|
sudo tar xf "${DEST_FILE}" --directory "${APP_DEST_DIR}" --strip-components 1
|
||
|
sudo chown --recursive root:root "${APP_DEST_DIR}"
|
||
5 years ago
|
else
|
||
4 years ago
|
echo "${APP}" "${VERSION}" already installed
|
||
5 years ago
|
fi
|
||
|
|
||
|
cd ${APP_PREFIX_DIR}
|
||
|
[[ -s current ]] && sudo unlink current
|
||
4 years ago
|
sudo ln --symbolic "${APP_DEST_DIR}" current
|
||
|
echo current version set to "${VERSION}"
|
||
5 years ago
|
|
||
|
cd ${BIN_DIR}
|
||
4 years ago
|
# shellcheck disable=SC2044
|
||
5 years ago
|
for bin in $(find ${APP_CURRENT}/ -maxdepth 1 -executable -type f -exec basename {} \;); do
|
||
4 years ago
|
[[ -s $bin ]] || sudo ln --symbolic "${APP_CURRENT}/$bin"
|
||
5 years ago
|
done
|
||
|
|
||
|
if [[ $TMP_DIR != "" ]]; then
|
||
4 years ago
|
rm -rf "${TMP_DIR}"
|
||
|
echo removed up temp directory "${TMP_DIR}"
|
||
5 years ago
|
fi
|