Skip to content

Scripts

Operational tasks are wrapped in shell scripts under sbin/. They are Bash, resolve every path through BSS_HOME, and are safe to source or execute (a source-safety guard re-runs an accidentally-sourced script in a child process so a failure can never close your shell).

Installing the platform

This page is a per-script reference. For the end-to-end greenfield flow (build → database → secrets → certificates → license → run, and the package/deploy path), follow the single Installation guide.

Build

install.sh

Provisions a build host and makes the in-tree build self-contained. Two jobs:

  1. Dependencies — installs the platform's build/runtime dependencies (Homebrew on macOS, APT on Ubuntu/Debian), downloads the Inja header, builds Plutobook and installs the MySQL Connector/C++ where they ship no package (the Connector .debs are picked to match the host's distro release from /etc/os-release, e.g. ubuntu26.04, falling back to the ubuntu24.04 build), and bootstraps ACE from source (build_ace.sh) when no libACE is present. It builds the PHP grpc extension from PECL for one PHP and enables it only there — a compiled extension is tied to one Zend API (one PHP minor version). On macOS that is the latest PHP 8, Homebrew's php formula (the one Homebrew's Apache loads): grpc is built with that version's own pecl, lands in its extension_dir, and is enabled through /opt/homebrew/etc/php/<ver>/conf.d/ext-grpc.ini; grpc.so entries that earlier runs wrote into other PHP versions' ini files (which broke those PHPs with "Module compiled with module API=… These options need to match") are removed, keeping a .microbss.bak copy, and a running Homebrew httpd is restarted. PHP 8.6 dropped the legacy XtOffsetOf() alias that the grpc PECL source still uses, so the build force-includes a one-line compat header restoring the old offsetof definition (a no-op on PHP versions that still define it). If an earlier sudo pecl install left root-owned files in Homebrew's PEAR tree, the script stops before the build and prints the chown that fixes it. On Ubuntu/Debian it is the default php (apt install php-grpc fails because that package is not in the APT repos), enabled with mods-available/grpc.ini + phpenmod -v <ver>; this requires php-dev (phpize) and php-pear (pecl), which the script installs.
  2. Library bundling (hermetic) — bundles the third-party shared libraries the engine links against into the root lib, recreating the version/soname symlinks as local relative links and writing .sha256 sidecars into a hidden lib/.sha256/ subdir (kept out of lib itself so a libfoo.so.N.sha256 is never mistaken for a malformed ELF object by ldconfig at unpack time). It starts from a seed set (libACE, libACE_SSL, libprotobuf, libgrpc(++), libmysqlcppconnx, libplutobook, libssl, libcrypto, the libabsl_* set) and then, on Linux, walks the full ldd dependency closure of those seeds (and of the built binaries when present), pulling in every transitively-required object — libupb, libre2, libcares, the ICU/cairo/freetype/fontconfig/harfbuzz/pixman/image stack, libz, libstdc++, libgcc_s, … — except the core glibc/loader libs (libc, libm, libpthread, ld-linux, …), which must come from the target host. The result is self-contained: a freshly built tree typically bundles ~100+ objects. Each binary's RPATH lists the bundled lib and platform-built usr/lib (at both the bin/ and usr/lib/ depths) ahead of any system directory; on Linux the binaries are linked with -Wl,--disable-new-dtags so the RPATH is DT_RPATH (honoured transitively, unlike DT_RUNPATH), which lets the bundled libraries' own dependencies resolve from lib too — no ldconfig or LD_LIBRARY_PATH required on the target. Copies are checksum-guarded, so re-runs are cheap and idempotent. (macOS, the dev host, uses the explicit seed list only.) On Linux it also bundles the host's PECL-built PHP grpc extension, stripped, into lib/php/<PHP-API>/grpc.so, so a target with the same PHP minor version gets ext-grpc from the archive instead of compiling it (see unpack.sh).
bash sbin/install.sh               # deps + bundle libs
bash sbin/install.sh --deps-only   # dependencies (+ ACE) only
bash sbin/install.sh --bundle-libs # re-bundle libs only (e.g. after a system upgrade)

