fix: make prime_profile.sh fail loudly instead of exiting 0 or dying silently

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-08-29 15:09:21 +02:00
parent bb72f0ae93
commit f4f8c32329

View File

@ -35,11 +35,12 @@ RECIPIENTS=()
# shellcheck source-path=SCRIPTDIR source=scripts/lib_signal.sh
. "${SCRIPT_DIR}/lib_signal.sh"
# Prints only. The caller decides the exit code, so a usage *error* cannot
# exit 0 and be read as success by whatever ran this.
usage() {
echo "Usage: ${SCRIPT_NAME} +<E164 number> [+<E164 number> ...]"
echo "Sends one DM from the bot so the recipient's client learns its"
echo "profile key, which makes a later group add land as a real join."
exit 0
}
validate_requirements() {
@ -47,7 +48,8 @@ validate_requirements() {
command -v jq >/dev/null || { echo "Error: jq is required" >&2; exit 1; }
if [[ ${#RECIPIENTS[@]} -eq 0 ]]; then
echo "Error: at least one recipient number is required" >&2
usage
usage >&2
exit 1
fi
local number
for number in "${RECIPIENTS[@]}"; do
@ -66,7 +68,11 @@ validate_requirements() {
# typed twice is a number that can be typed differently the second time.
bot_number() {
local number
number="$(grep -E '^PHONE_NUMBER=' "${REPO_ROOT}/.env" | head -1 | cut -d= -f2-)"
# `|| true`: under `set -e` a grep that matches nothing kills the whole
# subshell, so the error message below would never print and the script
# would exit 1 silently -- the failure mode this repo exists to gate.
number="$(grep -E '^PHONE_NUMBER=' "${REPO_ROOT}/.env" || true)"
number="$(printf '%s' "$number" | head -1 | cut -d= -f2-)"
if [[ -z "$number" ]]; then
echo "Error: PHONE_NUMBER is not set in ${REPO_ROOT}/.env" >&2
return 1
@ -113,6 +119,7 @@ while [[ $# -gt 0 ]]; do
case $1 in
-h | --help)
usage
exit 0
;;
-*)
echo "Unknown option: $1" >&2