mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-11-27 18:29:23 +01:00
fix: make prime_profile.sh fail loudly instead of exiting 0 or dying silently
Some checks are pending
CI / check (push) Waiting to run
Some checks are pending
CI / check (push) Waiting to run
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5de21959ba
commit
60ae8d70c8
@ -35,11 +35,12 @@ RECIPIENTS=()
|
|||||||
# shellcheck source-path=SCRIPTDIR source=scripts/lib_signal.sh
|
# shellcheck source-path=SCRIPTDIR source=scripts/lib_signal.sh
|
||||||
. "${SCRIPT_DIR}/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() {
|
usage() {
|
||||||
echo "Usage: ${SCRIPT_NAME} +<E164 number> [+<E164 number> ...]"
|
echo "Usage: ${SCRIPT_NAME} +<E164 number> [+<E164 number> ...]"
|
||||||
echo "Sends one DM from the bot so the recipient's client learns its"
|
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."
|
echo "profile key, which makes a later group add land as a real join."
|
||||||
exit 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
validate_requirements() {
|
validate_requirements() {
|
||||||
@ -47,7 +48,8 @@ validate_requirements() {
|
|||||||
command -v jq >/dev/null || { echo "Error: jq is required" >&2; exit 1; }
|
command -v jq >/dev/null || { echo "Error: jq is required" >&2; exit 1; }
|
||||||
if [[ ${#RECIPIENTS[@]} -eq 0 ]]; then
|
if [[ ${#RECIPIENTS[@]} -eq 0 ]]; then
|
||||||
echo "Error: at least one recipient number is required" >&2
|
echo "Error: at least one recipient number is required" >&2
|
||||||
usage
|
usage >&2
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
local number
|
local number
|
||||||
for number in "${RECIPIENTS[@]}"; do
|
for number in "${RECIPIENTS[@]}"; do
|
||||||
@ -66,7 +68,11 @@ validate_requirements() {
|
|||||||
# typed twice is a number that can be typed differently the second time.
|
# typed twice is a number that can be typed differently the second time.
|
||||||
bot_number() {
|
bot_number() {
|
||||||
local 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
|
if [[ -z "$number" ]]; then
|
||||||
echo "Error: PHONE_NUMBER is not set in ${REPO_ROOT}/.env" >&2
|
echo "Error: PHONE_NUMBER is not set in ${REPO_ROOT}/.env" >&2
|
||||||
return 1
|
return 1
|
||||||
@ -113,6 +119,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
case $1 in
|
case $1 in
|
||||||
-h | --help)
|
-h | --help)
|
||||||
usage
|
usage
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
echo "Unknown option: $1" >&2
|
echo "Unknown option: $1" >&2
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user