Changed from user specific, to open for everyone

This commit is contained in:
Ace
2026-06-26 11:48:51 +02:00
parent 4c09635d30
commit da702d6beb
8 changed files with 269 additions and 4 deletions
+47
View File
@@ -0,0 +1,47 @@
import { execSync, spawn } from "node:child_process"
import { platform } from "node:os"
function isRunning() {
try {
if (platform() === "win32") {
execSync('tasklist /FI "IMAGENAME eq ollama.exe" 2>nul | findstr ollama', { stdio: "pipe", timeout: 3000 })
} else {
execSync('pgrep -x ollama', { stdio: "pipe", timeout: 3000 })
}
return true
} catch {
return false
}
}
function findOllama() {
if (platform() === "win32") {
try {
return execSync("where ollama", { encoding: "utf8", timeout: 3000 }).trim().split("\n")[0]
} catch {}
const local = `${process.env.LOCALAPPDATA}\\Programs\\Ollama\\ollama.exe`
const programFiles = `${process.env.PROGRAMFILES}\\Ollama\\ollama.exe`
if (local) try { execSync(`"${local}" --version`, { stdio: "ignore", timeout: 2000 }); return local } catch {}
if (programFiles) try { execSync(`"${programFiles}" --version`, { stdio: "ignore", timeout: 2000 }); return programFiles } catch {}
} else {
try { return execSync("which ollama", { encoding: "utf8", timeout: 3000 }).trim() } catch {}
}
return null
}
if (!isRunning()) {
const bin = findOllama()
if (!bin) {
console.error("Ollama not found. Install from https://ollama.com")
process.exit(1)
}
console.log("Starting Ollama...")
if (platform() === "win32") {
spawn(bin, ["serve"], { stdio: "ignore", detached: true, windowsHide: true }).unref()
} else {
spawn(bin, ["serve"], { stdio: "ignore", detached: true }).unref()
}
execSync("sleep 3", { stdio: "ignore", timeout: 5000 })
} else {
console.log("Ollama already running")
}
+23
View File
@@ -0,0 +1,23 @@
import { execSync } from "node:child_process"
import { platform } from "node:os"
const url = process.argv[2] || "http://localhost:3001/splash"
const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
async function main() {
await sleep(8000)
try {
if (platform() === "win32") {
execSync(`start "" "${url}"`, { stdio: "ignore", timeout: 5000 })
} else if (platform() === "darwin") {
execSync(`open "${url}"`, { stdio: "ignore", timeout: 5000 })
} else {
execSync(`xdg-open "${url}"`, { stdio: "ignore", timeout: 5000 })
}
} catch (e) {
console.error("Failed to open browser:", e.message)
}
}
main()
+30
View File
@@ -0,0 +1,30 @@
import { execSync } from "node:child_process"
import { platform } from "node:os"
const PORTS = [3001, 3006, 3007, 3008]
if (platform() === "win32") {
for (const port of PORTS) {
try {
const out = execSync(`netstat -ano | findstr "LISTENING" | findstr ":${port} "`, { encoding: "utf8", timeout: 5000 })
const lines = out.trim().split("\n").filter(Boolean)
for (const line of lines) {
const parts = line.trim().split(/\s+/)
const pid = parts[parts.length - 1]
if (pid) {
try { execSync(`taskkill /F /PID ${pid}`, { stdio: "ignore", timeout: 3000 }); console.log(`Freed port ${port} (PID ${pid})`) } catch {}
}
}
} catch {}
}
} else {
for (const port of PORTS) {
try {
const pid = execSync(`lsof -ti:${port} 2>/dev/null`, { encoding: "utf8", timeout: 5000 }).trim()
if (pid) {
execSync(`kill -9 ${pid}`, { stdio: "ignore", timeout: 3000 })
console.log(`Freed port ${port} (PID ${pid})`)
}
} catch {}
}
}
+27
View File
@@ -0,0 +1,27 @@
import { execSync, spawn } from "node:child_process"
import { platform } from "node:os"
function detectPython() {
const candidates = platform() === "win32" ? ["python", "python3"] : ["python3", "python"]
for (const cmd of candidates) {
try {
const out = execSync(platform() === "win32" ? `where ${cmd}` : `which ${cmd}`, { encoding: "utf8", timeout: 5000 })
const path = out.trim().split("\n")[0].replace(/\r$/, "")
if (path) return path
} catch {}
}
console.error("Python not found. Install Python 3 from https://python.org")
process.exit(1)
}
const PYTHON = detectPython()
const script = process.argv[2]
const args = process.argv.slice(3)
if (!script) {
console.error("Usage: node run-python.mjs <script> [args...]")
process.exit(1)
}
const proc = spawn(PYTHON, [script, ...args], { stdio: "inherit" })
proc.on("exit", (code) => process.exit(code ?? 1))
+69
View File
@@ -0,0 +1,69 @@
import { execSync } from "node:child_process"
import { existsSync, copyFileSync } from "node:fs"
import { platform } from "node:os"
const SEP = platform() === "win32" ? "&" : ";"
function detectPython() {
const candidates = platform() === "win32" ? ["python", "python3"] : ["python3", "python"]
for (const cmd of candidates) {
try {
execSync(`${cmd} --version`, { stdio: "pipe", timeout: 5000 })
return cmd
} catch {}
}
console.error("Python not found. Install Python 3 from https://python.org")
process.exit(1)
}
function detectPip(python) {
const candidates = platform() === "win32" ? ["pip", "pip3"] : ["pip3", "pip"]
for (const cmd of candidates) {
try {
execSync(`${cmd} --version`, { stdio: "pipe", timeout: 5000 })
return cmd
} catch {}
}
return `${python} -m pip`
}
const PY = detectPython()
const PIP = detectPip(PY)
function run(cmd, label) {
console.log(`\n── ${label} ──`)
try {
execSync(cmd, { stdio: "inherit", timeout: 120000 })
} catch (e) {
console.error(` ✗ Failed: ${e.message}`)
process.exit(1)
}
}
console.log("=== CoastIT CRM Setup ===\n")
// 1. Node dependencies
run("npm install", "Installing Node.js dependencies")
// 2. Python dependencies
run(`cd browser-use-service ${SEP} ${PIP} install -r requirements.txt`, "Installing Python dependencies")
// 3. Playwright browsers
run(`${PY} -m playwright install firefox chromium`, "Installing Playwright browsers")
// 4. .env file
if (!existsSync(".env.local")) {
console.log("\n── Creating .env.local ──")
copyFileSync(".env.example", ".env.local")
console.log(" ✓ Created .env.local from .env.example — edit it with your settings")
} else {
console.log("\n── .env.local already exists, skipping ──")
}
// 5. Ollama model
console.log("\n── Next steps ──")
console.log(" 1. Make sure PostgreSQL is running with database 'crm'")
console.log(" 2. Pull the Ollama model: ollama pull dolphin-llama3:8b")
console.log(" 3. Edit .env.local with your settings")
console.log(" 4. Run: npm run dev")
console.log("\n=== Setup complete! ===")