#!/usr/bin/env bash
# ox services catalog verification script
# entry: clickhouse@24 (entry_version 1)
# generated by `ox catalog verify-script`; replay with: bash <this-file>
set -euo pipefail
if systemctl is-active --quiet clickhouse-server.service; then echo "clickhouse@24: converged (unit active)"; exit 0; fi
# step: create /etc/apt/keyrings
install -d -m 0755 /etc/apt/keyrings
# step: fetch the clickhouse signing key
bash -c 'curl -fsSL --max-time 60 '\''https://packages.clickhouse.com/rpm/lts/repodata/repomd.xml.key'\'' -o '\''/tmp/ox-key-clickhouse.asc'\'' && test -s '\''/tmp/ox-key-clickhouse.asc'\'''
# step: install the clickhouse keyring
install -o root -g root -m 0644 /tmp/ox-key-clickhouse.asc /etc/apt/keyrings/clickhouse.asc
# step: write the clickhouse sources list
bash -c 'printf '\''%s'\'' '\''Types: deb
URIs: https://packages.clickhouse.com/deb
Suites: stable
Components: main
Signed-By: /etc/apt/keyrings/clickhouse.asc
'\'' > '\''/tmp/ox-source-clickhouse.sources'\'''
# step: install the clickhouse sources list
install -o root -g root -m 0644 /tmp/ox-source-clickhouse.sources /etc/apt/sources.list.d/ox-clickhouse.sources
# step: refresh package index for clickhouse@24
apt-get update -qq
# step: install clickhouse-server clickhouse-client
bash -c 'DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends clickhouse-server clickhouse-client'
# step: enable clickhouse-server.service
systemctl enable --now clickhouse-server.service
# step: wait for http://127.0.0.1:8123/ping
curl --fail --silent --show-error --retry 15 --retry-delay 2 --retry-connrefused --retry-max-time 60 --max-time 3 http://127.0.0.1:8123/ping
# step: run
bash -c 'clickhouse-client --query '\''CREATE DATABASE IF NOT EXISTS verify'\'' && clickhouse-client --query '\''SHOW DATABASES'\'' | grep -qx '\''verify'\'''
