fix start sh

This commit is contained in:
user 2025-09-13 20:30:50 +03:00
parent 4ed7eae715
commit 37331e7d97
1 changed files with 30 additions and 28 deletions

View File

@ -3,8 +3,10 @@ set -euo pipefail
echo "MY Network Node setup (interactive)"
ENV_FILE=".env"
EXAMPLE_FILE=".env.example"
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
BASE_DIR="$SCRIPT_DIR/.."
ENV_FILE="$BASE_DIR/.env"
EXAMPLE_FILE="$BASE_DIR/.env.example"
if [[ ! -f "$ENV_FILE" ]]; then
if [[ -f "$EXAMPLE_FILE" ]]; then
@ -25,27 +27,27 @@ fi
if [[ "$NODE_PRIVACY" == "private" ]]; then
read -rp "Public host URL (leave empty for private): " PUBLIC_HOST || true
else
read -rp "Public host URL (e.g., https://node.example.com) [$(grep -E '^PUBLIC_HOST=' "$ENV_FILE" | cut -d'=' -f2)]: " PUBLIC_HOST
PUBLIC_HOST=${PUBLIC_HOST:-$(grep -E '^PUBLIC_HOST=' "$ENV_FILE" | cut -d'=' -f2)}
read -rp "Public host URL (e.g., https://node.example.com) [$(grep -E '^PUBLIC_HOST=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2)]: " PUBLIC_HOST || true
PUBLIC_HOST=${PUBLIC_HOST:-$(grep -E '^PUBLIC_HOST=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2)}
fi
read -rp "Internal app port (SANIC_PORT) [$(grep -E '^SANIC_PORT=' "$ENV_FILE" | cut -d'=' -f2)]: " SANIC_PORT
SANIC_PORT=${SANIC_PORT:-$(grep -E '^SANIC_PORT=' "$ENV_FILE" | cut -d'=' -f2)}
read -rp "Internal app port (SANIC_PORT) [$(grep -E '^SANIC_PORT=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2)]: " SANIC_PORT || true
SANIC_PORT=${SANIC_PORT:-$(grep -E '^SANIC_PORT=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2)}
read -rp "Published backend port on host (BACKEND_HTTP_PORT) [$(grep -E '^BACKEND_HTTP_PORT=' "$ENV_FILE" | cut -d'=' -f2)]: " BACKEND_HTTP_PORT
BACKEND_HTTP_PORT=${BACKEND_HTTP_PORT:-$(grep -E '^BACKEND_HTTP_PORT=' "$ENV_FILE" | cut -d'=' -f2)}
read -rp "Published backend port on host (BACKEND_HTTP_PORT) [$(grep -E '^BACKEND_HTTP_PORT=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2)]: " BACKEND_HTTP_PORT || true
BACKEND_HTTP_PORT=${BACKEND_HTTP_PORT:-$(grep -E '^BACKEND_HTTP_PORT=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2)}
read -rp "Bootstrap seeds (comma-separated URLs) [$(grep -E '^BOOTSTRAP_SEEDS=' "$ENV_FILE" | cut -d'=' -f2)]: " BOOTSTRAP_SEEDS
BOOTSTRAP_SEEDS=${BOOTSTRAP_SEEDS:-$(grep -E '^BOOTSTRAP_SEEDS=' "$ENV_FILE" | cut -d'=' -f2)}
read -rp "Bootstrap seeds (comma-separated URLs) [$(grep -E '^BOOTSTRAP_SEEDS=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2)]: " BOOTSTRAP_SEEDS || true
BOOTSTRAP_SEEDS=${BOOTSTRAP_SEEDS:-$(grep -E '^BOOTSTRAP_SEEDS=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2)}
read -rp "Handshake interval seconds [$(grep -E '^HANDSHAKE_INTERVAL_SEC=' "$ENV_FILE" | cut -d'=' -f2)]: " HANDSHAKE_INTERVAL_SEC
HANDSHAKE_INTERVAL_SEC=${HANDSHAKE_INTERVAL_SEC:-$(grep -E '^HANDSHAKE_INTERVAL_SEC=' "$ENV_FILE" | cut -d'=' -f2)}
read -rp "Handshake interval seconds [$(grep -E '^HANDSHAKE_INTERVAL_SEC=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2)]: " HANDSHAKE_INTERVAL_SEC || true
HANDSHAKE_INTERVAL_SEC=${HANDSHAKE_INTERVAL_SEC:-$(grep -E '^HANDSHAKE_INTERVAL_SEC=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2)}
read -rp "Telegram uploader bot token (TELEGRAM_API_KEY) [$(grep -E '^TELEGRAM_API_KEY=' "$ENV_FILE" | cut -d'=' -f2)]: " TELEGRAM_API_KEY
TELEGRAM_API_KEY=${TELEGRAM_API_KEY:-$(grep -E '^TELEGRAM_API_KEY=' "$ENV_FILE" | cut -d'=' -f2)}
read -rp "Telegram uploader bot token (TELEGRAM_API_KEY) [$(grep -E '^TELEGRAM_API_KEY=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2)]: " TELEGRAM_API_KEY || true
TELEGRAM_API_KEY=${TELEGRAM_API_KEY:-$(grep -E '^TELEGRAM_API_KEY=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2)}
read -rp "Telegram client bot token (CLIENT_TELEGRAM_API_KEY) [$(grep -E '^CLIENT_TELEGRAM_API_KEY=' "$ENV_FILE" | cut -d'=' -f2)]: " CLIENT_TELEGRAM_API_KEY
CLIENT_TELEGRAM_API_KEY=${CLIENT_TELEGRAM_API_KEY:-$(grep -E '^CLIENT_TELEGRAM_API_KEY=' "$ENV_FILE" | cut -d'=' -f2)}
read -rp "Telegram client bot token (CLIENT_TELEGRAM_API_KEY) [$(grep -E '^CLIENT_TELEGRAM_API_KEY=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2)]: " CLIENT_TELEGRAM_API_KEY || true
CLIENT_TELEGRAM_API_KEY=${CLIENT_TELEGRAM_API_KEY:-$(grep -E '^CLIENT_TELEGRAM_API_KEY=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2)}
echo "Applying configuration to $ENV_FILE ..."
@ -72,15 +74,15 @@ update_env TELEGRAM_API_KEY "$TELEGRAM_API_KEY"
update_env CLIENT_TELEGRAM_API_KEY "$CLIENT_TELEGRAM_API_KEY"
# Ensure IPFS swarm key exists for private swarm by default
SWARM_KEY_FILE_DEFAULT="./configs/ipfs/swarm.key"
SWARM_KEY_FILE_DEFAULT="$BASE_DIR/configs/ipfs/swarm.key"
if [[ ! -f "$SWARM_KEY_FILE_DEFAULT" ]]; then
echo "Generating IPFS private swarm key at $SWARM_KEY_FILE_DEFAULT ..."
mkdir -p "$(dirname "$SWARM_KEY_FILE_DEFAULT")"
KEYHEX=$(python3 - <<'PY'
import os, binascii
print(binascii.b2a_hex(os.urandom(32)).decode())
PY
)
if command -v openssl >/dev/null 2>&1; then
KEYHEX=$(openssl rand -hex 32)
else
KEYHEX=$(head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n')
fi
cat > "$SWARM_KEY_FILE_DEFAULT" <<EOF
/key/swarm/psk/1.0.0/
/base16/
@ -90,9 +92,9 @@ fi
update_env IPFS_SWARM_KEY_FILE "$SWARM_KEY_FILE_DEFAULT"
# Ensure data directories exist
mkdir -p ./data/ipfs ./data/tusd ./app-logs ./dynamicStorage
update_env IPFS_DATA_DIR_HOST "./data/ipfs"
update_env TUSD_DATA_DIR_HOST "./data/tusd"
mkdir -p "$BASE_DIR/data/ipfs" "$BASE_DIR/data/tusd" "$BASE_DIR/app-logs" "$BASE_DIR/dynamicStorage"
update_env IPFS_DATA_DIR_HOST "$BASE_DIR/data/ipfs"
update_env TUSD_DATA_DIR_HOST "$BASE_DIR/data/tusd"
if ! grep -qE '^IPFS_GATEWAY_BIND=' "$ENV_FILE"; then
update_env IPFS_GATEWAY_BIND "0.0.0.0"
fi
@ -104,7 +106,7 @@ else
fi
fi
echo "Config written. Starting containers..."
echo "Config written to $ENV_FILE. Starting containers..."
if ! command -v docker >/dev/null 2>&1; then
echo "Docker is required. Please install Docker and retry." >&2
@ -118,9 +120,9 @@ fi
set -x
if command -v docker compose >/dev/null 2>&1; then
docker compose up -d --build
(cd "$BASE_DIR" && docker compose up -d --build)
else
docker-compose up -d --build
(cd "$BASE_DIR" && docker-compose up -d --build)
fi
set +x