diff --git a/Cargo.lock b/Cargo.lock index 08951d7..de31238 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -731,7 +731,7 @@ checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" [[package]] name = "openapi-aggregator" -version = "0.1.0" +version = "0.2.0" dependencies = [ "clap", "mockito", diff --git a/README.md b/README.md index 40e7b39..70e103e 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,12 @@ VERSION=v0.1.0 curl -sSfL https://raw.githubusercontent.com/OWNER/openapi-aggreg INSTALL_DIR=~/.local/bin curl -sSfL https://raw.githubusercontent.com/OWNER/openapi-aggregator/main/install.sh | sh ``` +Uninstall: + +```sh +curl -sSfL https://raw.githubusercontent.com/OWNER/openapi-aggregator/main/install.sh | sh -s -- --uninstall +``` + ### From source ```sh diff --git a/install.sh b/install.sh index 42f2c0b..c424d30 100755 --- a/install.sh +++ b/install.sh @@ -1,9 +1,11 @@ #!/bin/sh -# Install script for openapi-aggregator -# Usage: curl -sSfL https://raw.githubusercontent.com/OWNER/openapi-aggregator/main/install.sh | sh +# Install/uninstall script for openapi-aggregator +# Usage: +# Install: curl -sSfL https://raw.githubusercontent.com/OWNER/openapi-aggregator/main/install.sh | sh +# Uninstall: curl -sSfL https://raw.githubusercontent.com/OWNER/openapi-aggregator/main/install.sh | sh -s -- --uninstall # # Options (via environment variables): -# VERSION - specific version to install (e.g. v0.1.0). Defaults to latest. +# VERSION - specific version to install (e.g. v0.1.0). Defaults to latest. # INSTALL_DIR - directory to install to. Defaults to /usr/local/bin. set -e @@ -112,10 +114,34 @@ download_and_install() { "${INSTALL_DIR}/${BINARY}" --version 2>/dev/null || true } -# --- main ------------------------------------------------------------------ +# --- uninstall ------------------------------------------------------------- + +uninstall() { + if [ ! -f "${INSTALL_DIR}/${BINARY}" ]; then + error "${BINARY} not found in ${INSTALL_DIR}" + fi + + info "removing ${INSTALL_DIR}/${BINARY}" + if [ -w "$INSTALL_DIR" ]; then + rm -f "${INSTALL_DIR}/${BINARY}" + else + info "elevated permissions required to remove from ${INSTALL_DIR}" + sudo rm -f "${INSTALL_DIR}/${BINARY}" + fi -detect_target -resolve_version -download_and_install + info "${BINARY} has been uninstalled" +} + +# --- main ------------------------------------------------------------------ -info "done!" +case "${1:-}" in + --uninstall) + uninstall + ;; + *) + detect_target + resolve_version + download_and_install + info "done!" + ;; +esac