Format the bash script

This commit is contained in:
Jared Miller 2026-02-26 09:37:20 -05:00
parent 8ad02453a7
commit 087d6fbc55
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -29,7 +29,6 @@ NONCE_LOG_FILE="$DATA_DIR/run/nonces_$$"
AUTO_LISTEN_FLAG="$DATA_DIR/run/autolisten_$$"
AUTO_LISTEN_PID=""
# Defaults
LISTEN_PORT=7777
TOR_SOCKS_PORT=9050
@ -450,15 +449,12 @@ install_snowflake() {
fi
}
start_tor() {
if [ -n "$TOR_PID" ] && kill -0 "$TOR_PID" 2>/dev/null; then
log_info "Tor is already running (PID $TOR_PID)"
return 0
fi
setup_tor
# Clear old log so we only see fresh output
@ -642,8 +638,8 @@ get_circuit_hops() {
# Find best BUILT circuit — prefer HS circuits
local circuit_line
circuit_line=$(echo "$circ_resp" | grep " BUILT " \
| grep -E "PURPOSE=HS_SERVICE_INTRO|PURPOSE=HS_CLIENT_REND" | head -1) || true
circuit_line=$(echo "$circ_resp" | grep " BUILT " |
grep -E "PURPOSE=HS_SERVICE_INTRO|PURPOSE=HS_CLIENT_REND" | head -1) || true
[ -z "$circuit_line" ] && circuit_line=$(echo "$circ_resp" | grep " BUILT " | head -1)
[ -z "$circuit_line" ] && return 1
@ -658,9 +654,11 @@ get_circuit_hops() {
for r in "${relays[@]}"; do
local name fp
if [[ "$r" == *"~"* ]]; then
name="${r#*~}"; fp="${r%%~*}"
name="${r#*~}"
fp="${r%%~*}"
else
name="${r:0:8}..."; fp="$r"
name="${r:0:8}..."
fp="$r"
fi
names+=("$name")
fps+=("${fp#\$}")
@ -774,7 +772,6 @@ set_shared_secret() {
log_ok "Shared secret saved"
}
# Encrypt a file
encrypt_file() {
local infile="$1" outfile="$2"
@ -1012,25 +1009,21 @@ audio_play() {
fi
}
# Play an opus file
play_chunk() {
local opus_file="$1"
if [ $IS_TERMUX -eq 1 ]; then
# Termux: pipe decode directly to sox play (avoids temp file + Android media framework)
opusdec --quiet --rate 48000 "$opus_file" - 2>/dev/null | \
opusdec --quiet --rate 48000 "$opus_file" - 2>/dev/null |
play -q -t raw -r 48000 -e signed -b 16 -c 1 - 2>/dev/null || true
else
# Linux: pipe decode directly to aplay
opusdec --quiet --rate 48000 "$opus_file" - 2>/dev/null | \
opusdec --quiet --rate 48000 "$opus_file" - 2>/dev/null |
aplay -f S16_LE -r 48000 -c 1 -q 2>/dev/null || true
fi
}
#=============================================================================
# CALL CLEANUP — RESET EVERYTHING TO FRESH STATE
#=============================================================================
@ -1161,9 +1154,9 @@ start_vol_monitor() {
while [ -f "$CONNECTED_FLAG" ]; do
local cur_vol
cur_vol=$(termux-volume 2>/dev/null \
| jq -r '.[] | select(.stream=="music") | .volume' 2>/dev/null \
|| echo "")
cur_vol=$(termux-volume 2>/dev/null |
jq -r '.[] | select(.stream=="music") | .volume' 2>/dev/null ||
echo "")
# Remember the initial volume so we can restore after detection
if [ -n "$cur_vol" ] && [ -z "$restore_vol" ]; then
@ -1424,8 +1417,10 @@ draw_call_header() {
# Snowflake bridge info
if [ "$SNOWFLAKE_ENABLED" -eq 1 ]; then
local tor_log="$TOR_DIR/tor.log"
echo "" >&2; _r=$((_r + 1))
echo -e " ${TOR_PURPLE}${NC} ${BOLD}Snowflake bridge${NC}" >&2; _r=$((_r + 1))
echo "" >&2
_r=$((_r + 1))
echo -e " ${TOR_PURPLE}${NC} ${BOLD}Snowflake bridge${NC}" >&2
_r=$((_r + 1))
if [ -f "$tor_log" ]; then
local bridge_line=""
bridge_line=$(grep "new bridge descriptor" "$tor_log" 2>/dev/null | tail -1 || true)
@ -1463,8 +1458,10 @@ draw_call_header() {
local _hop_data
_hop_data=$(get_circuit_hops 2>/dev/null) || true
if [ -n "$_hop_data" ]; then
echo "" >&2; _r=$((_r + 1))
echo -e " ${TOR_PURPLE}${NC} ${BOLD}Circuit${NC}" >&2; _r=$((_r + 1))
echo "" >&2
_r=$((_r + 1))
echo -e " ${TOR_PURPLE}${NC} ${BOLD}Circuit${NC}" >&2
_r=$((_r + 1))
CIRCUIT_START_ROW=$_r
local _hop_i=0 _hop_total
_hop_total=$(echo "$_hop_data" | wc -l)
@ -1480,7 +1477,8 @@ draw_call_header() {
fi
fi
echo "" >&2; _r=$((_r + 1))
echo "" >&2
_r=$((_r + 1))
# Static placeholders — updated in-place via ANSI positioning
echo -e " ${DIM}Last sent: --${NC}" >&2
@ -1491,7 +1489,8 @@ draw_call_header() {
RECV_INFO_ROW=$_r
_r=$((_r + 1))
echo "" >&2; _r=$((_r + 1))
echo "" >&2
_r=$((_r + 1))
# Static status bar
if [ $IS_TERMUX -eq 1 ]; then
@ -1765,7 +1764,8 @@ in_call_session() {
# TERMUX: Toggle mode
if [ $ptt_active -eq 0 ]; then
ptt_active=1
printf '\033[s' >&2; printf '\033[%d;1H\033[K' "$STATUS_ROW" >&2
printf '\033[s' >&2
printf '\033[%d;1H\033[K' "$STATUS_ROW" >&2
printf ' \033[41;1;37m \u25cf RECORDING \033[0m \033[2m[SPACE]=Send\033[0m ' >&2
printf '\033[u' >&2
start_recording
@ -1785,7 +1785,8 @@ in_call_session() {
# LINUX: Hold-to-talk
if [ $ptt_active -eq 0 ]; then
ptt_active=1
printf '\033[s' >&2; printf '\033[%d;1H\033[K' "$STATUS_ROW" >&2
printf '\033[s' >&2
printf '\033[%d;1H\033[K' "$STATUS_ROW" >&2
printf ' \033[41;1;37;5m \u25cf RECORDING \033[0m ' >&2
printf '\033[u' >&2
stty time 5 # longer timeout to span keyboard repeat delay
@ -2251,8 +2252,7 @@ settings_cipher() {
0 | q | Q)
return
;;
'')
;;
'') ;;
*)
if [[ "$cinput" =~ ^[0-9]+$ ]] && [ "$cinput" -ge 1 ] && [ "$cinput" -le "$total" ]; then
local selected="${ciphers[$((cinput - 1))]}"
@ -2451,7 +2451,8 @@ settings_voice() {
4) VOICE_EFFECT="robot" ;;
5) VOICE_EFFECT="echo" ;;
6) VOICE_EFFECT="whisper" ;;
7) VOICE_EFFECT="custom"
7)
VOICE_EFFECT="custom"
settings_voice_custom
;;
0 | q | Q) return ;;
@ -2960,15 +2961,18 @@ main_menu() {
read -r
;;
4) set_shared_secret ;;
5) test_audio
5)
test_audio
echo -ne " ${DIM}Press Enter to continue...${NC}"
read -r
;;
6) show_status
6)
show_status
echo -ne " ${DIM}Press Enter to continue...${NC}"
read -r
;;
7) install_deps
7)
install_deps
echo -ne "\n ${DIM}Press Enter to continue...${NC}"
read -r
;;