Skip to content

Commit f00e6a9

Browse files
authored
feat: Add sentry-admin.sh tool (#2594)
1 parent b413e01 commit f00e6a9

File tree

3 files changed

+95
-4
lines changed

3 files changed

+95
-4
lines changed

_integration-test/ensure-backup-restore-works.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ echo "Creating backup..."
1010
# to group and owner. Instead, try creating the empty file and then give everyone write access to the backup file
1111
touch $(pwd)/sentry/backup.json
1212
chmod 666 $(pwd)/sentry/backup.json
13-
# Command here matches exactly what we have in our docs https://develop.sentry.dev/self-hosted/backup/#backup
14-
$dc run -v $(pwd)/sentry:/sentry-data/backup --rm -T -e SENTRY_LOG_LEVEL=CRITICAL web export global /sentry-data/backup/backup.json
15-
# Check to make sure there is content in the file
13+
SENTRY_DOCKER_IO_DIR=$(pwd)/sentry /bin/bash $(pwd)/sentry-admin.sh export global /sentry-admin/backup.json
1614
if [ ! -s "$(pwd)/sentry/backup.json" ]; then
1715
echo "Backup file is empty"
1816
exit 1
@@ -33,6 +31,6 @@ source install/set-up-and-migrate-database.sh
3331
$dc up -d
3432

3533
echo "Importing backup..."
36-
$dc run --rm -T web import global /etc/sentry/backup.json
34+
SENTRY_DOCKER_IO_DIR=$(pwd)/sentry /bin/bash $(pwd)/sentry-admin.sh import global /sentry-admin/backup.json
3735

3836
rm $(pwd)/sentry/backup.json
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
source install/_lib.sh
5+
source install/dc-detect-version.sh
6+
7+
echo "${_group}Test that sentry-admin works..."
8+
9+
echo "Global help documentation..."
10+
11+
global_help_doc=$(/bin/bash --help)
12+
if ! echo "$global_help_doc" | grep -q "^Usage: ./sentry-admin.sh"; then
13+
echo "Assertion failed: Incorrect binary name in global help docs"
14+
exit 1
15+
fi
16+
if ! echo "$global_help_doc" | grep -q "SENTRY_DOCKER_IO_DIR"; then
17+
echo "Assertion failed: Missing SENTRY_DOCKER_IO_DIR global help doc"
18+
exit 1
19+
fi
20+
21+
echo "Command-specific help documentation..."
22+
23+
command_help_doc=$(/bin/bash permissions --help)
24+
if ! echo "$command_help_doc" | grep -q "^Usage: ./sentry-admin.sh permissions"; then
25+
echo "Assertion failed: Incorrect binary name in command-specific help docs"
26+
exit 1
27+
fi

sentry-admin.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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

Comments
 (0)