# pg_comb

PostgreSQL metrics collector agent for the Odilatech platform.
Single static binary, no dependencies, Linux **amd64** and **arm64**.

---

## Quick install (one-liner)

```bash
curl -fsSL https://download.odilatech.com.br/pg_comb/latest/install.sh | bash
```

or

```bash
wget -qO- https://download.odilatech.com.br/pg_comb/latest/install.sh | bash
```

Use the URL matching your region:

| Region | Install URL |
|--------|-------------|
| (BR) Brazil | `https://download.odilatech.com.br/pg_comb/latest/install.sh` |
| (AU) Australia | `https://download-au.odilatech.com/pg_comb/latest/install.sh` |
| (CA) Canada | `https://download-ca.odilatech.com/pg_comb/latest/install.sh` |
| (EU) Europe | `https://download-eu.odilatech.com/pg_comb/latest/install.sh` |

The installer detects your CPU architecture (amd64 / arm64) automatically and verifies the binary's **GPG signature** before installing.

---

## What `install.sh` does

1. Detects architecture (`x86_64` or `aarch64`).
2. Installs `gnupg` if missing (asks the package manager: apt / dnf / yum / apk / pacman).
3. Downloads the matching binary and its detached GPG signature (`.asc`).
4. Verifies the signature against the **embedded Odilatech Release public key**. Aborts if invalid.
5. Installs to `/opt/pg_comb/pg_comb` (`chmod +x`).

---

## Manual install (step by step)

```bash
ARCH=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')
mkdir -p /opt/pg_comb && cd /opt/pg_comb

# 1) download binary + signature
curl -fsSLO https://download.odilatech.com.br/pg_comb/latest/pg_comb_linux_${ARCH}
curl -fsSLO https://download.odilatech.com.br/pg_comb/latest/pg_comb_linux_${ARCH}.asc

# 2) get the public key (embedded in install.sh)
curl -fsSL https://download.odilatech.com.br/pg_comb/latest/install.sh \
    | sed -n '/BEGIN PGP PUBLIC KEY/,/END PGP PUBLIC KEY/p' > odilatech-release.pub.asc

# 3) verify
gpg --import odilatech-release.pub.asc
gpg --verify pg_comb_linux_${ARCH}.asc pg_comb_linux_${ARCH}
# expected: "Good signature from \"Odilatech Release Signing ...\""

# 4) install
mv pg_comb_linux_${ARCH} pg_comb
chmod +x pg_comb
```

---

## Cron (collect every minute)

```cron
* * * * * timeout 55 /opt/pg_comb/pg_comb > /opt/pg_comb/pg_comb.log 2>&1
```

---

## Files in this directory

| File | Purpose |
|------|---------|
| `install.sh` | Auto-installer (region-templated, includes embedded public key) |
| `pg_comb_linux_amd64` | Binary for x86_64 |
| `pg_comb_linux_amd64.asc` | Detached GPG signature |
| `pg_comb_linux_arm64` | Binary for aarch64 |
| `pg_comb_linux_arm64.asc` | Detached GPG signature |
| `pg_comb.version` | Plain-text version string |
| `<version>.version` | Empty marker file (visual version indicator) |
| `README.md` | This file |

---

## Verifying the release publicly

The releases are signed by the **Odilatech Release Signing** key.

**Fingerprint:**

```
6620 02B0 1150 8EC6 74CB  FD2E 8CE1 742A A457 681C
```

Cross-check this fingerprint at:

- The Odilatech website (`odila.tech/pgp`)
- The public Git repository's README
- WKD: `gpg --auto-key-locate wkd --locate-keys release@odilatech.com`

If the fingerprint shown by `gpg --import` matches the one above, the key is genuine.

---

## After install — claim the server

After installing, register the host on the regional admin panel:

| Region | Panel |
|--------|-------|
| BR | `https://admin.odilatech.com.br` |
| AU | `https://admin-au.odilatech.com` |

Run `pg_comb` once interactively; it prints a one-time code to enter on the panel.

---

## Auto-update

`pg_comb` checks for newer versions on every run and updates itself in place (GPG-verified) when a newer build is available on the regional download server. Downgrade requires manual reinstall.

---

## Architecture support

| Arch | Status |
|------|--------|
| linux/amd64 (`x86_64`) | ✅ Full support |
| linux/arm64 (`aarch64`) | ✅ Full support |
| Other (riscv64, s390x, ppc64le) | ❌ Not built |

---

Built with [garble](https://github.com/burrowers/garble) (obfuscation) + [UPX](https://upx.github.io/) (compression). Released hourly-aligned by the Forgejo Actions pipeline on each version bump.
