Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tools: Remove dependencies installed by make tools #14309

Merged
merged 13 commits into from
Oct 26, 2023
144 changes: 144 additions & 0 deletions tools/remove_dependencies.sh
FirePing32 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#!/bin/bash

FirePing32 marked this conversation as resolved.
Show resolved Hide resolved
# Copyright 2019 The Vitess Authors.
FirePing32 marked this conversation as resolved.
Show resolved Hide resolved
#
# 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"

get_arch() {
uname -m
}
FirePing32 marked this conversation as resolved.
Show resolved Hide resolved

function fail() {
echo "ERROR: ${1}"
exit 1
}

FirePing32 marked this conversation as resolved.
Show resolved Hide resolved
BUILD_JAVA=${BUILD_JAVA:-1}
BUILD_CONSUL=${BUILD_CONSUL:-1}
VTROOT="$PWD/../"
FirePing32 marked this conversation as resolved.
Show resolved Hide resolved

[[ "$(dirname "$0")" = "." ]] || fail "remove_dependencies.sh must be run from its current directory"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it's here because of assumption in line 30? We don't need to make that assumption IMO. We could instead pushd ${VTROOT} and then popd at the end to put the user back where they started.

IMO it's also worth doing some basic checks if we do set VTROOT by looking for some expected dir contents (e.g. the tools subdir). We're removing a lot of files, so IMO it's worth being extra safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that line is no longer needed as from now onwards this file will be invocated by Makefile


uninstall_protoc() {
echo "Removing protoc..."
local dist="$1"

if [ -f $dist ]; then
unlink "$dist/bin/protoc"
rm "$VTROOT/bin/protoc"
fi
rm -rf $dist
FirePing32 marked this conversation as resolved.
Show resolved Hide resolved
}
FirePing32 marked this conversation as resolved.
Show resolved Hide resolved

uninstall_zookeeper() {
echo "Removing zookeeper..."
local dist="$1"

rm -rf $dist
FirePing32 marked this conversation as resolved.
Show resolved Hide resolved
}

uninstall_etcd() {
echo "Removing etcd..."
local version="$1"
local dist="$2"

case $(uname) in
Linux) local platform=linux; local ext=tar.gz;;
Darwin) local platform=darwin; local ext=zip;;
*) echo "ERROR: unsupported platform for etcd"; exit 1;;
FirePing32 marked this conversation as resolved.
Show resolved Hide resolved
esac

case $(get_arch) in
aarch64) local target=arm64;;
x86_64) local target=amd64;;
arm64) local target=arm64;;
*) echo "ERROR: unsupported architecture for etcd"; exit 1;;
esac

if [ -f "$dist/etcd-${version}-${platform}-${target}/etcd" ]; then
unlink "$dist/etcd-${version}-${platform}-${target}/etcd"
mattlord marked this conversation as resolved.
Show resolved Hide resolved
rm "$VTROOT/bin/etcd"
fi
if [ -f "$dist/etcd-${version}-${platform}-${target}/etcdctl" ]; then
unlink "$dist/etcd-${version}-${platform}-${target}/etcdctl"
rm "$VTROOT/bin/etcdctl"
fi
rm -rf $dist
}

uninstall_consul() {
echo "Removing consul..."
local dist="$1"

if [ -f "$dist/consul" ]; then
unlink "$dist/consul"
rm "$VTROOT/bin/consul"
fi
rm -rf $dist
}

uninstall_toxiproxy() {
echo "Removing toxiproxy..."
local dist="$1"

case $(uname) in
Linux) local platform=linux;;
Darwin) local platform=darwin;;
*) echo "WARNING: unsupported platform. Some tests that rely on toxiproxy will not function."; return;;
FirePing32 marked this conversation as resolved.
Show resolved Hide resolved
esac

case $(get_arch) in
aarch64) local target=arm64;;
x86_64) local target=amd64;;
arm64) local target=arm64;;
*) echo "WARNING: unsupported architecture. Some tests that rely on toxiproxy will not function."; return;;
esac

file="toxiproxy-server-${platform}-${target}"

if [ -f "$dist/$file" ]; then
unlink "$dist/$file"
rm "$VTROOT/bin/toxiproxy-server"
fi
rm -rf $dist
}

uninstall_all() {
echo "## local system details..."
echo "## platform: $(uname) target:$(get_arch) OS: $os"

# protoc
protoc_ver=21.3
uninstall_protoc "$VTROOT/dist/vt-protoc-$protoc_ver"

# zk
zk_ver=${ZK_VERSION:-3.8.0}
if [ "$BUILD_JAVA" == 1 ] ; then
uninstall_zookeeper "$VTROOT/dist/vt-zookeeper-$zk_ver"
fi

# etcd
uninstall_etcd "v3.5.6" "$VTROOT/dist/etcd"
FirePing32 marked this conversation as resolved.
Show resolved Hide resolved

# consul
if [ "$BUILD_CONSUL" == 1 ] ; then
uninstall_consul "$VTROOT/dist/consul"
fi

# toxiproxy
uninstall_toxiproxy "$VTROOT/dist/toxiproxy"
}

uninstall_all
Loading