52 Path.basic(phabricator_name(name = name)) |
52 Path.basic(phabricator_name(name = name)) |
53 |
53 |
54 def default_repo(options: Options, name: String): Path = |
54 def default_repo(options: Options, name: String): Path = |
55 default_root(options, name) + Path.basic("repo") |
55 default_root(options, name) + Path.basic("repo") |
56 |
56 |
|
57 val mailers_path: Path = Path.explode("mailers.json") |
|
58 |
|
59 val mailers_template: String = |
|
60 """[ |
|
61 { |
|
62 "key": "example.org", |
|
63 "type": "smtp", |
|
64 "options": { |
|
65 "host": "mail.example.org", |
|
66 "port": 465, |
|
67 "user": "phabricator@example.org", |
|
68 "password": "********", |
|
69 "protocol": "ssl", |
|
70 "message-id": true |
|
71 } |
|
72 } |
|
73 ]""" |
|
74 |
57 |
75 |
58 |
76 |
59 /** global configuration **/ |
77 /** global configuration **/ |
60 |
78 |
61 val global_config = Path.explode("/etc/" + isabelle_phabricator_name(ext = "conf")) |
79 val global_config = Path.explode("/etc/" + isabelle_phabricator_name(ext = "conf")) |
369 package_update = package_update, progress = progress) |
396 package_update = package_update, progress = progress) |
370 }) |
397 }) |
371 |
398 |
372 |
399 |
373 |
400 |
374 /** update **/ |
401 /** setup mail **/ |
375 |
402 |
376 def phabricator_update(name: String, progress: Progress = No_Progress) |
403 def phabricator_setup_mail( |
|
404 name: String = default_name, |
|
405 config_file: Option[Path] = None, |
|
406 test_user: String = "", |
|
407 progress: Progress = No_Progress) |
377 { |
408 { |
378 Linux.check_system_root() |
409 Linux.check_system_root() |
379 |
410 |
380 ??? |
411 val config = get_config(name) |
|
412 val default_config_file = config.home + mailers_path |
|
413 |
|
414 val mail_config = config_file getOrElse default_config_file |
|
415 |
|
416 def setup_mail |
|
417 { |
|
418 progress.echo("Using mail configuration from " + mail_config) |
|
419 config.execute("config set cluster.mailers --stdin < " + File.bash_path(mail_config)) |
|
420 |
|
421 if (test_user.nonEmpty) { |
|
422 progress.echo("Sending test mail to " + quote(test_user)) |
|
423 progress.bash(cwd = config.home.file, echo = true, |
|
424 script = """echo "Test from Phabricator ($(date))" | ./bin/mail send-test --subject "Test" --to """ + |
|
425 Bash.string(test_user)).check |
|
426 } |
|
427 } |
|
428 |
|
429 if (config_file.isEmpty) { |
|
430 if (!default_config_file.is_file) File.write(default_config_file, mailers_template) |
|
431 if (File.read(default_config_file) == mailers_template) { |
|
432 progress.echo( |
|
433 "Please invoke the tool again, after providing details in\n " + default_config_file) |
|
434 } |
|
435 else setup_mail |
|
436 } |
|
437 else setup_mail |
381 } |
438 } |
382 |
439 |
383 |
440 |
384 /* Isabelle tool wrapper */ |
441 /* Isabelle tool wrapper */ |
385 |
442 |
386 val isabelle_tool2 = |
443 val isabelle_tool2 = |
387 Isabelle_Tool("phabricator_update", "update Phabricator server installation", args => |
444 Isabelle_Tool("phabricator_setup_mail", |
|
445 "setup mail configuration for existing Phabricator server", args => |
388 { |
446 { |
|
447 var test_user = "" |
|
448 var name = default_name |
|
449 var config_file: Option[Path] = None |
|
450 |
389 val getopts = |
451 val getopts = |
390 Getopts(""" |
452 Getopts(""" |
391 Usage: isabelle phabricator_update [NAME] |
453 Usage: isabelle phabricator_setup_mail [OPTIONS] |
392 |
454 |
393 Update Phabricator installation, with lookup of NAME (default + """ + quote(default_name) + """) |
455 Options are: |
394 in """ + global_config + "\n") |
456 -T USER send test mail to Phabricator user |
|
457 -f FILE config file (default: """ + mailers_path + """ within installation home) |
|
458 -n NAME Phabricator installation name (default: """ + quote(default_name) + """) |
|
459 |
|
460 Provide mail configuration for existing Phabricator installation. See also |
|
461 https://secure.phabricator.com/book/phabricator/article/configuring_outbound_email |
|
462 (notably section "Mailer: SMTP"). |
|
463 """, |
|
464 "T:" -> (arg => test_user = arg), |
|
465 "f:" -> (arg => config_file = Some(Path.explode(arg))), |
|
466 "n:" -> (arg => name = arg)) |
395 |
467 |
396 val more_args = getopts(args) |
468 val more_args = getopts(args) |
397 val name = |
469 if (more_args.nonEmpty) getopts.usage() |
398 more_args match { |
|
399 case Nil => default_name |
|
400 case List(name) => name |
|
401 case _ => getopts.usage() |
|
402 } |
|
403 |
470 |
404 val progress = new Console_Progress |
471 val progress = new Console_Progress |
405 |
472 |
406 phabricator_update(name, progress = progress) |
473 phabricator_setup_mail(name = name, config_file = config_file, |
|
474 test_user = test_user, progress = progress) |
407 }) |
475 }) |
408 } |
476 } |