From 0e30f4f625fd0c498aacb7cb580be6e635a33d7c Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Sun, 27 May 2018 20:55:31 +0100 Subject: [PATCH] Add --setup option to setup_nimforum script. --- src/setup_nimforum.nim | 76 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/src/setup_nimforum.nim b/src/setup_nimforum.nim index a0c39ff..a015f2d 100644 --- a/src/setup_nimforum.nim +++ b/src/setup_nimforum.nim @@ -7,7 +7,7 @@ # # Script to initialise the nimforum. -import strutils, db_sqlite, os, times, json, options +import strutils, db_sqlite, os, times, json, options, terminal import auth, frontend/user @@ -210,7 +210,8 @@ proc initialiseConfig( recaptcha: tuple[siteKey, secretKey: string], smtp: tuple[address, user, password: string], isDev: bool, - dbPath: string + dbPath: string, + ga: string="" ) = let path = getCurrentDir() / "forum.json" @@ -226,6 +227,8 @@ proc initialiseConfig( "isDev": %isDev, "dbPath": %dbPath } + if ga.len > 0: + j["ga"] = %ga backup(path, some(pretty(j))) writeFile(path, pretty(j)) @@ -235,6 +238,67 @@ proc question(q: string): string = stdout.write(q) result = stdin.readLine() +proc setup() = + echo(""" +Welcome to the NimForum setup script. Please answer the following questions. +These can be changed later in the generated forum.json file. + """) + + let name = question("Forum full name: ") + let title = question("Forum short name: ") + + let hostname = question("Forum hostname: ") + + let adminUser = question("Admin username: ") + let adminPass = readPasswordFromStdin("Admin password: ") + let adminEmail = question("Admin email: ") + + echo("") + echo("The following question are related to recaptcha. \nYou must set up a " & + "recaptcha for your forum before answering them. \nPlease do so now " & + "and then answer these questions: https://www.google.com/recaptcha/admin") + let recaptchaSiteKey = question("Recaptcha site key: ") + let recaptchaSecretKey = question("Recaptcha secret key: ") + + + echo("The following questions are related to smtp. You must set up a \n" & + "mailing server for your forum or use an external service.") + let smtpAddress = question("SMTP address (eg: mail.hostname.com): ") + let smtpUser = question("SMTP user: ") + let smtpPassword = readPasswordFromStdin("SMTP pass: ") + + echo("The following is optional. You can specify your Google Analytics ID " & + "if you wish. Otherwise just leave it blank.") + stdout.write("Google Analytics (eg: UA-12345678-1): ") + let ga = stdin.readLine().strip() + + let dbPath = "nimforum.db" + initialiseConfig( + name, title, hostname, (recaptchaSiteKey, recaptchaSecretKey), + (smtpAddress, smtpUser, smtpPassword), isDev=false, + dbPath, ga + ) + + initialiseDb( + admin=(adminUser, adminPass, adminEmail), + dbPath + ) + + echo("Setup complete!") + +proc echoHelp() = + quit(""" +Usage: setup_nimforum opts + +Options: + --setup Performs first time setup for end users. + +Development options: + --dev Creates a new development DB and config. + --test Creates a new test DB and config. + --blank Creates a new blank DB. + """) + when isMainModule: if paramCount() > 0: case paramStr(1) @@ -279,5 +343,11 @@ when isMainModule: admin=("", "", ""), dbPath ) + of "--setup": + setup() else: - quit("--dev|--test|--prod") + echoHelp() + else: + echoHelp() + +