Update setup script to use bbctl auto-discovery
This commit is contained in:
@@ -31,20 +31,75 @@ mkdir -p "$DATA_DIR"
|
|||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "--- 1. Beeper Registration ---"
|
echo "--- 1. Beeper Registration ---"
|
||||||
echo "Please run 'bbctl register sh-$BRIDGE_SERVICE' on your machine (or retrieve existing values)."
|
|
||||||
echo "Enter the values below:"
|
|
||||||
|
|
||||||
read -p "ID (e.g., 99ab27...): " REG_ID
|
# Try auto-discovery via bbctl
|
||||||
|
if command -v bbctl &> /dev/null; then
|
||||||
|
echo "Found 'bbctl'. Attempting to fetch registration automatically..."
|
||||||
|
|
||||||
|
# Run bbctl and capture output. We need to filter out the "You already have..." text.
|
||||||
|
# Usually the YAML starts with "id:". We try to grep from "id:" down.
|
||||||
|
BBCTL_OUT=$(bbctl register "sh-$BRIDGE_SERVICE" 2>&1)
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
# Extract YAML: Find line starting with "id:" and everything after
|
||||||
|
YAML_CONTENT=$(echo "$BBCTL_OUT" | sed -n '/^id:/,$p')
|
||||||
|
|
||||||
|
if [ ! -z "$YAML_CONTENT" ]; then
|
||||||
|
echo "$YAML_CONTENT" > "$REG_FILE"
|
||||||
|
echo "Successfully saved registration to $REG_FILE"
|
||||||
|
|
||||||
|
# Now we need to parse values from this file to populate config variables
|
||||||
|
# We use python one-liner to extract vars
|
||||||
|
echo "Extracting tokens..."
|
||||||
|
|
||||||
|
eval $(docker run --rm -v "$(pwd)/$REG_FILE:/reg.yaml" python:3.11-slim python -c "
|
||||||
|
import yaml # PyYAML is standard in some images, but if not we might need manual parsing or install
|
||||||
|
try:
|
||||||
|
import yaml
|
||||||
|
except ImportError:
|
||||||
|
# Fallback: simple line parsing if yaml module missing in minimal image (though python:3.11-slim usually needs pip install)
|
||||||
|
# Let's just do manual parsing to be safe and fast without network
|
||||||
|
d = {}
|
||||||
|
with open('/reg.yaml') as f:
|
||||||
|
for line in f:
|
||||||
|
if ':' in line:
|
||||||
|
k,v = line.split(':', 1)
|
||||||
|
d[k.strip()] = v.strip()
|
||||||
|
print(f'REG_ID={d.get(\"id\", \"\")}')
|
||||||
|
print(f'AS_TOKEN={d.get(\"as_token\", \"\")}')
|
||||||
|
print(f'HS_TOKEN={d.get(\"hs_token\", \"\")}')
|
||||||
|
print(f'BOT_USERNAME={d.get(\"sender_localpart\", \"\")}')
|
||||||
|
")
|
||||||
|
else
|
||||||
|
echo "Could not parse YAML from bbctl output. Falling back to manual input."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "bbctl failed. Falling back to manual input."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "bbctl not found in PATH. Falling back to manual input."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Fallback prompts if variables are still empty
|
||||||
|
if [ -z "$REG_ID" ]; then
|
||||||
|
echo "Manual Input Required:"
|
||||||
|
read -p "ID (e.g., 99ab27...): " REG_ID
|
||||||
|
fi
|
||||||
while [[ -z "$REG_ID" ]]; do read -p "ID cannot be empty: " REG_ID; done
|
while [[ -z "$REG_ID" ]]; do read -p "ID cannot be empty: " REG_ID; done
|
||||||
|
|
||||||
read -p "AS Token (e.g., Agqb...): " AS_TOKEN
|
if [ -z "$AS_TOKEN" ]; then
|
||||||
|
read -p "AS Token (e.g., Agqb...): " AS_TOKEN
|
||||||
|
fi
|
||||||
while [[ -z "$AS_TOKEN" ]]; do read -p "AS Token cannot be empty: " AS_TOKEN; done
|
while [[ -z "$AS_TOKEN" ]]; do read -p "AS Token cannot be empty: " AS_TOKEN; done
|
||||||
|
|
||||||
read -p "HS Token (e.g., bR5t...): " HS_TOKEN
|
if [ -z "$HS_TOKEN" ]; then
|
||||||
|
read -p "HS Token (e.g., bR5t...): " HS_TOKEN
|
||||||
|
fi
|
||||||
while [[ -z "$HS_TOKEN" ]]; do read -p "HS Token cannot be empty: " HS_TOKEN; done
|
while [[ -z "$HS_TOKEN" ]]; do read -p "HS Token cannot be empty: " HS_TOKEN; done
|
||||||
|
|
||||||
# Default Beeper values (can be overridden but we default to what we saw in logs)
|
# Default Beeper values (can be overridden but we default to what we saw in logs)
|
||||||
DEFAULT_HS_URL="https://matrix.beeper.com/_hungryserv/inswe"
|
DEFAULT_HS_URL="https://matrix.beeper.com/_hungryserv/inswe"
|
||||||
|
# Try to extract HS URL from bbctl output if possible, otherwise default
|
||||||
read -p "Homeserver URL [$DEFAULT_HS_URL]: " HS_URL
|
read -p "Homeserver URL [$DEFAULT_HS_URL]: " HS_URL
|
||||||
HS_URL=${HS_URL:-$DEFAULT_HS_URL}
|
HS_URL=${HS_URL:-$DEFAULT_HS_URL}
|
||||||
|
|
||||||
@@ -56,9 +111,11 @@ DEFAULT_USER="@inswe:beeper.com"
|
|||||||
read -p "Your Admin User ID [$DEFAULT_USER]: " ADMIN_USER
|
read -p "Your Admin User ID [$DEFAULT_USER]: " ADMIN_USER
|
||||||
ADMIN_USER=${ADMIN_USER:-$DEFAULT_USER}
|
ADMIN_USER=${ADMIN_USER:-$DEFAULT_USER}
|
||||||
|
|
||||||
DEFAULT_BOT="sh-${BRIDGE_SERVICE}bot"
|
if [ -z "$BOT_USERNAME" ]; then
|
||||||
read -p "Bot Username (Localpart) [$DEFAULT_BOT]: " BOT_USERNAME
|
DEFAULT_BOT="sh-${BRIDGE_SERVICE}bot"
|
||||||
BOT_USERNAME=${BOT_USERNAME:-$DEFAULT_BOT}
|
read -p "Bot Username (Localpart) [$DEFAULT_BOT]: " BOT_USERNAME
|
||||||
|
BOT_USERNAME=${BOT_USERNAME:-$DEFAULT_BOT}
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
Reference in New Issue
Block a user