| author | wenzelm |
| Thu, 07 Nov 2019 11:00:11 +0100 | |
| changeset 71074 | 324c40205fc8 |
| parent 71073 | d61fd7aade69 |
| child 71075 | 70205e023cb4 |
| permissions | -rw-r--r-- |
| 70967 | 1 |
/* Title: Pure/Tools/phabricator.scala |
2 |
Author: Makarius |
|
3 |
||
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
4 |
Support for Phabricator server, notably for Ubuntu 18.04 LTS. |
|
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
5 |
|
|
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
6 |
See also: |
| 70967 | 7 |
- https://www.phacility.com/phabricator |
8 |
- https://secure.phabricator.com/book/phabricator |
|
9 |
*/ |
|
10 |
||
11 |
package isabelle |
|
12 |
||
13 |
||
| 70969 | 14 |
import scala.util.matching.Regex |
15 |
||
16 |
||
| 70967 | 17 |
object Phabricator |
18 |
{
|
|
19 |
/** defaults **/ |
|
20 |
||
| 71049 | 21 |
/* required packages */ |
22 |
||
23 |
val packages: List[String] = |
|
24 |
Build_Docker.packages ::: |
|
25 |
List( |
|
26 |
// https://secure.phabricator.com/source/phabricator/browse/master/scripts/install/install_ubuntu.sh 15e6e2adea61 |
|
27 |
"git", "mysql-server", "apache2", "libapache2-mod-php", "php", "php-mysql", |
|
28 |
"php-gd", "php-curl", "php-apcu", "php-cli", "php-json", "php-mbstring", |
|
29 |
// more packages |
|
30 |
"php-zip", "python-pygments", "ssh") |
|
31 |
||
32 |
||
33 |
/* global system resources */ |
|
34 |
||
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
35 |
val www_user = "www-data" |
|
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
36 |
|
| 71049 | 37 |
val daemon_user = "phabricator" |
38 |
||
39 |
val ssh_standard = 22 |
|
40 |
val ssh_alternative1 = 222 |
|
41 |
val ssh_alternative2 = 2222 |
|
42 |
||
43 |
||
44 |
/* installation parameters */ |
|
45 |
||
| 70967 | 46 |
val default_name = "vcs" |
47 |
||
|
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
48 |
def phabricator_name(name: String = "", ext: String = ""): String = |
|
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
49 |
"phabricator" + (if (name.isEmpty) "" else "-" + name) + (if (ext.isEmpty) "" else "." + ext) |
|
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
50 |
|
|
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
51 |
def isabelle_phabricator_name(name: String = "", ext: String = ""): String = |
|
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
52 |
"isabelle-" + phabricator_name(name = name, ext = ext) |
| 70967 | 53 |
|
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
54 |
def default_root(name: String): Path = |
|
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
55 |
Path.explode("/var/www") + Path.basic(phabricator_name(name = name))
|
| 70967 | 56 |
|
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
57 |
def default_repo(name: String): Path = default_root(name) + Path.basic("repo")
|
| 70967 | 58 |
|
| 71072 | 59 |
val default_mailers: Path = Path.explode("mailers.json")
|
| 71066 | 60 |
|
| 70967 | 61 |
|
62 |
||
63 |
/** global configuration **/ |
|
64 |
||
|
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
65 |
val global_config = Path.explode("/etc/" + isabelle_phabricator_name(ext = "conf"))
|
| 70967 | 66 |
|
67 |
sealed case class Config(name: String, root: Path) |
|
| 70968 | 68 |
{
|
|
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
69 |
def home: Path = root + Path.explode(phabricator_name()) |
| 70969 | 70 |
|
71 |
def execute(command: String): Process_Result = |
|
| 71074 | 72 |
Isabelle_System.bash("./bin/" + command, cwd = home.file, redirect = true).check
|
| 70968 | 73 |
} |
| 70967 | 74 |
|
75 |
def read_config(): List[Config] = |
|
76 |
{
|
|
77 |
if (global_config.is_file) {
|
|
78 |
for (entry <- Library.trim_split_lines(File.read(global_config)) if entry.nonEmpty) |
|
79 |
yield {
|
|
80 |
space_explode(':', entry) match {
|
|
81 |
case List(name, root) => Config(name, Path.explode(root)) |
|
82 |
case _ => error("Malformed config file " + global_config + "\nentry " + quote(entry))
|
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
else Nil |
|
87 |
} |
|
88 |
||
89 |
def write_config(configs: List[Config]) |
|
90 |
{
|
|
91 |
File.write(global_config, |
|
92 |
configs.map(config => config.name + ":" + config.root.implode).mkString("", "\n", "\n"))
|
|
93 |
} |
|
94 |
||
95 |
def get_config(name: String): Config = |
|
96 |
read_config().find(config => config.name == name) getOrElse |
|
97 |
error("Bad Isabelle/Phabricator installation " + quote(name))
|
|
98 |
||
99 |
||
100 |
||
101 |
/** setup **/ |
|
102 |
||
| 71049 | 103 |
def user_setup(name: String, description: String, ssh_setup: Boolean = false) |
104 |
{
|
|
105 |
if (!Linux.user_exists(name)) {
|
|
|
71054
b64fc38327ae
prefer system user setup, e.g. avoid occurrence on login screen;
wenzelm
parents:
71053
diff
changeset
|
106 |
Linux.user_add(name, description = description, system = true, ssh_setup = ssh_setup) |
| 71049 | 107 |
} |
108 |
else if (Linux.user_description(name) != description) {
|
|
109 |
error("User " + quote(name) + " already exists --" +
|
|
110 |
" for Phabricator it should have the description:\n " + quote(description)) |
|
111 |
} |
|
112 |
} |
|
113 |
||
| 70967 | 114 |
def phabricator_setup( |
115 |
name: String = default_name, |
|
116 |
root: String = "", |
|
117 |
repo: String = "", |
|
| 71047 | 118 |
package_update: Boolean = false, |
| 70967 | 119 |
progress: Progress = No_Progress) |
120 |
{
|
|
121 |
/* system environment */ |
|
122 |
||
123 |
Linux.check_system_root() |
|
124 |
||
| 71047 | 125 |
if (package_update) {
|
126 |
Linux.package_update(progress = progress) |
|
127 |
Linux.check_reboot_required() |
|
128 |
} |
|
| 70967 | 129 |
|
130 |
Linux.package_install(packages, progress = progress) |
|
131 |
Linux.check_reboot_required() |
|
132 |
||
133 |
||
| 71049 | 134 |
/* users */ |
135 |
||
136 |
if (name == daemon_user) {
|
|
137 |
error("Clash of installation name with daemon user " + quote(daemon_user))
|
|
138 |
} |
|
139 |
||
140 |
user_setup(daemon_user, "Phabricator Daemon User", ssh_setup = true) |
|
141 |
user_setup(name, "Phabricator SSH User") |
|
142 |
||
143 |
||
| 70967 | 144 |
/* basic installation */ |
145 |
||
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
146 |
val root_path = if (root.nonEmpty) Path.explode(root) else default_root(name) |
|
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
147 |
val repo_path = if (repo.nonEmpty) Path.explode(repo) else default_repo(name) |
| 70967 | 148 |
|
149 |
val configs = read_config() |
|
150 |
||
151 |
for (config <- configs if config.name == name) {
|
|
152 |
error("Duplicate Phabricator installation " + quote(name) + " in " + config.root)
|
|
153 |
} |
|
154 |
||
155 |
if (!Isabelle_System.bash("mkdir -p " + File.bash_path(root_path)).ok) {
|
|
156 |
error("Failed to create root directory " + root_path)
|
|
157 |
} |
|
158 |
||
159 |
progress.bash(cwd = root_path.file, echo = true, |
|
160 |
script = """ |
|
161 |
set -e |
|
| 71050 | 162 |
chown """ + Bash.string(www_user) + ":" + Bash.string(www_user) + """ . |
| 70967 | 163 |
chmod 755 . |
164 |
||
165 |
git clone https://github.com/phacility/libphutil.git |
|
166 |
git clone https://github.com/phacility/arcanist.git |
|
167 |
git clone https://github.com/phacility/phabricator.git |
|
168 |
""").check |
|
169 |
||
170 |
val config = Config(name, root_path) |
|
171 |
write_config(configs ::: List(config)) |
|
| 70968 | 172 |
|
| 71051 | 173 |
config.execute("config set pygments.enabled true")
|
174 |
||
| 70968 | 175 |
|
| 71050 | 176 |
/* local repository directory */ |
177 |
||
178 |
if (!Isabelle_System.bash("mkdir -p " + File.bash_path(repo_path)).ok) {
|
|
179 |
error("Failed to create local repository directory " + repo_path)
|
|
180 |
} |
|
181 |
||
182 |
Isabelle_System.bash(cwd = repo_path.file, |
|
183 |
script = """ |
|
184 |
set -e |
|
185 |
chown -R """ + Bash.string(daemon_user) + ":" + Bash.string(daemon_user) + """ . |
|
186 |
chmod 755 . |
|
187 |
""").check |
|
188 |
||
189 |
config.execute("config set repository.default-local-path " + File.bash_path(repo_path))
|
|
190 |
||
191 |
||
| 70969 | 192 |
/* MySQL setup */ |
193 |
||
194 |
progress.echo("MySQL setup...")
|
|
195 |
||
|
71055
27a998cdc0f4
back to plain name, to have it accepted my mysql;
wenzelm
parents:
71054
diff
changeset
|
196 |
File.write(Path.explode("/etc/mysql/mysql.conf.d/" + phabricator_name(ext = "cnf")),
|
| 71051 | 197 |
"""[mysqld] |
198 |
max_allowed_packet = 32M |
|
199 |
innodb_buffer_pool_size = 1600M |
|
200 |
local_infile = 0 |
|
201 |
""") |
|
202 |
||
203 |
Linux.service_restart("mysql")
|
|
204 |
||
205 |
||
| 70969 | 206 |
def mysql_conf(R: Regex): Option[String] = |
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
207 |
split_lines(File.read(Path.explode("/etc/mysql/debian.cnf"))).collectFirst({ case R(a) => a })
|
| 70969 | 208 |
|
209 |
for (user <- mysql_conf("""^user\s*=\s*(\S*)\s*$""".r)) {
|
|
210 |
config.execute("config set mysql.user " + Bash.string(user))
|
|
211 |
} |
|
212 |
||
213 |
for (pass <- mysql_conf("""^password\s*=\s*(\S*)\s*$""".r)) {
|
|
214 |
config.execute("config set mysql.pass " + Bash.string(pass))
|
|
215 |
} |
|
216 |
||
217 |
config.execute("config set storage.default-namespace " +
|
|
|
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
218 |
Bash.string(phabricator_name(name = name).replace("-", "_")))
|
| 70969 | 219 |
|
| 71051 | 220 |
config.execute("config set storage.mysql-engine.max-size 8388608")
|
221 |
||
| 70969 | 222 |
config.execute("storage upgrade --force")
|
223 |
||
224 |
||
| 71049 | 225 |
/* SSH hosting */ |
226 |
||
227 |
progress.echo("SSH hosting setup...")
|
|
228 |
||
229 |
val ssh_port = ssh_alternative2 |
|
230 |
||
231 |
config.execute("config set diffusion.ssh-user " + Bash.string(name))
|
|
232 |
config.execute("config set diffusion.ssh-port " + ssh_port)
|
|
233 |
||
|
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
234 |
val sudoers_file = Path.explode("/etc/sudoers.d") + Path.basic(isabelle_phabricator_name())
|
| 71049 | 235 |
File.write(sudoers_file, |
236 |
www_user + " ALL=(" + daemon_user + ") SETENV: NOPASSWD: /usr/bin/git, /usr/bin/hg, /usr/bin/ssh, /usr/bin/id\n" +
|
|
237 |
name + " ALL=(" + daemon_user + ") SETENV: NOPASSWD: /usr/bin/git, /usr/bin/git-upload-pack, /usr/bin/git-receive-pack, /usr/bin/hg, /usr/bin/svnserve, /usr/bin/ssh, /usr/bin/id\n")
|
|
238 |
||
239 |
Isabelle_System.bash("chmod 0440 " + File.bash_path(sudoers_file)).check
|
|
240 |
||
241 |
||
| 71051 | 242 |
/* PHP setup */ |
243 |
||
244 |
val php_version = |
|
245 |
Isabelle_System.bash("""php --run 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;'""")
|
|
246 |
.check.out |
|
247 |
||
248 |
val php_conf = |
|
249 |
Path.explode("/etc/php") + Path.basic(php_version) + // educated guess
|
|
|
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
250 |
Path.explode("apache2/conf.d") +
|
|
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
251 |
Path.basic(isabelle_phabricator_name(ext = "ini")) |
| 71051 | 252 |
|
253 |
File.write(php_conf, |
|
254 |
"post_max_size = 32M\n" + |
|
255 |
"opcache.validate_timestamps = 0\n" + |
|
256 |
"memory_limit = 512M\n") |
|
257 |
||
258 |
||
| 70968 | 259 |
/* Apache setup */ |
260 |
||
261 |
progress.echo("Apache setup...")
|
|
262 |
||
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
263 |
val apache_root = Path.explode("/etc/apache2")
|
| 70968 | 264 |
val apache_sites = apache_root + Path.explode("sites-available")
|
265 |
||
266 |
if (!apache_sites.is_dir) error("Bad Apache sites directory " + apache_sites)
|
|
267 |
||
| 71058 | 268 |
val server_name = phabricator_name(name = name, ext = "lvh.me") // alias for "localhost" for testing |
|
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
269 |
val server_url = "http://" + server_name |
|
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
270 |
|
| 71058 | 271 |
File.write(apache_sites + Path.basic(isabelle_phabricator_name(name = name, ext = "conf")), |
| 70968 | 272 |
"""<VirtualHost *:80> |
|
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
273 |
ServerName """ + server_name + """ |
| 70968 | 274 |
ServerAdmin webmaster@localhost |
| 70969 | 275 |
DocumentRoot """ + config.home.implode + """/webroot |
| 70968 | 276 |
|
277 |
ErrorLog ${APACHE_LOG_DIR}/error.log
|
|
278 |
RewriteEngine on |
|
279 |
RewriteRule ^(.*)$ /index.php?__path__=$1 [B,L,QSA] |
|
280 |
</VirtualHost> |
|
281 |
||
282 |
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet |
|
283 |
""") |
|
284 |
||
| 71051 | 285 |
Isabelle_System.bash( """ |
| 70968 | 286 |
set -e |
287 |
a2enmod rewrite |
|
| 71058 | 288 |
a2ensite """ + Bash.string(isabelle_phabricator_name(name = name))).check |
| 71051 | 289 |
|
| 71057 | 290 |
config.execute("config set phabricator.base-uri " + Bash.string(server_url))
|
291 |
||
| 71051 | 292 |
Linux.service_restart("apache2")
|
| 70968 | 293 |
|
| 71053 | 294 |
|
295 |
/* PHP daemon */ |
|
296 |
||
297 |
progress.echo("PHP daemon setup...")
|
|
298 |
||
299 |
config.execute("config set phd.user " + Bash.string(daemon_user))
|
|
300 |
||
|
71056
ee3c43eb79ae
proper service name (again): it is specific to each installation;
wenzelm
parents:
71055
diff
changeset
|
301 |
Linux.service_install(isabelle_phabricator_name(name = name), |
| 71053 | 302 |
"""[Unit] |
303 |
Description=PHP daemon for Isabelle/Phabricator """ + quote(name) + """ |
|
304 |
After=syslog.target network.target apache2.service mysql.service |
|
305 |
||
306 |
[Service] |
|
307 |
Type=oneshot |
|
308 |
User=""" + daemon_user + """ |
|
309 |
Group=""" + daemon_user + """ |
|
310 |
Environment=PATH=/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin |
|
311 |
ExecStart=""" + config.home.implode + """/bin/phd start |
|
312 |
ExecStop=""" + config.home.implode + """/bin/phd stop |
|
313 |
RemainAfterExit=yes |
|
314 |
||
315 |
[Install] |
|
316 |
WantedBy=multi-user.target |
|
317 |
""") |
|
318 |
||
319 |
||
|
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
320 |
progress.echo("\nDONE\nWeb configuration via " + server_url)
|
| 70967 | 321 |
} |
322 |
||
323 |
||
324 |
/* Isabelle tool wrapper */ |
|
325 |
||
326 |
val isabelle_tool1 = |
|
327 |
Isabelle_Tool("phabricator_setup", "setup Phabricator server on Ubuntu Linux", args =>
|
|
328 |
{
|
|
| 71047 | 329 |
var repo = "" |
330 |
var package_update = false |
|
| 70967 | 331 |
var root = "" |
332 |
||
333 |
val getopts = |
|
334 |
Getopts("""
|
|
335 |
Usage: isabelle phabricator_setup [OPTIONS] [NAME] |
|
336 |
||
337 |
Options are: |
|
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
338 |
-R DIR repository directory (default: """ + default_repo("NAME") + """)
|
| 71047 | 339 |
-U full update of system packages before installation |
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
340 |
-r DIR installation root directory (default: """ + default_root("NAME") + """)
|
| 70967 | 341 |
|
342 |
Install Phabricator as Ubuntu LAMP application (Linux, Apache, MySQL, PHP). |
|
343 |
||
344 |
Slogan: "Discuss. Plan. Code. Review. Test. |
|
345 |
Every application your project needs, all in one tool." |
|
346 |
||
347 |
The installation NAME (default: """ + quote(default_name) + """) is mapped to |
|
348 |
a regular Unix user and used for public SSH access. |
|
349 |
""", |
|
350 |
"R:" -> (arg => repo = arg), |
|
| 71047 | 351 |
"U" -> (_ => package_update = true), |
| 70967 | 352 |
"r:" -> (arg => root = arg)) |
353 |
||
354 |
val more_args = getopts(args) |
|
355 |
||
356 |
val name = |
|
357 |
more_args match {
|
|
358 |
case Nil => default_name |
|
359 |
case List(name) => name |
|
360 |
case _ => getopts.usage() |
|
361 |
} |
|
362 |
||
363 |
val progress = new Console_Progress |
|
364 |
||
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
365 |
phabricator_setup(name, root = root, repo = repo, |
| 71047 | 366 |
package_update = package_update, progress = progress) |
| 70967 | 367 |
}) |
368 |
||
369 |
||
370 |
||
| 71066 | 371 |
/** setup mail **/ |
| 70967 | 372 |
|
| 71072 | 373 |
val mailers_template: String = |
374 |
"""[ |
|
375 |
{
|
|
376 |
"key": "example.org", |
|
377 |
"type": "smtp", |
|
378 |
"options": {
|
|
379 |
"host": "mail.example.org", |
|
380 |
"port": 465, |
|
381 |
"user": "phabricator@example.org", |
|
382 |
"password": "********", |
|
383 |
"protocol": "ssl", |
|
384 |
"message-id": true |
|
385 |
} |
|
386 |
} |
|
387 |
]""" |
|
388 |
||
| 71066 | 389 |
def phabricator_setup_mail( |
390 |
name: String = default_name, |
|
391 |
config_file: Option[Path] = None, |
|
392 |
test_user: String = "", |
|
393 |
progress: Progress = No_Progress) |
|
| 70967 | 394 |
{
|
395 |
Linux.check_system_root() |
|
396 |
||
| 71066 | 397 |
val config = get_config(name) |
| 71073 | 398 |
val default_config_file = config.root + default_mailers |
| 71066 | 399 |
|
400 |
val mail_config = config_file getOrElse default_config_file |
|
401 |
||
402 |
def setup_mail |
|
403 |
{
|
|
404 |
progress.echo("Using mail configuration from " + mail_config)
|
|
405 |
config.execute("config set cluster.mailers --stdin < " + File.bash_path(mail_config))
|
|
406 |
||
407 |
if (test_user.nonEmpty) {
|
|
408 |
progress.echo("Sending test mail to " + quote(test_user))
|
|
409 |
progress.bash(cwd = config.home.file, echo = true, |
|
410 |
script = """echo "Test from Phabricator ($(date))" | ./bin/mail send-test --subject "Test" --to """ + |
|
411 |
Bash.string(test_user)).check |
|
412 |
} |
|
413 |
} |
|
414 |
||
415 |
if (config_file.isEmpty) {
|
|
| 71070 | 416 |
if (!default_config_file.is_file) {
|
417 |
File.write(default_config_file, mailers_template) |
|
418 |
Isabelle_System.bash("chmod 600 " + File.bash_path(default_config_file)).check
|
|
419 |
} |
|
| 71066 | 420 |
if (File.read(default_config_file) == mailers_template) {
|
421 |
progress.echo( |
|
| 71071 | 422 |
"Please invoke the tool again, after providing details in:\n " + |
423 |
default_config_file.implode) |
|
| 71066 | 424 |
} |
425 |
else setup_mail |
|
426 |
} |
|
427 |
else setup_mail |
|
| 70967 | 428 |
} |
429 |
||
430 |
||
431 |
/* Isabelle tool wrapper */ |
|
432 |
||
433 |
val isabelle_tool2 = |
|
| 71066 | 434 |
Isabelle_Tool("phabricator_setup_mail",
|
435 |
"setup mail configuration for existing Phabricator server", args => |
|
| 70967 | 436 |
{
|
| 71066 | 437 |
var test_user = "" |
438 |
var name = default_name |
|
439 |
var config_file: Option[Path] = None |
|
440 |
||
| 70967 | 441 |
val getopts = |
442 |
Getopts("""
|
|
| 71066 | 443 |
Usage: isabelle phabricator_setup_mail [OPTIONS] |
444 |
||
445 |
Options are: |
|
446 |
-T USER send test mail to Phabricator user |
|
| 71073 | 447 |
-f FILE config file (default: """ + default_mailers + """ within installation root) |
| 71066 | 448 |
-n NAME Phabricator installation name (default: """ + quote(default_name) + """) |
| 70967 | 449 |
|
| 71066 | 450 |
Provide mail configuration for existing Phabricator installation. See also |
451 |
https://secure.phabricator.com/book/phabricator/article/configuring_outbound_email |
|
452 |
(notably section "Mailer: SMTP"). |
|
453 |
""", |
|
454 |
"T:" -> (arg => test_user = arg), |
|
455 |
"f:" -> (arg => config_file = Some(Path.explode(arg))), |
|
456 |
"n:" -> (arg => name = arg)) |
|
| 70967 | 457 |
|
458 |
val more_args = getopts(args) |
|
| 71066 | 459 |
if (more_args.nonEmpty) getopts.usage() |
| 70967 | 460 |
|
461 |
val progress = new Console_Progress |
|
462 |
||
| 71066 | 463 |
phabricator_setup_mail(name = name, config_file = config_file, |
464 |
test_user = test_user, progress = progress) |
|
| 70967 | 465 |
}) |
466 |
} |