|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# The purpose of this script is to make it easy to reset a local onpremise |
| 4 | +# install to a clean state, optionally targeting a particular version. |
| 5 | + |
| 6 | +set -euo pipefail |
| 7 | + |
| 8 | +if [ -n "${DEBUG:-}" ]; then |
| 9 | + set -x |
| 10 | +fi |
| 11 | + |
| 12 | +cd "$(dirname $0)" |
| 13 | + |
| 14 | + |
| 15 | +function confirm () { |
| 16 | + read -p "$1 [y/n] " confirmation |
| 17 | + if [ "$confirmation" != "y" ]; then |
| 18 | + echo "Canceled. 😅" |
| 19 | + exit |
| 20 | + fi |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +# If we have a version given, validate it. |
| 25 | +# ---------------------------------------- |
| 26 | +# Note that arbitrary git refs won't work, because the *_IMAGE variables in |
| 27 | +# .env will almost certainly point to :latest. Tagged releases are generally |
| 28 | +# the only refs where these component versions are pinned, so enforce that |
| 29 | +# we're targeting a valid tag here. Do this early in order to fail fast. |
| 30 | + |
| 31 | +version="${1:-}" |
| 32 | +if [ -n "$version" ]; then |
| 33 | + set +e |
| 34 | + git rev-parse --verify --quiet "refs/tags/$version" > /dev/null |
| 35 | + if [ $? -gt 0 ]; then |
| 36 | + echo "Bad version: $version" |
| 37 | + exit |
| 38 | + fi |
| 39 | + set -e |
| 40 | +fi |
| 41 | + |
| 42 | +# Make sure they mean it. |
| 43 | +confirm "☠️ Warning! 😳 This is highly destructive! 😱 Are you sure you wish to proceed?" |
| 44 | +echo "Okay ... good luck! 😰" |
| 45 | + |
| 46 | +# Hit the reset button. |
| 47 | +docker compose down --volumes --remove-orphans --rmi local |
| 48 | + |
| 49 | +# Remove any remaining (likely external) volumes with name matching 'sentry-.*'. |
| 50 | +for volume in $(docker volume list --format '{{ .Name }}' | grep '^sentry-'); do |
| 51 | + docker volume remove $volume > /dev/null \ |
| 52 | + && echo "Removed volume: $volume" \ |
| 53 | + || echo "Skipped volume: $volume" |
| 54 | +done |
| 55 | + |
| 56 | +# If we have a version given, switch to it. |
| 57 | +if [ -n "$version" ]; then |
| 58 | + git checkout "$version" |
| 59 | +fi |
| 60 | + |
| 61 | +# Install. |
| 62 | +exec ./install.sh |
0 commit comments