Feat: Initial Setup through env vars (#1736)
* initial support for initial setup * improve setup * improve mobile view * move base admin route * admin panel mobile view * set initial host and port * add docs * properly setup everything, use for dev env * change userconfig and interface port on setup, note users afterwards
This commit is contained in:
@@ -19,7 +19,13 @@ const db = drizzle({ client, schema });
|
||||
|
||||
export async function connect() {
|
||||
await migrate();
|
||||
return new DBService(db);
|
||||
const dbService = new DBService(db);
|
||||
|
||||
if (WG_INITIAL_ENV.ENABLED) {
|
||||
await initialSetup(dbService);
|
||||
}
|
||||
|
||||
return dbService;
|
||||
}
|
||||
|
||||
class DBService {
|
||||
@@ -58,3 +64,47 @@ async function migrate() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function initialSetup(db: DBServiceType) {
|
||||
const setup = await db.general.getSetupStep();
|
||||
|
||||
if (setup.done) {
|
||||
DB_DEBUG('Setup already done. Skiping initial setup.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (WG_INITIAL_ENV.IPV4_CIDR && WG_INITIAL_ENV.IPV6_CIDR) {
|
||||
DB_DEBUG('Setting initial CIDR...');
|
||||
await db.interfaces.updateCidr({
|
||||
ipv4Cidr: WG_INITIAL_ENV.IPV4_CIDR,
|
||||
ipv6Cidr: WG_INITIAL_ENV.IPV6_CIDR,
|
||||
});
|
||||
}
|
||||
|
||||
if (WG_INITIAL_ENV.DNS) {
|
||||
DB_DEBUG('Setting initial DNS...');
|
||||
const userConfig = await db.userConfigs.get();
|
||||
await db.userConfigs.update({
|
||||
...userConfig,
|
||||
defaultDns: WG_INITIAL_ENV.DNS,
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
WG_INITIAL_ENV.USERNAME &&
|
||||
WG_INITIAL_ENV.PASSWORD &&
|
||||
WG_INITIAL_ENV.HOST &&
|
||||
WG_INITIAL_ENV.PORT
|
||||
) {
|
||||
DB_DEBUG('Creating initial user...');
|
||||
await db.users.create(WG_INITIAL_ENV.USERNAME, WG_INITIAL_ENV.PASSWORD);
|
||||
|
||||
DB_DEBUG('Setting initial host and port...');
|
||||
await db.userConfigs.updateHostPort(
|
||||
WG_INITIAL_ENV.HOST,
|
||||
WG_INITIAL_ENV.PORT
|
||||
);
|
||||
|
||||
await db.general.setSetupStep(0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user