|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Detect docker and platform state. |
| 4 | +source install/dc-detect-version.sh |
| 5 | +source install/detect-platform.sh |
| 6 | + |
| 7 | +# Define the Docker volume mapping. |
| 8 | +VOLUME_MAPPING="${SENTRY_DOCKER_IO_DIR:-$HOME/.sentry/sentry-admin}:/sentry-admin" |
| 9 | + |
| 10 | +# Custom help text paragraphs |
| 11 | +HELP_TEXT_SUFFIX=" |
| 12 | +All file paths are relative to the 'web' docker container, not the host environment. To pass files |
| 13 | +to/from the host system for commands that require it ('execfile', 'export', 'import', etc), you may |
| 14 | +specify a 'SENTRY_DOCKER_IO_DIR' environment variable to mount a volume for file IO operations into |
| 15 | +the host filesystem. The default value of 'SENTRY_DOCKER_IO_DIR' points to '~/.sentry/sentry-admin' |
| 16 | +on the host filesystem. Commands that write files should write them to the '/sentry-admin' in the |
| 17 | +'web' container (ex: './sentry-admin.sh export global /sentry-admin/my-export.json'). |
| 18 | +" |
| 19 | + |
| 20 | +# Actual invocation that runs the command in the container. |
| 21 | +invocation() { |
| 22 | + $dc run -v "$VOLUME_MAPPING" --rm -T -e SENTRY_LOG_LEVEL=CRITICAL web "$@" |
| 23 | +} |
| 24 | + |
| 25 | +# Function to modify lines starting with `Usage: sentry` to say `Usage: ./sentry-admin.sh` instead. |
| 26 | +rename_sentry_bin_in_help_output() { |
| 27 | + local output="$1" |
| 28 | + local help_prefix="$2" |
| 29 | + local usage_seen=false |
| 30 | + |
| 31 | + output=$(invocation "$@") |
| 32 | + |
| 33 | + echo -e "\n\n" |
| 34 | + |
| 35 | + while IFS= read -r line; do |
| 36 | + if [[ $line == "Usage: sentry"* ]] && [ "$usage_seen" = false ]; then |
| 37 | + echo -e "\n\n" |
| 38 | + echo "${line/sentry/./sentry-admin.sh}" |
| 39 | + echo "$help_prefix" |
| 40 | + usage_seen=true |
| 41 | + else |
| 42 | + if [[ $line == "Options:"* ]] && [ -n "$1" ]; then |
| 43 | + echo "$help_prefix" |
| 44 | + fi |
| 45 | + echo "$line" |
| 46 | + fi |
| 47 | + done <<<"$output" |
| 48 | +} |
| 49 | + |
| 50 | +# Check for the user passing ONLY the '--help' argument - we'll add a special prefix to the output. |
| 51 | +if { [ "$1" = "help" ] || [ "$1" = "--help" ]; } && [ "$#" -eq 1 ]; then |
| 52 | + rename_sentry_bin_in_help_output "$(invocation "$@")" "$HELP_TEXT_SUFFIX" |
| 53 | + exit 0 |
| 54 | +fi |
| 55 | + |
| 56 | +# Check for '--help' in other contexts. |
| 57 | +for arg in "$@"; do |
| 58 | + if [ "$arg" = "--help" ]; then |
| 59 | + rename_sentry_bin_in_help_output "$(invocation "$@")" |
| 60 | + exit 0 |
| 61 | + fi |
| 62 | +done |
| 63 | + |
| 64 | +# Help has not been requested - go ahead and execute the command. |
| 65 | +echo -e "\n\n" |
| 66 | +invocation "$@" |
0 commit comments