Flags: --deps-only, --bundle-libs, --no-ace. The bundled third-party libs are host-specific and git-ignored; the platform's own libs stay tracked. Packaging to a foreign prefix is not this script's job — that is pack.sh / unpack.sh.

build.sh

Configures CMake (tmp/CMakeLists.txt, build directory tmp/build/) with -DBSS_HOME_DEFAULT=$BSS_HOME, compiles the engine into bin and usr/lib, regenerates the PHP gRPC stubs (generate-proto.sh), and runs composer install for the CRM. Run after any C++/proto change.

bash sbin/build.sh

build_ace.sh

Bootstraps the ACE framework from source when the system has no libACE — fetches the latest ACE_TAO release, builds with ssl=1, and (with install) installs to /usr/local.

./build_ace.sh Linux install      # or: ./build_ace.sh macOS install

generate-proto.sh

Regenerates the PHP gRPC client stubs from usr/src/proto/types.proto into the frontend's var/www/generated/ directory. Invoked by build.sh; run standalone after editing the proto. Requires protoc + grpc_php_plugin.

Environment

dev_env.sh

Source this (do not execute) to load the development environment into your shell: it resolves BSS_HOME, generates the PAN-token key once into var/lib/secrets/pan_token_key, reads the JWT secret from etc/.jwt_secret (created and rotated by set_env.sh — the single copy the engine and the PHP front-end share), and exports MICROBSS_DB_* (including MICROBSS_TEST_DB_PORT), the derived CRM_DB_* frontend variables, CERTS_PATH, MICROBSS_GRPC_*, and the MICROBSS_JWT_* / MICROBSS_PAN_TOKEN_KEY variables. It deliberately does not export MICROBSS_LOG_PATH, so each role logs to its own var/log/<module>/ (set it yourself to force one shared log directory). dev_env.sh is the single source of truth for every environment variable the platform reads — the other scripts consume what it exports rather than inventing their own defaults; a new variable belongs in dev_env.sh. It is meant to be sourced from your ~/.bashrc.

On a deployed host it fills any MICROBSS_DB_* / MICROBSS_TEST_DB_PORT / CRM_DB_NAME that is not already exported from etc/db.local.env (written by set_env.sh), so run.sh and the test suites reach the deployment's database from a fresh login shell; explicit exports still win. On a fresh install, before set_env.sh has created etc/.jwt_secret, it exports everything except the JWT variables, prints a note and returns non-zero (so run.sh refuses to start) — run set_env.sh --all, then re-source it.

source sbin/dev_env.sh

set_env.sh

Production configuration writer. Resolves/generates the JWT secret, then writes the database settings read from the environment (the MICROBSS_DB_* and CRM_DB_* variables dev_env.sh exports) into the backend (app.local.env + db.local.env) and/or frontend (config.local.php) local-override files. It also copies the HTTPS certificates from $CERTS_PATH into the backend's etc/certs. It does not invent DB defaults — source dev_env.sh first or the run aborts with a pointer to it. It can also emit a Kubernetes Secret manifest instead of writing files.

source sbin/dev_env.sh        # populate the environment first
set_env.sh --all
set_env.sh --output-k8s-secret --k8s-namespace prod | kubectl apply -f -

Package & deploy

pack.sh

Builds versioned release archives into $BSS_HOME/dist/. Manages four areas — backend, frontend, docs, tests — or all (backend + frontend + docs). tests is the standalone deployment acceptance pack (usr/share/tests/e2e, noarch). Config files ship as *.template only. Refuses to pack a stale backend build unless --no-verify is given. The backend archive carries both lib trees — the platform-built usr/lib and the bundled third-party root lib — so the unpacked platform runs standalone without system-installing the engine's dependencies. It also ships the sbin/ operational scripts (so the unpacked tree is self-managing), the SQL install set (usr/src/sql/billing_0?_*.sql + crm/crm_auth.sql) consumed by microbss_db_reset.sh / the crm_auth setup, the etc/mediation/formats/ descriptors, and the test suite (usr/share/tests/, minus the arch-specific .venv) so the deployed tree is self-testing. Each staging step is logged so a packing run is self-documenting.

