134 lines
3.8 KiB
TypeScript
134 lines
3.8 KiB
TypeScript
import { createDb } from './client';
|
|
import { games } from './schema/games';
|
|
import { users } from './schema/users';
|
|
|
|
async function seed() {
|
|
const databaseUrl = process.env.DATABASE_URL;
|
|
if (!databaseUrl) {
|
|
console.error('DATABASE_URL is required');
|
|
process.exit(1);
|
|
}
|
|
|
|
const db = createDb(databaseUrl);
|
|
|
|
// Seed super admin
|
|
console.log('Seeding super admin...');
|
|
// Password: admin123 (argon2id hash)
|
|
// In production, change this immediately after first login
|
|
const ADMIN_PASSWORD_HASH =
|
|
'$argon2id$v=19$m=65536,t=3,p=4$c29tZXNhbHQ$RdescudvJCsgt3ub+b+daw';
|
|
|
|
await db
|
|
.insert(users)
|
|
.values({
|
|
email: 'admin@gamepanel.local',
|
|
username: 'admin',
|
|
passwordHash: ADMIN_PASSWORD_HASH,
|
|
isSuperAdmin: true,
|
|
})
|
|
.onConflictDoNothing();
|
|
|
|
// Seed games
|
|
console.log('Seeding games...');
|
|
await db
|
|
.insert(games)
|
|
.values([
|
|
{
|
|
slug: 'minecraft-java',
|
|
name: 'Minecraft: Java Edition',
|
|
dockerImage: 'itzg/minecraft-server:latest',
|
|
defaultPort: 25565,
|
|
startupCommand: '/start',
|
|
stopCommand: 'stop',
|
|
configFiles: [
|
|
{
|
|
path: 'server.properties',
|
|
parser: 'properties',
|
|
editableKeys: [
|
|
'server-port',
|
|
'max-players',
|
|
'motd',
|
|
'difficulty',
|
|
'gamemode',
|
|
'level-seed',
|
|
'pvp',
|
|
'spawn-protection',
|
|
'view-distance',
|
|
'online-mode',
|
|
'white-list',
|
|
],
|
|
},
|
|
{ path: 'ops.json', parser: 'json' },
|
|
{ path: 'whitelist.json', parser: 'json' },
|
|
{ path: 'bukkit.yml', parser: 'yaml' },
|
|
{ path: 'spigot.yml', parser: 'yaml' },
|
|
],
|
|
environmentVars: [
|
|
{ key: 'EULA', default: 'TRUE', description: 'Accept Minecraft EULA', required: true },
|
|
{
|
|
key: 'TYPE',
|
|
default: 'PAPER',
|
|
description: 'Server type (VANILLA, PAPER, SPIGOT, FORGE, FABRIC)',
|
|
required: true,
|
|
},
|
|
{
|
|
key: 'VERSION',
|
|
default: 'LATEST',
|
|
description: 'Minecraft version',
|
|
required: true,
|
|
},
|
|
{ key: 'MEMORY', default: '1G', description: 'JVM memory allocation', required: false },
|
|
],
|
|
},
|
|
{
|
|
slug: 'cs2',
|
|
name: 'Counter-Strike 2',
|
|
dockerImage: 'cm2network/csgo:latest',
|
|
defaultPort: 27015,
|
|
startupCommand:
|
|
'./srcds_run -game csgo -console -usercon +game_type 0 +game_mode 0 +mapgroup mg_active +map de_dust2',
|
|
stopCommand: 'quit',
|
|
configFiles: [
|
|
{
|
|
path: 'csgo/cfg/server.cfg',
|
|
parser: 'keyvalue',
|
|
editableKeys: [
|
|
'hostname',
|
|
'sv_password',
|
|
'rcon_password',
|
|
'sv_cheats',
|
|
'mp_autoteambalance',
|
|
'mp_limitteams',
|
|
],
|
|
},
|
|
{ path: 'csgo/cfg/autoexec.cfg', parser: 'keyvalue' },
|
|
],
|
|
environmentVars: [
|
|
{
|
|
key: 'SRCDS_TOKEN',
|
|
default: '',
|
|
description: 'Steam Game Server Login Token',
|
|
required: true,
|
|
},
|
|
{ key: 'SRCDS_RCONPW', default: '', description: 'RCON password', required: false },
|
|
{ key: 'SRCDS_PW', default: '', description: 'Server password', required: false },
|
|
{
|
|
key: 'SRCDS_MAXPLAYERS',
|
|
default: '16',
|
|
description: 'Max players',
|
|
required: false,
|
|
},
|
|
],
|
|
},
|
|
])
|
|
.onConflictDoNothing();
|
|
|
|
console.log('Seed completed successfully!');
|
|
process.exit(0);
|
|
}
|
|
|
|
seed().catch((err) => {
|
|
console.error('Seed failed:', err);
|
|
process.exit(1);
|
|
});
|