forked from curly60e/pyblock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
Β·101 lines (91 loc) Β· 3.17 KB
/
Copy pathentrypoint.sh
File metadata and controls
executable file
Β·101 lines (91 loc) Β· 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
set -e
CONFIG_DIR="/app/pyblock/pybitblock/config"
mkdir -p "$CONFIG_DIR"
# Fail fast with a clear message if the config dir is not writable. This is
# almost always a UID mismatch between the host bind-mount owner and the
# container user (Umbrel forces `user: "1000:1000"`).
if ! touch "$CONFIG_DIR/.writetest" 2>/dev/null; then
echo "[PyBLOCK] FATAL: cannot write to $CONFIG_DIR" >&2
echo "[PyBLOCK] The bind-mounted host directory must be writable by UID $(id -u):$(id -g)." >&2
echo "[PyBLOCK] On Umbrel, ensure \${APP_DATA_DIR}/data/config is owned by 1000:1000." >&2
ls -ld "$CONFIG_DIR" >&2 || true
exit 1
fi
rm -f "$CONFIG_DIR/.writetest"
# Auto-generate Bitcoin config from env vars if set
if [ -n "$BITCOIN_RPC_HOST" ] && [ -n "$BITCOIN_RPC_USER" ]; then
BITCOIN_RPC_PORT="${BITCOIN_RPC_PORT:-8332}"
cat > "$CONFIG_DIR/bclock.conf" <<BTCEOF
{
"ip_port": "http://${BITCOIN_RPC_HOST}:${BITCOIN_RPC_PORT}",
"rpcuser": "${BITCOIN_RPC_USER}",
"rpcpass": "${BITCOIN_RPC_PASS}",
"bitcoincli": "${BITCOIN_CLI_PATH:-}"
}
BTCEOF
echo "[PyBLOCK] Bitcoin RPC configured: ${BITCOIN_RPC_HOST}:${BITCOIN_RPC_PORT}"
fi
# Auto-generate LND config from env vars if set
if [ -n "$LND_HOST" ] || [ -n "$LND_TLS_CERT_PATH" ]; then
LND_GRPC_PORT="${LND_GRPC_PORT:-10009}"
# Only build ip_port if LND_HOST is set (matches Python _env_lnd_config)
if [ -n "$LND_HOST" ]; then
LND_IP_PORT="${LND_HOST}:${LND_GRPC_PORT}"
else
LND_IP_PORT=""
fi
cat > "$CONFIG_DIR/blndconnect.conf" <<LNDEOF
{
"ip_port": "${LND_IP_PORT}",
"tls": "${LND_TLS_CERT_PATH:-}",
"macaroon": "${LND_MACAROON_PATH:-}",
"ln": "${LND_CLI_PATH:-}"
}
LNDEOF
echo "[PyBLOCK] LND configured: ${LND_IP_PORT:-local paths only}"
fi
# Auto-set mode if specified (PYBLOCK_MODE always overwrites)
PYBLOCK_MODE="${PYBLOCK_MODE:-}"
if [ -n "$PYBLOCK_MODE" ]; then
echo "\"${PYBLOCK_MODE}\"" > "$CONFIG_DIR/intro.conf"
echo "[PyBLOCK] Mode set to: ${PYBLOCK_MODE}"
elif [ -n "$BITCOIN_RPC_HOST" ] && [ ! -f "$CONFIG_DIR/intro.conf" ]; then
# Auto-detect mode from available env vars
if [ -n "$LND_HOST" ] || [ -n "$LND_TLS_CERT_PATH" ]; then
echo '"A"' > "$CONFIG_DIR/intro.conf"
echo "[PyBLOCK] Auto-detected mode: A (Bitcoin + Lightning)"
else
echo '"B"' > "$CONFIG_DIR/intro.conf"
echo "[PyBLOCK] Auto-detected mode: B (Bitcoin Only)"
fi
fi
# Generate default settings if missing
if [ ! -f "$CONFIG_DIR/pyblocksettings.conf" ]; then
cat > "$CONFIG_DIR/pyblocksettings.conf" <<SEOF
{
"gradient": "",
"design": "block",
"colorA": "green",
"colorB": "yellow"
}
SEOF
fi
if [ ! -f "$CONFIG_DIR/pyblocksettingsClock.conf" ]; then
cat > "$CONFIG_DIR/pyblocksettingsClock.conf" <<SCEOF
{
"gradient": "",
"colorA": "green",
"colorB": "yellow"
}
SCEOF
fi
echo "[PyBLOCK] Starting..."
# Ensure UTF-8 for all terminal output (ttyd, AI responses, etc.)
export LANG="${LANG:-C.UTF-8}"
export LC_ALL="${LC_ALL:-C.UTF-8}"
export PYTHONIOENCODING=utf-8
# Launch PyBLOCK via ttyd
exec ttyd -W -p "${PYBLOCK_PORT:-6969}" \
${PYBLOCK_TTYD_AUTH:+-c "$PYBLOCK_TTYD_AUTH"} \
python3 /app/pyblock/pybitblock/PyBlock.py "$@"