diff --git a/Makefile b/Makefile index 8cde5b640c7..625a28baac0 100644 --- a/Makefile +++ b/Makefile @@ -392,6 +392,9 @@ tools: echo $$(date): Installing dependencies ./bootstrap.sh +clean_tools: + ./tools/remove_dependencies.sh + minimaltools: echo $$(date): Installing minimal dependencies BUILD_JAVA=0 BUILD_CONSUL=0 ./bootstrap.sh diff --git a/bootstrap.sh b/bootstrap.sh index f95302ea771..d3a4943ad38 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -224,27 +224,25 @@ install_toxiproxy() { install_all() { echo "##local system details..." - echo "##platform: $(uname) target:$(get_arch) OS: $os" + echo "##platform: $(uname) target:$(get_arch) OS: $OSTYPE" # protoc - protoc_ver=21.3 - install_dep "protoc" "$protoc_ver" "$VTROOT/dist/vt-protoc-$protoc_ver" install_protoc + install_dep "protoc" "$PROTOC_VER" "$VTROOT/dist/vt-protoc-$PROTOC_VER" install_protoc # zk - zk_ver=${ZK_VERSION:-3.8.0} if [ "$BUILD_JAVA" == 1 ] ; then - install_dep "Zookeeper" "$zk_ver" "$VTROOT/dist/vt-zookeeper-$zk_ver" install_zookeeper + install_dep "Zookeeper" "$ZK_VER" "$VTROOT/dist/vt-zookeeper-$ZK_VER" install_zookeeper fi # etcd - install_dep "etcd" "v3.5.6" "$VTROOT/dist/etcd" install_etcd + install_dep "etcd" "$ETCD_VER" "$VTROOT/dist/etcd" install_etcd # consul if [ "$BUILD_CONSUL" == 1 ] ; then - install_dep "Consul" "1.11.4" "$VTROOT/dist/consul" install_consul + install_dep "Consul" "$CONSUL_VER" "$VTROOT/dist/consul" install_consul fi # toxiproxy - install_dep "toxiproxy" "v2.5.0" "$VTROOT/dist/toxiproxy" install_toxiproxy + install_dep "toxiproxy" "$TOXIPROXY_VER" "$VTROOT/dist/toxiproxy" install_toxiproxy echo echo "bootstrap finished - run 'make build' to compile" diff --git a/build.env b/build.env index b9e44331e65..5986ee247b0 100755 --- a/build.env +++ b/build.env @@ -1,13 +1,13 @@ # No shebang line as this script is sourced from an external shell. # Copyright 2019 The Vitess Authors. -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,6 +27,11 @@ mkdir -p vthook export VTROOT="$PWD" export VTDATAROOT="${VTDATAROOT:-${VTROOT}/vtdataroot}" export PATH="$PWD/bin:$PATH" +export PROTOC_VER=21.3 +export ZK_VER=${ZK_VERSION:-3.8.0} +export ETCD_VER=v3.5.6 +export CONSUL_VER=1.11.4 +export TOXIPROXY_VER=v2.5.0 mkdir -p "$VTDATAROOT" diff --git a/tools/remove_dependencies.sh b/tools/remove_dependencies.sh new file mode 100755 index 00000000000..62bf7785ba3 --- /dev/null +++ b/tools/remove_dependencies.sh @@ -0,0 +1,152 @@ +#!/bin/bash + +# Copyright 2023 The Vitess Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Remove tools and dependencies installed by "make tools" + +set -euo pipefail + +source build.env + +function fail() { + echo "ERROR: ${1}" + exit 1 +} + +BUILD_JAVA=${BUILD_JAVA:-1} +BUILD_CONSUL=${BUILD_CONSUL:-1} +UNAME=$(uname) +ARCH=$(uname -m) + +uninstall_protoc() { + echo "Removing protoc..." + local dist="$1" + + if [ -f "$dist/bin/protoc" ]; then + unlink "$dist/bin/protoc" + rm -f "$VTROOT/bin/protoc" + fi + if [[ "${dist##*/}" == "vt-protoc-$PROTOC_VER" ]]; then + rm -rf "$dist" + fi +} + +uninstall_zookeeper() { + echo "Removing zookeeper..." + local dist="$1" + + if [[ "${dist##*/}" == "vt-zookeeper-$ZK_VER" ]]; then + rm -rf "$dist" + fi +} + +uninstall_etcd() { + echo "Removing etcd..." + local version="$1" + local dist="$2" + + case $UNAME in + Linux) local platform=linux;; + Darwin) local platform=darwin;; + *) echo "Etcd not installed. Ignoring..."; return;; + esac + + case $ARCH in + aarch64) local target=arm64;; + x86_64) local target=amd64;; + arm64) local target=arm64;; + *) echo "Etcd not installed. Ignoring..."; return;; + esac + + if [ -f "$dist/etcd-${version}-${platform}-${target}/etcd" ]; then + unlink "$dist/etcd-${version}-${platform}-${target}/etcd" + rm -f "$VTROOT/bin/etcd" + fi + if [ -f "$dist/etcd-${version}-${platform}-${target}/etcdctl" ]; then + unlink "$dist/etcd-${version}-${platform}-${target}/etcdctl" + rm -f "$VTROOT/bin/etcdctl" + fi + + if [[ "${dist##*/}" == "etcd" ]]; then + rm -rf "$dist" + fi +} + +uninstall_consul() { + echo "Removing consul..." + local dist="$1" + + if [ -f "$dist/consul" ]; then + unlink "$dist/consul" + rm -f "$VTROOT/bin/consul" + fi + if [[ "${dist##*/}" == "consul" ]]; then + rm -rf "$dist" + fi +} + +uninstall_toxiproxy() { + echo "Removing toxiproxy..." + local dist="$1" + + case $UNAME in + Linux) local platform=linux;; + Darwin) local platform=darwin;; + *) echo "Toxiproxy not installed. Ignoring..."; return;; + esac + + case $ARCH in + aarch64) local target=arm64;; + x86_64) local target=amd64;; + arm64) local target=arm64;; + *) echo "Toxiproxy not installed. Ignoring..."; return;; + esac + + file="toxiproxy-server-${platform}-${target}" + + if [ -f "$dist/$file" ]; then + unlink "$dist/$file" + rm -f "$VTROOT/bin/toxiproxy-server" + fi + if [[ "${dist##*/}" == "toxiproxy" ]]; then + rm -rf "$dist" + fi +} + +uninstall_all() { + echo "## local system details..." + echo "## platform: $UNAME target:$ARCH OS: $OSTYPE" + + # protoc + uninstall_protoc "$VTROOT/dist/vt-protoc-$PROTOC_VER" + + # zk + if [ "$BUILD_JAVA" == 1 ] ; then + uninstall_zookeeper "$VTROOT/dist/vt-zookeeper-$ZK_VER" + fi + + # etcd + uninstall_etcd "$ETCD_VER" "$VTROOT/dist/etcd" + + # consul + if [ "$BUILD_CONSUL" == 1 ] ; then + uninstall_consul "$VTROOT/dist/consul" + fi + + # toxiproxy + uninstall_toxiproxy "$VTROOT/dist/toxiproxy" +} + +uninstall_all