From eb2793ad573da48c79f062c42c16ab5addeabda3 Mon Sep 17 00:00:00 2001 From: Kyle Quest Date: Sat, 15 Jul 2023 16:32:37 -0700 Subject: [PATCH] enhanced scripts/install-slim.sh to accept optional release version, added scripts/uninstall-slim.sh for quick uninstalls Signed-off-by: Kyle Quest --- scripts/install-slim.sh | 12 +++++++++--- scripts/uninstall-slim.sh | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100755 scripts/uninstall-slim.sh diff --git a/scripts/install-slim.sh b/scripts/install-slim.sh index 7b7a9596d9..7273d7a31f 100755 --- a/scripts/install-slim.sh +++ b/scripts/install-slim.sh @@ -10,9 +10,13 @@ function get_slim() { local URL="" local VER="" - # Get the current released tag_name - VER=$(curl -sL https://api.github.com/repos/docker-slim/docker-slim/releases \ + if [ -n "$1" ]; then + VER=$1 + else + # Get the current released tag_name + VER=$(curl -sL https://api.github.com/repos/slimtoolkit/slim/releases \ | grep tag_name | head -n1 | cut -d'"' -f4) + fi if [ -n "${VER}" ]; then URL="https://downloads.dockerslim.com/releases/${VER}" @@ -96,4 +100,6 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi -get_slim +get_slim $1 + +# You can pass a specific version to install otherwise the latest version will be installed diff --git a/scripts/uninstall-slim.sh b/scripts/uninstall-slim.sh new file mode 100755 index 0000000000..6803c6ebb6 --- /dev/null +++ b/scripts/uninstall-slim.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +function uninstall_slim() { + local VER="" + + # /usr/local/bin should be present on Linux and macOS hosts. Just be sure. + if [ -d /usr/local/bin ]; then + VER=$(slim --version | cut -d'|' -f3) + echo " - Uninstalling version - ${VER}" + + echo " - Removing slim slim binaries from /usr/local/bin" + rm /usr/local/bin/slim + rm /usr/local/bin/slim-sensor + + echo " - Removing local state directory" + rm -rfv /tmp/slim-state + + echo " - Removing state volume" + docker volume rm slim-state + + echo " - Removing sensor volume" + docker volume rm slim-sensor.${VER} + else + echo "ERROR! /usr/local/bin is not present. Uninstall aborted." + exit 1 + fi +} + +echo "Slim scripted uninstall" + +if [ "$(id -u)" -ne 0 ]; then + echo "ERROR! You must run this script as root." + exit 1 +fi + +uninstall_slim