Skip to content

Commit 2ba213d

Browse files
authored
fix: pct create fails with malformed arguments (#423) (#427)
- Fix NS/MTU/MAC/VLAN/SD variables missing proper prefixes in base_settings() Variables were passed as raw values instead of formatted pct options (e.g., '192.168.1.1' instead of '-nameserver=192.168.1.1') - Strip spaces from nameserver values to prevent 'too many arguments' error Multiple DNS servers must be comma-separated without spaces - Auto-create database directory before Prisma initialization Fixes 'Cannot open database because directory does not exist' error for manual Git installations
1 parent 849aabb commit 2ba213d

3 files changed

Lines changed: 39 additions & 7 deletions

File tree

scripts/core/build.func

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,16 @@ base_settings() {
517517
fi
518518
fi
519519

520-
MTU=${var_mtu:-""}
521-
SD=${var_storage:-""}
522-
NS=${var_ns:-""}
523-
MAC=${var_mac:-""}
524-
VLAN=${var_vlan:-""}
520+
# Format optional network variables with proper prefixes for pct create
521+
# Also strip any spaces from nameserver values (multiple IPs must be comma-separated without spaces)
522+
local _ns_clean="${var_ns:-}"
523+
_ns_clean="${_ns_clean// /}" # Remove all spaces from nameserver value
524+
525+
[[ -n "${var_mtu:-}" ]] && MTU=",mtu=${var_mtu}" || MTU=""
526+
[[ -n "${var_searchdomain:-}" ]] && SD="-searchdomain=${var_searchdomain}" || SD=""
527+
[[ -n "$_ns_clean" ]] && NS="-nameserver=${_ns_clean}" || NS=""
528+
[[ -n "${var_mac:-}" ]] && MAC=",hwaddr=${var_mac}" || MAC=""
529+
[[ -n "${var_vlan:-}" ]] && VLAN=",tag=${var_vlan}" || VLAN=""
525530
SSH=${var_ssh:-"no"}
526531
SSH_AUTHORIZED_KEY=${var_ssh_authorized_key:-""}
527532
UDHCPC_FIX=${var_udhcpc_fix:-""}
@@ -2023,10 +2028,11 @@ Advanced:
20232028
var_apt_cacher="$_apt_cacher"
20242029
var_apt_cacher_ip="$_apt_cacher_ip"
20252030

2026-
# Format optional values
2031+
# Format optional values (strip spaces from nameserver - multiple IPs must be comma-separated without spaces)
2032+
local _ns_clean="${_ns// /}"
20272033
[[ -n "$_mtu" ]] && MTU=",mtu=$_mtu" || MTU=""
20282034
[[ -n "$_sd" ]] && SD="-searchdomain=$_sd" || SD=""
2029-
[[ -n "$_ns" ]] && NS="-nameserver=$_ns" || NS=""
2035+
[[ -n "$_ns_clean" ]] && NS="-nameserver=$_ns_clean" || NS=""
20302036
[[ -n "$_mac" ]] && MAC=",hwaddr=$_mac" || MAC=""
20312037
[[ -n "$_vlan" ]] && VLAN=",tag=$_vlan" || VLAN=""
20322038

src/server/db.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
import 'dotenv/config'
22
import { PrismaClient } from '../../prisma/generated/prisma/client.ts'
33
import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3'
4+
import { existsSync, mkdirSync } from 'fs'
5+
import { dirname } from 'path'
46

57
const globalForPrisma = globalThis;
68

9+
// Ensure database directory exists before initializing Prisma
10+
// DATABASE_URL format: file:/path/to/database.db
11+
const dbUrl = process.env.DATABASE_URL || 'file:./data/settings.db';
12+
const dbPath = dbUrl.replace(/^file:/, '');
13+
const dbDir = dirname(dbPath);
14+
15+
if (!existsSync(dbDir)) {
16+
console.log(`Creating database directory: ${dbDir}`);
17+
mkdirSync(dbDir, { recursive: true });
18+
}
19+
720
const adapter = new PrismaBetterSqlite3({ url: process.env.DATABASE_URL });
821

922
export const prisma = globalForPrisma.prisma ?? new PrismaClient({ adapter });

src/server/db.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
import 'dotenv/config'
22
import { PrismaClient } from '../../prisma/generated/prisma/client'
33
import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3'
4+
import { existsSync, mkdirSync } from 'fs'
5+
import { dirname } from 'path'
46

57
const globalForPrisma = globalThis as { prisma?: PrismaClient };
68

9+
// Ensure database directory exists before initializing Prisma
10+
// DATABASE_URL format: file:/path/to/database.db
11+
const dbUrl = process.env.DATABASE_URL || 'file:./data/settings.db';
12+
const dbPath = dbUrl.replace(/^file:/, '');
13+
const dbDir = dirname(dbPath);
14+
15+
if (!existsSync(dbDir)) {
16+
console.log(`Creating database directory: ${dbDir}`);
17+
mkdirSync(dbDir, { recursive: true });
18+
}
19+
720
const adapter = new PrismaBetterSqlite3({ url: process.env.DATABASE_URL! });
821

922
export const prisma: PrismaClient = globalForPrisma.prisma ?? new PrismaClient({

0 commit comments

Comments
 (0)