#!/usr/bin/env bash # Install only the local Asterisk HEP mirror config; restart separately after confirming zero calls. set -euo pipefail [[ $# == 1 && $1 =~ ^127\.0\.0\.1:([1-9][0-9]{0,4})$ ]] || { echo 'usage: configure-asterisk-user-hep.sh 127.0.0.1:' >&2; exit 2; } port=${BASH_REMATCH[1]} (( 10#$port <= 65535 )) || { echo 'invalid HEP port' >&2; exit 2; } config="$HOME/.config/go-sip-asterisk" [[ -d $config && -r $config/asterisk.conf ]] || { echo 'user Asterisk config missing; fail-closed' >&2; exit 1; } [[ ! -e $config/hep.conf && ! -L $config/hep.conf ]] || { echo 'HEP config already exists; refuse to overwrite' >&2; exit 1; } umask 077 stage=$(mktemp "$config/.hep.XXXXXXXX") trap 'rm -f -- "$stage"' EXIT printf '[general]\nenabled = yes\ncapture_address = %s\ncapture_id = 1234\nuuid_type = call-id\n' "$1" >"$stage" ln -- "$stage" "$config/hep.conf" || { echo 'cannot create HEP config without overwriting another file' >&2; exit 1; } echo 'Asterisk local HEP mirror configured; service not restarted'