diff --git a/install/_test_setup.sh b/install/_test_setup.sh index 3a44099..e00d8d6 100644 --- a/install/_test_setup.sh +++ b/install/_test_setup.sh @@ -1,50 +1,52 @@ set -euo pipefail source "$(dirname $0)/_lib.sh" rm -rf /tmp/sentry-onpremise-test-sandbox.* _SANDBOX="$(mktemp -d /tmp/sentry-onpremise-test-sandbox.XXX)" report_success() { echo "$(basename $0) - Success 👍" } teardown() { test "${DEBUG:-}" || rm -rf "$_SANDBOX" } setup() { + cd .. + # Clone the local repo into a temp dir. FWIW `git clone --local` breaks for # me because it depends on hard-linking, which doesn't work across devices, # and I happen to have my workspace and /tmp on separate devices. git clone --depth=1 "file://$(pwd)" "$_SANDBOX" # Now propagate any local changes from the working copy to the sandbox. This # provides a pretty nice dev experience: edit the files in the working copy, # then run `DEBUG=1 some-test.sh` to leave the sandbox up for interactive # dev/debugging. git status --porcelain | while read line; do # $line here is something like `M some-script.sh`. local filepath="$(cut -f2 -d' ' <(echo $line))" local filestatus="$(cut -f1 -d' ' <(echo $line))" case $filestatus in D) rm "$_SANDBOX/$filepath" ;; A | M | AM | ??) ln -sf "$(realpath $filepath)" "$_SANDBOX/$filepath" ;; **) echo "Wuh? $line" exit 77 ;; esac done - cd "$_SANDBOX" + cd "$_SANDBOX/install" trap teardown EXIT } setup diff --git a/install/geoip-test.sh b/install/geoip-test.sh index f6c55cc..3d61c11 100755 --- a/install/geoip-test.sh +++ b/install/geoip-test.sh @@ -1,16 +1,16 @@ #!/usr/bin/env bash source "$(dirname $0)/_test_setup.sh" -mmdb="geoip/GeoLite2-City.mmdb" +mmdb="../geoip/GeoLite2-City.mmdb" # Starts with no mmdb, ends up with empty. test ! -f $mmdb source geoip.sh diff -rub $mmdb $mmdb.empty # Doesn't clobber existing, though. echo GARBAGE > $mmdb source geoip.sh test "$(cat $mmdb)" = "GARBAGE" report_success diff --git a/install/geoip.sh b/install/geoip.sh index 9a1317b..bc5d84b 100644 --- a/install/geoip.sh +++ b/install/geoip.sh @@ -1,34 +1,38 @@ echo "${_group}Setting up GeoIP integration ..." install_geoip() { - local mmdb='geoip/GeoLite2-City.mmdb' - local conf='geoip/GeoIP.conf' + cd ../geoip + + local mmdb='GeoLite2-City.mmdb' + local conf='GeoIP.conf' local result='Done' echo "Setting up IP address geolocation ..." if [[ ! -f "$mmdb" ]]; then echo -n "Installing (empty) IP address geolocation database ... " cp "$mmdb.empty" "$mmdb" echo "done." else echo "IP address geolocation database already exists." fi if [[ ! -f "$conf" ]]; then echo "IP address geolocation is not configured for updates." echo "See https://develop.sentry.dev/self-hosted/geolocation/ for instructions." result='Error' else echo "IP address geolocation is configured for updates." echo "Updating IP address geolocation database ... " if ! $dcr geoipupdate; then result='Error' fi echo "$result updating IP address geolocation database." fi echo "$result setting up IP address geolocation." + + cd ../install } install_geoip echo "${_endgroup}" diff --git a/install/relay-credentials-test.sh b/install/relay-credentials-test.sh index c025410..ea740f3 100755 --- a/install/relay-credentials-test.sh +++ b/install/relay-credentials-test.sh @@ -1,24 +1,24 @@ #!/usr/bin/env bash source "$(dirname $0)/_test_setup.sh" -cfg="relay/config.yml" -creds="relay/credentials.json" +cfg="../relay/config.yml" +creds="../relay/credentials.json" # Relay files don't exist in a clean clone. test ! -f $cfg test ! -f $creds # Running the install script adds them. source relay-credentials.sh test -f $cfg test -f $creds test "$(jq -r 'keys[2]' $creds)" = "secret_key" # If the files exist we don't touch it. echo GARBAGE > $cfg echo MOAR GARBAGE > $creds source relay-credentials.sh test "$(cat $cfg)" = "GARBAGE" test "$(cat $creds)" = "MOAR GARBAGE" report_success diff --git a/install/relay-credentials.sh b/install/relay-credentials.sh index 91fe34d..2d62e2b 100644 --- a/install/relay-credentials.sh +++ b/install/relay-credentials.sh @@ -1,25 +1,25 @@ echo "${_group}Generating Relay credentials ..." -RELAY_CONFIG_YML="relay/config.yml" -RELAY_CREDENTIALS_JSON="relay/credentials.json" +RELAY_CONFIG_YML="../relay/config.yml" +RELAY_CREDENTIALS_JSON="../relay/credentials.json" ensure_file_from_example $RELAY_CONFIG_YML if [[ ! -f "$RELAY_CREDENTIALS_JSON" ]]; then # We need the ugly hack below as `relay generate credentials` tries to read # the config and the credentials even with the `--stdout` and `--overwrite` # flags and then errors out when the credentials file exists but not valid # JSON. We hit this case as we redirect output to the same config folder, # creating an empty credentials file before relay runs. $dcr \ --no-deps \ --volume "$(pwd)/$RELAY_CONFIG_YML:/tmp/config.yml" \ relay --config /tmp credentials generate --stdout \ > "$RELAY_CREDENTIALS_JSON" echo "Relay credentials written to $RELAY_CREDENTIALS_JSON" fi echo "${_endgroup}"