update install script
Some checks failed
CI / test-build (push) Has been cancelled

This commit is contained in:
2025-12-16 00:58:02 +07:00
parent e1a66dc7df
commit f1a344bf6a
3 changed files with 218 additions and 1 deletions

View File

@@ -785,6 +785,75 @@ MAINGO
echo " Global commands: atlas-api, atlas-tui"
}
# Copy web files (templates and static assets)
copy_web_files() {
echo -e "${GREEN}Copying web files...${NC}"
# Use BUILD_DIR from build_binaries if available, otherwise detect it
local source_dir=""
# Function to check if directory is valid repo root
is_repo_root() {
local dir="$1"
[[ -f "$dir/go.mod" ]] && [[ -d "$dir/internal" ]]
}
# Try REPO_DIR first
if [[ -n "$REPO_DIR" ]] && is_repo_root "$REPO_DIR"; then
source_dir="$(cd "$REPO_DIR" && pwd)"
# Try REPO_ROOT (if script is in installer/ subdirectory)
elif [[ -n "$REPO_ROOT" ]] && is_repo_root "$REPO_ROOT"; then
source_dir="$REPO_ROOT"
# Try current directory
elif is_repo_root "."; then
source_dir="$(pwd)"
# Try script directory
elif is_repo_root "$SCRIPT_DIR"; then
source_dir="$SCRIPT_DIR"
# Try parent of script directory
elif is_repo_root "$SCRIPT_DIR/.."; then
source_dir="$(cd "$SCRIPT_DIR/.." && pwd)"
fi
if [[ -z "$source_dir" ]]; then
echo -e "${YELLOW}Warning: Cannot find repository root, skipping web files copy${NC}"
echo " Templates and static files may not be available"
return
fi
# Check if web/templates exists
if [[ ! -d "$source_dir/web/templates" ]]; then
echo -e "${YELLOW}Warning: web/templates directory not found in $source_dir${NC}"
echo " Templates may not be available"
else
# Create web directories in install directory
mkdir -p "$INSTALL_DIR/web/templates"
mkdir -p "$INSTALL_DIR/web/static"
# Copy templates
echo " Copying templates from $source_dir/web/templates..."
cp -r "$source_dir/web/templates"/* "$INSTALL_DIR/web/templates/" 2>/dev/null || {
echo -e "${YELLOW}Warning: Failed to copy some template files${NC}"
}
# Copy static files if they exist
if [[ -d "$source_dir/web/static" ]]; then
echo " Copying static files from $source_dir/web/static..."
cp -r "$source_dir/web/static"/* "$INSTALL_DIR/web/static/" 2>/dev/null || {
echo -e "${YELLOW}Warning: Failed to copy some static files${NC}"
}
fi
# Set ownership
chown -R "$SERVICE_USER:$SERVICE_USER" "$INSTALL_DIR/web"
chmod -R 755 "$INSTALL_DIR/web"
echo -e "${GREEN}Web files copied successfully${NC}"
echo " Templates: $INSTALL_DIR/web/templates"
echo " Static: $INSTALL_DIR/web/static"
fi
}
# Create systemd service
create_systemd_service() {
echo -e "${GREEN}Creating systemd service...${NC}"
@@ -1244,6 +1313,9 @@ main() {
# Step 6: Build binaries
build_binaries
# Step 6.5: Copy web files (templates and static assets)
copy_web_files
# Step 7: Create configuration
create_config
generate_jwt_secret