Compare commits
2 Commits
d1f04b8b5e
...
7d81e7aff3
| Author | SHA1 | Date |
|---|---|---|
|
|
7d81e7aff3 | |
|
|
e3b86d6b4e |
|
|
@ -23,26 +23,44 @@ if [[ "$UBUNTU_MAJOR" != "22" ]]; then
|
|||
fi
|
||||
|
||||
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
BACKEND_ROOT=$(cd "$SCRIPT_DIR/.." && pwd)
|
||||
PROJECT_ROOT=$(cd "$BACKEND_ROOT/.." && pwd)
|
||||
if [[ -d "$SCRIPT_DIR/../app" && -d "$SCRIPT_DIR/../scripts" ]]; then
|
||||
DEFAULT_INSTALL_ROOT=$(cd "$SCRIPT_DIR/../.." && pwd)
|
||||
else
|
||||
DEFAULT_INSTALL_ROOT="/home/my-network"
|
||||
fi
|
||||
|
||||
read -r -p "Installation root [$DEFAULT_INSTALL_ROOT]: " INSTALL_ROOT || true
|
||||
INSTALL_ROOT=${INSTALL_ROOT:-$DEFAULT_INSTALL_ROOT}
|
||||
INSTALL_ROOT=${INSTALL_ROOT%/}
|
||||
if [[ -z "$INSTALL_ROOT" ]]; then
|
||||
INSTALL_ROOT="/home/my-network"
|
||||
fi
|
||||
mkdir -p "$INSTALL_ROOT"
|
||||
INSTALL_ROOT=$(cd "$INSTALL_ROOT" && pwd)
|
||||
|
||||
echo "Using installation root: $INSTALL_ROOT"
|
||||
|
||||
PROJECT_ROOT="$INSTALL_ROOT"
|
||||
BACKEND_ROOT="$PROJECT_ROOT/uploader-bot"
|
||||
CONFIGS_DIR="$PROJECT_ROOT/configs"
|
||||
FRONTEND_DIR="$PROJECT_ROOT/web2-client"
|
||||
|
||||
if [[ ! -d "$CONFIGS_DIR" ]]; then
|
||||
echo "Expected configs directory at $CONFIGS_DIR." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -f "$CONFIGS_DIR/docker-compose.yml" ]]; then
|
||||
echo "Missing docker-compose.yml in $CONFIGS_DIR." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -d "$FRONTEND_DIR" ]]; then
|
||||
echo "Warning: web2-client directory not found at $FRONTEND_DIR (frontend build will fail)." >&2
|
||||
fi
|
||||
|
||||
ENV_FILE="$CONFIGS_DIR/.env"
|
||||
ENV_EXAMPLE="$BACKEND_ROOT/env.example"
|
||||
|
||||
DEFAULT_BACKEND_REMOTE="https://git.projscale.dev/my-dev/uploader-bot"
|
||||
if [[ -d "$BACKEND_ROOT/.git" ]]; then
|
||||
DEFAULT_BACKEND_REMOTE=$(git -C "$BACKEND_ROOT" config --get remote.origin.url 2>/dev/null || echo "$DEFAULT_BACKEND_REMOTE")
|
||||
fi
|
||||
DEFAULT_CONFIGS_REMOTE="https://git.projscale.dev/my-dev/configs"
|
||||
if [[ -d "$CONFIGS_DIR/.git" ]]; then
|
||||
DEFAULT_CONFIGS_REMOTE=$(git -C "$CONFIGS_DIR" config --get remote.origin.url 2>/dev/null || echo "$DEFAULT_CONFIGS_REMOTE")
|
||||
fi
|
||||
DEFAULT_WEB2_REMOTE="https://git.projscale.dev/my-dev/web2-client"
|
||||
if [[ -d "$FRONTEND_DIR/.git" ]]; then
|
||||
DEFAULT_WEB2_REMOTE=$(git -C "$FRONTEND_DIR" config --get remote.origin.url 2>/dev/null || echo "$DEFAULT_WEB2_REMOTE")
|
||||
fi
|
||||
|
||||
trim() {
|
||||
local val="$1"
|
||||
val="${val#${val%%[![:space:]]*}}"
|
||||
|
|
@ -69,6 +87,41 @@ update_env() {
|
|||
echo "${key}=${value}" >> "$ENV_FILE"
|
||||
}
|
||||
|
||||
RUN_USER=${SUDO_USER:-$(logname 2>/dev/null || echo root)}
|
||||
if ! id -u "$RUN_USER" >/dev/null 2>&1; then
|
||||
RUN_USER=root
|
||||
fi
|
||||
RUN_GROUP=$(id -gn "$RUN_USER" 2>/dev/null || echo $RUN_USER)
|
||||
|
||||
ensure_repo() {
|
||||
local dir="$1"
|
||||
local default_url="$2"
|
||||
local label="$3"
|
||||
|
||||
if [[ -d "$dir/.git" ]]; then
|
||||
return
|
||||
fi
|
||||
if [[ -d "$dir" && ! -d "$dir/.git" ]]; then
|
||||
echo "Found existing $label directory at $dir without git metadata." >&2
|
||||
read -r -p "Use the existing directory as-is? [y/N]: " reuse || true
|
||||
reuse=${reuse:-N}
|
||||
if [[ ! $reuse =~ ^[Yy]$ ]]; then
|
||||
echo "Please remove or move $dir and rerun the script." >&2
|
||||
exit 1
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
read -r -p "Git URL for $label repository [$default_url]: " repo_url || true
|
||||
repo_url=${repo_url:-$default_url}
|
||||
mkdir -p "$(dirname "$dir")"
|
||||
if ! git clone "$repo_url" "$dir"; then
|
||||
echo "Failed to clone $label repository from $repo_url" >&2
|
||||
exit 1
|
||||
fi
|
||||
chown -R "$RUN_USER:$RUN_GROUP" "$dir" || true
|
||||
}
|
||||
|
||||
prompt_required() {
|
||||
local var="$1"
|
||||
local label="$2"
|
||||
|
|
@ -105,6 +158,15 @@ prompt_optional() {
|
|||
printf -v "$var" '%s' "$value"
|
||||
}
|
||||
|
||||
# Install base dependencies
|
||||
apt-get update -y
|
||||
apt-get install -y ca-certificates curl gnupg apt-transport-https software-properties-common git make nginx certbot python3-certbot-nginx python3 jq openssl
|
||||
|
||||
# Ensure repository checkouts
|
||||
ensure_repo "$BACKEND_ROOT" "$DEFAULT_BACKEND_REMOTE" "uploader-bot"
|
||||
ensure_repo "$CONFIGS_DIR" "$DEFAULT_CONFIGS_REMOTE" "configs"
|
||||
ensure_repo "$FRONTEND_DIR" "$DEFAULT_WEB2_REMOTE" "web2-client"
|
||||
|
||||
# Prepare environment file
|
||||
if [[ ! -f "$ENV_FILE" ]]; then
|
||||
echo "Creating $ENV_FILE from example template." >&2
|
||||
|
|
@ -117,10 +179,7 @@ if [[ ! -f "$ENV_FILE" ]]; then
|
|||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Install base dependencies
|
||||
apt-get update -y
|
||||
apt-get install -y ca-certificates curl gnupg apt-transport-https software-properties-common git make nginx certbot python3-certbot-nginx python3 jq openssl
|
||||
chown "$RUN_USER:$RUN_GROUP" "$ENV_FILE" || true
|
||||
|
||||
# Docker repository setup
|
||||
install -m 0755 -d /etc/apt/keyrings
|
||||
|
|
@ -391,3 +450,4 @@ echo "\nNode provisioning complete."
|
|||
echo "- Admin panel: ${PUBLIC_HOST}/admin (use ADMIN_API_TOKEN)"
|
||||
echo "- To trust this node on peers, mark it via admin API on existing node."
|
||||
echo "- Docker services: run 'docker ps -a' or 'make -C $CONFIGS_DIR ps'."
|
||||
echo "- Installation root: $PROJECT_ROOT"
|
||||
|
|
|
|||
Loading…
Reference in New Issue