Add install etcd script
parent
2793b10a6b
commit
4b1845fa42
@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
set -x
|
||||
|
||||
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
|
||||
echo unknown os: $OSTYPE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ARCH=
|
||||
if [[ $(uname -m) == x86_64 ]]; then
|
||||
ARCH=amd64
|
||||
else
|
||||
echo arch not yet supported: $(uname -m)
|
||||
exit 1
|
||||
fi
|
||||
URL=https://github.com/etcd-io/etcd/releases/download/${VERSION}/etcd-${VERSION}-${OS}-${ARCH}.tar.gz
|
||||
|
||||
[[ -d ${APP_DEST_DIR} ]] || sudo mkdir -p ${APP_DEST_DIR}
|
||||
|
||||
TMP_DIR=
|
||||
if [[ ! -d ${APP_DEST_DIR}/bin ]]; then
|
||||
TMP_DIR=$(mktemp --directory)
|
||||
DEST_FILE=$TMP_DIR/${APP}.tar.gz
|
||||
echo downloading ${APP} ${VERSION} to temp directory ${TMP_DIR}
|
||||
curl --silent --location --output ${DEST_FILE} ${URL}
|
||||
|
||||
sudo tar xf ${DEST_FILE} --directory ${APP_DEST_DIR} --strip-components 1
|
||||
sudo chown --recursive root:root ${APP_DEST_DIR}
|
||||
else
|
||||
echo ${APP} ${VERSION} already installed
|
||||
fi
|
||||
|
||||
cd ${APP_PREFIX_DIR}
|
||||
[[ -s current ]] && sudo unlink current
|
||||
sudo ln --symbolic ${APP_DEST_DIR} current
|
||||
echo current version set to ${VERSION}
|
||||
|
||||
cd ${BIN_DIR}
|
||||
for bin in $(find ${APP_CURRENT}/ -maxdepth 1 -executable -type f -exec basename {} \;); do
|
||||
[[ -s $bin ]] || sudo ln --symbolic ${APP_CURRENT}/$bin
|
||||
done
|
||||
|
||||
if [[ $TMP_DIR != "" ]]; then
|
||||
rm -rf ${TMP_DIR}
|
||||
echo removed up temp directory ${TMP_DIR}
|
||||
fi
|
Loading…
Reference in New Issue