#!/usr/bin/env bash
# ox services catalog verification script
# entry: neo4j@5 (entry_version 1)
# generated by `ox catalog verify-script`; replay with: bash <this-file>
set -euo pipefail
if systemctl is-active --quiet neo4j.service; then echo "neo4j@5: converged (unit active)"; exit 0; fi
# step: create /etc/apt/keyrings
install -d -m 0755 /etc/apt/keyrings
# step: fetch the neo4j signing key
bash -c 'curl -fsSL --max-time 60 '\''https://debian.neo4j.com/neotechnology.gpg.key'\'' -o '\''/tmp/ox-key-neo4j.asc'\'' && test -s '\''/tmp/ox-key-neo4j.asc'\'''
# step: install the neo4j keyring
install -o root -g root -m 0644 /tmp/ox-key-neo4j.asc /etc/apt/keyrings/neo4j.asc
# step: write the neo4j sources list
bash -c 'printf '\''%s'\'' '\''Types: deb
URIs: https://debian.neo4j.com
Suites: stable
Components: latest
Signed-By: /etc/apt/keyrings/neo4j.asc
'\'' > '\''/tmp/ox-source-neo4j.sources'\'''
# step: install the neo4j sources list
install -o root -g root -m 0644 /tmp/ox-source-neo4j.sources /etc/apt/sources.list.d/ox-neo4j.sources
# step: refresh package index for neo4j@5
apt-get update -qq
# step: install neo4j
bash -c 'DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends neo4j'
# step: enable neo4j.service
systemctl enable --now neo4j.service
# step: run
bash -c 'cypher-shell -u neo4j -p '\''0xvERIFYcredential1234567890ABCDEFGH'\'' -a bolt://127.0.0.1:7687 '\''RETURN 1;'\'' >/dev/null 2>&1 && exit 0
env NEO4J_PASSWORD='\''0xvERIFYcredential1234567890ABCDEFGH'\'' systemctl stop neo4j.service
rm -f -- /var/lib/neo4j/data/dbms/auth.ini
sudo -u neo4j neo4j-admin dbms set-initial-password '\''0xvERIFYcredential1234567890ABCDEFGH'\''
systemctl start neo4j.service
for i in $(seq 1 30); do
  cypher-shell -u neo4j -p '\''0xvERIFYcredential1234567890ABCDEFGH'\'' -a bolt://127.0.0.1:7687 '\''RETURN 1;'\'' >/dev/null 2>&1 && exit 0
  sleep 2
done
exit 1'
