Reduce boilerplate of install scripts

main
Buddy Sandidge 4 years ago
parent 34803d74e4
commit fb74e39a2b

@ -0,0 +1,102 @@
#ft=sh
bail () {
>&2 echo "ERROR: $1"
exit 1
}
must_be_root () {
if [ "$(id --user)" != 0 ]; then
bail "must run as root"
fi
}
get_os () {
case $(uname -s) in
Linux*) echo linux;;
Darwin*) echo darwin;;
*) bail "unsupported os: $(uname -s)" ;;
esac
}
get_arch () {
case $(uname -m) in
x86_64*) echo amd64;;
amd64*) echo amd64;;
*) bail "unsupported architecture: $(uname -m)" ;;
esac
}
set_current_link () {
prefix="${1}"
version="${2}"
sudo="${3}"
current="${prefix}/current"
if [ -s "${current}" ] ; then
$sudo unlink "${current}"
fi
$sudo ln --symbolic --relative "${prefix}/${version}" "${current}"
}
extract_tarball () {
url="${1}"
dest="${2}"
args="${3}"
sudo="${4}"
if [ -d "${dest}" ]; then
return
fi
$sudo mkdir -p "${dest}"
tmp_dir="$(mktemp --directory)"
tarball=${tmp_dir}/release.tar.gz
curl --silent --location --output "${tarball}" "${url}"
# shellcheck disable=SC2086
$sudo tar xf "${tarball}" --directory "${dest}" ${args}
rm -rf "${tmp_dir}"
}
relative_path() {
# both $1 and $2 are absolute paths beginning with /
# $1 must be a canonical path; that is none of its directory
# components may be ".", ".." or a symbolic link
#
# returns relative path to $2/$target from $1/$src
src=$1
target=$2
common_part=$src
result=
while [ "${target#"$common_part"}" = "$target" ]; do
# no match, means that candidate common part is not correct
# go up one level (reduce common part)
common_part=$(dirname "$common_part")
# and record that we went back, with correct / handling
if [ -z "$result" ]; then
result=..
else
result=../$result
fi
done
if [ "$common_part" = / ]; then
# special case for root (no common path)
result=$result/
fi
# since we now have identified the common part,
# compute the non-common part
forward_part=${target#"$common_part"}
# and now stick all parts together
if [ -n "$result" ] && [ -n "$forward_part" ]; then
result=$result$forward_part
elif [ -n "$forward_part" ]; then
# extra slash removal
result=${forward_part#?}
fi
printf '%s' "$result"
}

@ -9,7 +9,7 @@ if [[ -d "${XDG_CONFIG_HOME}/zsh/env.d" ]]; then
done done
fi fi
if [ -d "${XDG_CONFIG_HOME}/zsh/zshrc.d" ]; then if [[ -d "${XDG_CONFIG_HOME}/zsh/zshrc.d" ]]; then
for file in "${XDG_CONFIG_HOME}"/zsh/zshrc.d/*.zsh(N); do for file in "${XDG_CONFIG_HOME}"/zsh/zshrc.d/*.zsh(N); do
if [ -r "$file" ]; then if [ -r "$file" ]; then
#shellcheck disable=1090 #shellcheck disable=1090

@ -1,6 +1,9 @@
if [ -d /usr/local/go/bin ] ; then __APPS_GO_PATH=/usr/local/apps/golang/current/bin
PATH="${PATH}:/usr/local/go/bin" if [ -d "${__APPS_GO_PATH}" ] && ! echo "${PATH}" | grep -q ${__APPS_GO_PATH} ; then
PATH="$__APPS_GO_PATH:${PATH}"
fi fi
if [ -d "${HOME}/go/bin" ] ; then unset __APPS_GO_PATH
if [ -d "${HOME}/go/bin" ] && ! echo "$PATH" | grep -q "${HOME}/go/bin" ; then
PATH="${PATH}:${HOME}/go/bin" PATH="${PATH}:${HOME}/go/bin"
fi fi

@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -e
# shellcheck disable=SC1090
source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh"
VERSION=${VERSION:-1.16.2}
DEST=/usr/local/apps/golang
URL=https://dl.google.com/go/go${VERSION}.$(get_os)-$(get_arch).tar.gz
DEST_BIN=$DEST/current/bin
extract_tarball "${URL}" "${DEST}/${VERSION}" "--strip-components 1" sudo
set_current_link "${DEST}" "${VERSION}" sudo
if [[ ! -f /etc/profile.d/go-path.sh ]]; then
cat <<EOF | sudo tee /etc/profile.d/go-path.sh
if [ -d "$DEST_BIN" ] && ! echo "\$PATH" | grep -q "$DEST_BIN" ; then
export PATH=$DEST_BIN:\$PATH
fi
EOF
fi

@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -e
# shellcheck disable=SC1090
source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh"
VERSION=${VERSION:-1.5.0}
DEST="${XDG_DATA_HOME}/buddy-up/apps/gomock"
URL=https://github.com/golang/mock/releases/download/v${VERSION}/mock_${VERSION}_$(get_os)_$(get_arch).tar.gz
extract_tarball "${URL}" "${DEST}/${VERSION}" "--strip-components 1"
set_current_link "${DEST}" "${VERSION}"
if [[ -L "$XDG_BIN_HOME/mockgen" ]]; then
unlink "$XDG_BIN_HOME/mockgen"
fi
cd "$XDG_BIN_HOME"
ln --symbolic \
"$(relative_path "${XDG_BIN_HOME}" "${XDG_DATA_HOME}/buddy-up/apps/gomock/current/mockgen")" \
mockgen

@ -2,63 +2,23 @@
set -e set -e
VERSION=${VERSION:-v3.4.4} # shellcheck disable=SC1090
source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh"
PREFIX_DIR=/usr/local
BIN_DIR=${PREFIX_DIR}/bin
APP=etcd APP=etcd
VERSION=${VERSION:-v3.4.15}
APP_PREFIX_DIR=${PREFIX_DIR}/${APP} APPS_DIR=/usr/local/apps/${APP}
APP_DEST_DIR=${APP_PREFIX_DIR}/${VERSION} URL=https://github.com/etcd-io/etcd/releases/download/${VERSION}/etcd-${VERSION}-$(get_os)-$(get_arch).tar
APP_CURRENT=${APP_PREFIX_DIR}/current
extract_tarball "${URL}" "${APPS_DIR}/${VERSION}" "--strip-components 1" sudo
OS= set_current_link "${APPS_DIR}" "${VERSION}" sudo
if [[ $OSTYPE =~ linux ]]; then
OS=linux apps=$(find ${APPS_DIR}/current/ -maxdepth 1 -executable -type f -exec basename {} \;)
elif [[ $OSTYPE =~ darwin ]]; then cd /usr/local/bin
OS=darwin for bin in $apps; do
else if [[ ! -s $bin ]]; then
echo unknown os: "$OSTYPE" sudo ln --symbolic \
exit 1 "$(relative_path "/usr/local/bin" "${APPS_DIR}/current/${bin}")" \
fi "${bin}"
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}
# shellcheck disable=SC2044
for bin in $(find ${APP_CURRENT}/ -maxdepth 1 -executable -type f -exec basename {} \;); do
[[ -s $bin ]] || sudo ln --symbolic "${APP_CURRENT}/$bin"
done done
if [[ $TMP_DIR != "" ]]; then
rm -rf "${TMP_DIR}"
echo removed up temp directory "${TMP_DIR}"
fi

@ -1,59 +0,0 @@
#!/usr/bin/env bash
set -e
GO_VERSION=${GO_VERSION:-1.15.2}
PREFIX_DIR=/usr/local
#BIN_DIR=${PREFIX_DIR}/bin
GO_PREFIX_DIR=${PREFIX_DIR}/golang
GO_DEST_DIR=${GO_PREFIX_DIR}/${GO_VERSION}
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
[[ -d ${GO_DEST_DIR} ]] || sudo mkdir -p "${GO_DEST_DIR}"
TMP_DIR=
if [[ ! -d ${GO_DEST_DIR}/bin ]]; then
TMP_DIR=$(mktemp --directory)
DEST_FILE=$TMP_DIR/go.tar.gz
URL=https://dl.google.com/go/go${GO_VERSION}.${OS}-${ARCH}.tar.gz
echo downloading go "$GO_VERSION" to temp directory "${TMP_DIR}"
curl --silent --output "${DEST_FILE}" "${URL}"
sudo tar xf "${DEST_FILE}" --directory "${GO_DEST_DIR}" --strip-components 1
sudo chown --recursive root:root "${GO_DEST_DIR}"
else
echo go "$GO_VERSION" already installed
fi
cd ${PREFIX_DIR}
[[ -s go ]] && sudo unlink go
sudo ln --symbolic "${GO_DEST_DIR}" go
echo current version set to "${GO_VERSION}"
[[ -f /etc/profile.d/go-path.sh ]] \
|| echo "export PATH=\$PATH:/usr/local/go/bin" \
| sudo tee /etc/profile.d/go-path.sh
if [[ $TMP_DIR != "" ]]; then
rm -rf "${TMP_DIR}"
echo removed up temp directory "${TMP_DIR}"
fi

@ -1,34 +1,30 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -x
set -e set -e
set -x
VERSION=${VERSION:-0.79.0} # shellcheck disable=SC1090
source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh"
LOCAL="${LOCAL:-${XDG_DATA_HOME:-${HOME}/.local}}"
SHARE_DIR="${LOCAL}/share/buddy-up"
DATA_DIR="${SHARE_DIR}/apps"
BIN_DIR="${BIN_DIR:-${XDG_BIN_HOME:-${LOCAL}/bin}}"
TMP_DIR= APP=hugo
if [[ ! -f "${DATA_DIR}/hugo/${VERSION}/hugo" ]] ; then VERSION=${VERSION:-0.81.0}
URL=https://github.com/gohugoio/hugo/releases/download/v${VERSION}/hugo_${VERSION}_$(uname -s)-64bit.tar.gz APPS_DIR=${XDG_DATA_HOME}/buddy-up/apps/${APP}
TMP_DIR=$(mktemp --directory)
cd "${TMP_DIR}"
curl --location --silent --output release.tar.gz "${URL}"
tar xvzf release.tar.gz
mkdir -p "${DATA_DIR}/hugo/${VERSION}"
mv ./hugo "${DATA_DIR}/hugo/${VERSION}/hugo"
fi
cd "${DATA_DIR}/hugo/" ARCH=
[[ -s current ]] && unlink current case $(get_arch) in
ln -s "${VERSION}" current amd64) ARCH=64bit
esac
URL=https://github.com/gohugoio/hugo/releases/download/v${VERSION}/hugo_${VERSION}_$(uname)-${ARCH}.tar.gz
cd "${BIN_DIR}" extract_tarball "${URL}" "${APPS_DIR}/${VERSION}"
[[ -L "hugo" ]] || ln --symbolic "${DATA_DIR}/hugo/current/hugo" hugo set_current_link "${APPS_DIR}" "${VERSION}"
if [[ "${TMP_DIR}" != "" ]]; then apps=$(find "${APPS_DIR}/current/" -maxdepth 1 -executable -type f -exec basename {} \;)
rm -rf "${TMP_DIR}" cd "${XDG_BIN_HOME}"
echo removed up temp directory "${TMP_DIR}" for bin in $apps; do
fi if [[ ! -s $bin ]]; then
ln --symbolic \
"$(relative_path "${XDG_BIN_HOME}" "${APPS_DIR}/current/${bin}")" \
"${bin}"
fi
done

@ -2,64 +2,23 @@
set -e set -e
VERSION=${VERSION:-v4.1.0} # shellcheck disable=SC1090
source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh"
PREFIX_DIR=/usr/local
BIN_DIR=${PREFIX_DIR}/bin
APP=lego APP=lego
VERSION=${VERSION:-v4.3.1}
APP_PREFIX_DIR=${PREFIX_DIR}/apps/${APP} APPS_DIR=/usr/local/apps/${APP}
APP_DEST_DIR=${APP_PREFIX_DIR}/${VERSION} URL=https://github.com/go-acme/lego/releases/download/${VERSION}/lego_${VERSION}_$(get_os)_$(get_arch).tar.gz
APP_CURRENT=${APP_PREFIX_DIR}/current
extract_tarball "${URL}" "${APPS_DIR}/${VERSION}" "" sudo
OS= set_current_link "${APPS_DIR}" "${VERSION}" sudo
if [[ $OSTYPE =~ linux ]]; then
OS=linux apps=$(find ${APPS_DIR}/current/ -maxdepth 1 -executable -type f -exec basename {} \;)
elif [[ $OSTYPE =~ darwin ]]; then cd /usr/local/bin
OS=darwin for bin in $apps; do
else if [[ ! -s $bin ]]; then
echo unknown os: "$OSTYPE" sudo ln --symbolic \
exit 1 "$(relative_path "/usr/local/bin" "${APPS_DIR}/current/${bin}")" \
fi "${bin}"
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/go-acme/lego/releases/download/${VERSION}/lego_${VERSION}_${OS}_${ARCH}.tar.gz
[[ -d ${APP_DEST_DIR} ]] || sudo mkdir -p "${APP_DEST_DIR}"
TMP_DIR=
if [[ ! -f ${APP_DEST_DIR}/lego ]]; 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}"
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}
# shellcheck disable=SC2044
for bin in $(find ${APP_CURRENT}/ -maxdepth 1 -executable -type f -exec basename {} \;); do
[[ -s $bin ]] || sudo ln --symbolic "${APP_CURRENT}/$bin"
done done
if [[ $TMP_DIR != "" ]]; then
rm -rf "${TMP_DIR}"
echo removed up temp directory "${TMP_DIR}"
fi

@ -2,56 +2,27 @@
set -e set -e
MINIKUBE_VERSION=${MINIKUBE_VERSION:-v1.9.2} # shellcheck disable=SC1090
source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh"
PREFIX_DIR=/usr/local
BIN_DIR=${PREFIX_DIR}/bin APP=minikube
VERSION=${VERSION:-v1.18.1}
MINIKUBE_PREFIX_DIR=${PREFIX_DIR}/apps/minikube APPS_DIR=/usr/local/apps/${APP}
MINIKUBE_DEST_DIR=${MINIKUBE_PREFIX_DIR}/${MINIKUBE_VERSION} URL=https://github.com/kubernetes/minikube/releases/download/${VERSION}/minikube-$(get_os)-$(get_arch).tar.gz
MINIKUBE_CURRENT=${MINIKUBE_PREFIX_DIR}/current
extract_tarball "${URL}" "${APPS_DIR}/${VERSION}" "--strip-components 1" sudo
if [[ $(uname) =~ Linux ]]; then sudo chown --recursive root:root "${APPS_DIR}/${VERSION}"
OS=linux set_current_link "${APPS_DIR}" "${VERSION}" sudo
elif [[ $(uname) =~ Darwin ]]; then
OS=darwin cd /usr/local/bin
else if [[ ! -L minikube ]]; then
echo "unsupported os: $(uname)" sudo ln --symbolic \
exit 1 "$(relative_path "/usr/local/bin" "${APPS_DIR}/current/minikube-linux-amd64")" \
fi minikube
ARCH=
if [[ $(uname -m) == x86_64 ]]; then
ARCH=amd64
else
echo arch not yet supported: "$(uname -m)"
exit 1
fi fi
TMP_DIR= if [[ ! -L docker-machine-driver-kvm2 ]]; then
if [[ ! -d ${MINIKUBE_DEST_DIR} ]]; then sudo ln --symbolic \
sudo mkdir -p "${MINIKUBE_DEST_DIR}" "$(relative_path "/usr/local/bin" "${APPS_DIR}/current/docker-machine-driver-kvm2")" \
TMP_DIR=$(mktemp --directory) docker-machine-driver-kvm2
DEST_FILE="${TMP_DIR}"/minikube
URL="https://github.com/kubernetes/minikube/releases/download/${MINIKUBE_VERSION}/minikube-${OS}-${ARCH}"
echo downloading minikube "${MINIKUBE_VERSION}" to temp directory "${TMP_DIR}"
curl --silent --location --output "${DEST_FILE}" "${URL}"
sudo chmod 755 "${DEST_FILE}"
sudo mv "${DEST_FILE}" "${MINIKUBE_DEST_DIR}"
sudo chown --recursive root:root "${MINIKUBE_DEST_DIR}"
else
echo minikube "${MINIKUBE_VERSION}" already installed
fi
cd "${MINIKUBE_PREFIX_DIR}"
[[ -s current ]] && sudo unlink current
sudo ln --symbolic "${MINIKUBE_VERSION}"/ current
echo current version set to "${MINIKUBE_VERSION}"
cd ${BIN_DIR}
[[ -L ${BIN_DIR}/minikube ]] || sudo ln --symbolic ${MINIKUBE_CURRENT}/minikube
if [[ $TMP_DIR != "" ]]; then
rm -rf "${TMP_DIR}"
echo removed up temp directory "${TMP_DIR}"
fi fi

@ -3,12 +3,19 @@
set -x set -x
set -e set -e
PROTOC_VERSION=${PROTOC_VERSION:-3.7.1} # shellcheck disable=SC1090
source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh"
PROTOC_VERSION=${PROTOC_VERSION:-3.15.6}
PROTOC_ZIP=protoc-$PROTOC_VERSION-linux-x86_64.zip PROTOC_ZIP=protoc-$PROTOC_VERSION-linux-x86_64.zip
TMP_DIR=$(mktemp --directory) TMP_DIR=$(mktemp --directory)
DEST_FILE=$TMP_DIR/$PROTOC_ZIP DEST_FILE=$TMP_DIR/$PROTOC_ZIP
URL=https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/$PROTOC_ZIP URL=https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/$PROTOC_ZIP
curl --output "$DEST_FILE" --location "$URL" curl --output "$DEST_FILE" --location "$URL"
sudo unzip -o "$DEST_FILE" -d /usr/local bin/protoc sudo unzip -o "$DEST_FILE" -d /usr/local bin/protoc
sudo chmod 755 /usr/local/bin/protoc
sudo unzip -o "$DEST_FILE" -d /usr/local 'include/*' sudo unzip -o "$DEST_FILE" -d /usr/local 'include/*'
sudo find /usr/local/include/google -type f -exec chmod 644 {} \;
sudo find /usr/local/include/google -type d -exec chmod 755 {} \;
rm -rfv "$TMP_DIR" rm -rfv "$TMP_DIR"
Loading…
Cancel
Save