77#
88# Script to initialise the nimforum.
99
10- import strutils, db_sqlite, os, times, json, options
10+ import strutils, db_sqlite, os, times, json, options, terminal
1111
1212import auth, frontend/ user
1313
@@ -210,7 +210,8 @@ proc initialiseConfig(
210210 recaptcha: tuple [siteKey, secretKey: string ],
211211 smtp: tuple [address, user, password: string ],
212212 isDev: bool ,
213- dbPath: string
213+ dbPath: string ,
214+ ga: string = " "
214215) =
215216 let path = getCurrentDir () / " forum.json"
216217
@@ -226,6 +227,8 @@ proc initialiseConfig(
226227 " isDev" : % isDev,
227228 " dbPath" : % dbPath
228229 }
230+ if ga.len > 0 :
231+ j[" ga" ] = % ga
229232
230233 backup (path, some (pretty (j)))
231234 writeFile (path, pretty (j))
@@ -235,6 +238,67 @@ proc question(q: string): string =
235238 stdout.write (q)
236239 result = stdin.readLine ()
237240
241+ proc setup () =
242+ echo ("""
243+ Welcome to the NimForum setup script. Please answer the following questions.
244+ These can be changed later in the generated forum.json file.
245+ """ )
246+
247+ let name = question (" Forum full name: " )
248+ let title = question (" Forum short name: " )
249+
250+ let hostname = question (" Forum hostname: " )
251+
252+ let adminUser = question (" Admin username: " )
253+ let adminPass = readPasswordFromStdin (" Admin password: " )
254+ let adminEmail = question (" Admin email: " )
255+
256+ echo (" " )
257+ echo (" The following question are related to recaptcha. \n You must set up a " &
258+ " recaptcha for your forum before answering them. \n Please do so now " &
259+ " and then answer these questions: https://www.google.com/recaptcha/admin" )
260+ let recaptchaSiteKey = question (" Recaptcha site key: " )
261+ let recaptchaSecretKey = question (" Recaptcha secret key: " )
262+
263+
264+ echo (" The following questions are related to smtp. You must set up a \n " &
265+ " mailing server for your forum or use an external service." )
266+ let smtpAddress = question (" SMTP address (eg: mail.hostname.com): " )
267+ let smtpUser = question (" SMTP user: " )
268+ let smtpPassword = readPasswordFromStdin (" SMTP pass: " )
269+
270+ echo (" The following is optional. You can specify your Google Analytics ID " &
271+ " if you wish. Otherwise just leave it blank." )
272+ stdout.write (" Google Analytics (eg: UA-12345678-1): " )
273+ let ga = stdin.readLine ().strip ()
274+
275+ let dbPath = " nimforum.db"
276+ initialiseConfig (
277+ name, title, hostname, (recaptchaSiteKey, recaptchaSecretKey),
278+ (smtpAddress, smtpUser, smtpPassword), isDev= false ,
279+ dbPath, ga
280+ )
281+
282+ initialiseDb (
283+ admin= (adminUser, adminPass, adminEmail),
284+ dbPath
285+ )
286+
287+ echo (" Setup complete!" )
288+
289+ proc echoHelp () =
290+ quit ("""
291+ Usage: setup_nimforum opts
292+
293+ Options:
294+ --setup Performs first time setup for end users.
295+
296+ Development options:
297+ --dev Creates a new development DB and config.
298+ --test Creates a new test DB and config.
299+ --blank Creates a new blank DB.
300+ """ )
301+
238302when isMainModule :
239303 if paramCount () > 0 :
240304 case paramStr (1 )
@@ -279,5 +343,11 @@ when isMainModule:
279343 admin= (" " , " " , " " ),
280344 dbPath
281345 )
346+ of " --setup" :
347+ setup ()
282348 else :
283- quit (" --dev|--test|--prod" )
349+ echoHelp ()
350+ else :
351+ echoHelp ()
352+
353+
0 commit comments