By default the archive is secret-free, same as before. Two opt-in, interactive flags (backend/all only, require a TTY) let you bake a customer-specific license and a fresh TLS cert pair directly into the archive instead of generating them post-install:

  • --with-license — prompts Mint a license for this package? [y/N] (answering no skips it entirely), then customer ID / expiry / feature mask / target hardware ID (localhost to read this machine's ID, or an explicit Linux machine-id / macOS IOPlatformUUID). Signs via mint_license.sh's YubiKey path — the packing machine needs a YubiKey plugged in. Writes var/lib/license/platform.lic.
  • --with-certs — prompts for the CRM frontend hostname (blank = localhost-only SAN), then regenerates a self-signed CA + server cert pair at etc/certs/, fresh on every invocation, using the same recipe as Installation §5.
pack.sh --load backend  --version 1.0.0
pack.sh --load frontend --version 1.0.0
pack.sh --load docs     --version 1.0.0
pack.sh --load tests    --version 1.0.0   # standalone e2e acceptance pack
pack.sh --load all      --version 1.0.0
pack.sh --load backend  --version 1.0.0 --with-license --with-certs   # appliance-style: bake in license + certs

build_linux.sh

Builds the Linux x86_64 release from a macOS build host, inside an already-running x86_64 Colima VM (QEMU). Run on the Mac; it re-invokes itself in the VM through Colima's $HOME mount. It builds only the committed state of the tree: it refuses uncommitted changes unless --allow-dirty, and even then builds only what is committed. Inside the VM it fetches that commit into a persistent VM-local clone (default ~/micro.bss, remote mac), runs install.sh → build.sh → pack.sh --load all (+ --load tests) with the Mac's $BSS_HOME/dist/ as --output-dir, then verifies the backend archive (x86-64 bin/server, every library resolved by ldd from the bundled lib trees, bundled grpc.so Zend API reported). The Mac's own bin/, usr/lib/ and tmp/build/ are never touched. The VM is never started unless --start is given. Log: var/log/build_linux/.

build_linux.sh --version 1.0.0
build_linux.sh --version 1.0.0 --ref v1.0.0 --no-install   # tag, deps already in the VM

Flags: --ref REF, --profile NAME, --vm-dir PATH, --start, --no-install, --no-tests, --allow-dirty.

unpack.sh

Installs an archive into a target prefix, auto-detecting the area from its name. Instantiates configs from templates, lays down the sbin/ scripts, the SQL install set, the etc/mediation/ descriptors and the full var/spool working subtree, runs composer install (frontend) and ldconfig (backend), recreates the virtualenvs of both test suites — regression and e2e (python -m venv + pip install -e ., unless --no-venv), and — for the docs area — places the MkDocs sources and renders the static site (the doc build is assimilated here; MkDocs + Material is installed if missing). The backend area lays down both usr/lib and the bundled root lib (replaced via write-and-rename, so a redeploy never corrupts a library a running process has mapped); the binaries' RPATH lets the platform run with no system-installed engine dependencies. Only the platform's own usr/lib is registered with ldconfig. The bundled third-party lib is deliberately kept out of the global linker cache, because its libcrypto/libssl/libz/libstdc++ copies would otherwise shadow the system libraries for every process on the host (sshd, Apache, MySQL, PHP); see NC-18. Re-running unpack.sh rewrites /etc/ld.so.conf.d/microbss.conf and so also removes that registration from older installs.

unpack.sh dist/microbss-backend-1.0.0-x86_64.tar.gz  --backend-prefix /opt/microbss/backend
unpack.sh dist/microbss-frontend-1.0.0-noarch.tar.gz --frontend-prefix /var/www
unpack.sh dist/microbss-docs-1.0.0-noarch.tar.gz     --docs-prefix /opt/microbss/backend --docs-site-dir /var/www/html/docs
unpack.sh dist/microbss-tests-1.0.0-noarch.tar.gz    --backend-prefix /opt/microbss/backend

Flags: --force, --no-composer, --no-venv, --no-db, --no-ldconfig, --no-docs-build, --dry-run.

  • PHP ext-grpc — the CRM's composer.json requires it. If the target's PHP lacks it, unpack.sh enables the build bundled in the backend's lib/php/<PHP-API>/grpc.so (Debian/Ubuntu: /etc/php/<ver>/mods-available/grpc.ini + phpenmod, then an Apache reload), provided the Zend API matches. Otherwise it stops and points at install.sh --deps-only, which builds the extension from PECL on that host.
  • Databases (backend/all) — when MICROBSS_DB_* credentials are exported (or an earlier etc/db.local.env exists), any missing billing / crm_auth database is created from the shipped SQL install set. An existing database is never touched; resetting is microbss_db_reset.sh's job. Without credentials the step is skipped with a note; --no-db skips it explicitly.
  • Next steps — after a backend/all/tests install it prints the remaining operator commands (dev_env.sh → set_env.sh --all → run.sh all) followed by the deployment acceptance check (usr/share/tests/e2e/run_e2e.sh --crm-url …, expect "3 passed"). The same instructions are in unpack.sh --help and in the script's header comment.

If the backend archive carries a pre-issued license (var/lib/license/platform.lic) or generated certs (etc/certs/) — i.e. it was packed with --with-license/--with-certs — unpack.sh installs them too, skipping (with a warning) any file that already exists at the target unless --force is given, so redeploying a newer archive never silently overwrites a live install's own license or certs. On Linux, the frontend install also links var/log/apache2 to the system /var/log/apache2 (a no-op, left in place with a warning, if something non-symlink already occupies that path).

Run, stop, status

run.sh

Starts one role (or every role) under nohup, reading etc/<role>.toml.

./run.sh all                  # start every role (incl. mediation + roaming)
./run.sh prepaid              # start one role in the background, then tail its nohup log
./run.sh billing              # billing1..billing4

kill.sh

Graceful stop: matches running bin/server processes by their TOML, sends SIGTERM, waits up to 5 s, then escalates to SIGKILL. This lets the CRM server drain in-flight RPCs and the reactor cancel its timers.

./kill.sh all          # or a single role: ./kill.sh prepaid / ./kill.sh billing

clean.sh

Removes every artefact build.sh produces — the CMake build directory, the installed binaries and platform libraries, the generated protobuf C++ and PHP stubs (var/www/generated), the Composer vendor/ tree and the build logs — returning the tree to a source-only state.

bash sbin/clean.sh

status.sh

Prints a one-line status per running role (PID → role), keyed off the TOML each bin/server was started with. Handy as a smoke test after run.sh all.

Database

microbss_db_reset.sh

Backs up, drops, recreates and reloads the billing database from the three ordered SQL files (usr/src/sql/billing_01_structure.sql → billing_02_reference_data.sql → billing_03_subscriber_data.sql). Reads connection settings from the MICROBSS_DB_* environment variables. Destructive — intended for development resets.

source sbin/dev_env.sh
./microbss_db_reset.sh

Licensing

mint_license.sh

Operator wrapper over bin/licensing --issue --yubikey that mints a signed platform.lic for a customer installation. Select the target platform with one of --auto (default → this host, bound via --localhost), --macos, or --linux; the host OS (where the YubiKey lives) is independent, so a macOS laptop can sign a license for a Linux VM. It format-checks the hardware id against the target (--linux → 32-hex /etc/machine-id, --macos → dashed IOPlatformUUID), requires an explicit --hwid whenever the target differs from the host, defaults to --features 0x7f, and runs --verify on the result as a self-check. --dry-run prints the command without signing. See the license-issuance runbook for worked examples; PIN handling (MBSS_YK_PIN / no-echo prompt) and key custody are unchanged.

# License for this machine (default --auto):
sbin/mint_license.sh --customer acme-7F3A --expires 2027-12-31

# On a macOS laptop, mint for a Linux GCP VM (hwid = the VM's /etc/machine-id):
sbin/mint_license.sh --linux --customer acme-7F3A --expires 2027-12-31 \
    --hwid 4f1c2e9ab0d34f5e8c7a1b2c3d4e5f60 --out /tmp/acme-platform.lic