author | wenzelm |
Tue, 12 Nov 2019 19:32:19 +0100 | |
changeset 71103 | c073c4e79518 |
parent 71102 | 3d228a3a88e0 |
child 71109 | 8c1c717a830b |
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 = |
|
71102 | 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 |
||
71097 | 101 |
/** command-line tools **/ |
102 |
||
103 |
/* Isabelle tool wrapper */ |
|
104 |
||
105 |
val isabelle_tool1 = |
|
106 |
Isabelle_Tool("phabricator", "invoke command-line tool within Phabricator home directory", args => |
|
107 |
{ |
|
71101 | 108 |
var list = false |
71097 | 109 |
var name = default_name |
110 |
||
111 |
val getopts = |
|
112 |
Getopts(""" |
|
113 |
Usage: isabelle phabricator [OPTIONS] COMMAND [ARGS...] |
|
114 |
||
115 |
Options are: |
|
71101 | 116 |
-l list available Phabricator installations |
71097 | 117 |
-n NAME Phabricator installation name (default: """ + quote(default_name) + """) |
118 |
||
71103 | 119 |
Invoke a command-line tool within the home directory of the named |
120 |
Phabricator installation. |
|
71097 | 121 |
""", |
71101 | 122 |
"l" -> (_ => list = true), |
71097 | 123 |
"n:" -> (arg => name = arg)) |
124 |
||
125 |
val more_args = getopts(args) |
|
71101 | 126 |
if (more_args.isEmpty && !list) getopts.usage() |
71097 | 127 |
|
128 |
val progress = new Console_Progress |
|
129 |
||
71101 | 130 |
if (list) { |
131 |
for (config <- read_config()) { |
|
71103 | 132 |
progress.echo("phabricator " + quote(config.name) + " root " + config.root) |
71101 | 133 |
} |
134 |
} |
|
135 |
||
71097 | 136 |
val config = get_config(name) |
137 |
||
71098 | 138 |
val result = progress.bash(Bash.strings(more_args), cwd = config.home.file, echo = true) |
139 |
if (!result.ok) error("Return code: " + result.rc.toString) |
|
71097 | 140 |
}) |
141 |
||
142 |
||
143 |
||
70967 | 144 |
/** setup **/ |
145 |
||
71049 | 146 |
def user_setup(name: String, description: String, ssh_setup: Boolean = false) |
147 |
{ |
|
148 |
if (!Linux.user_exists(name)) { |
|
71054
b64fc38327ae
prefer system user setup, e.g. avoid occurrence on login screen;
wenzelm
parents:
71053
diff
changeset
|
149 |
Linux.user_add(name, description = description, system = true, ssh_setup = ssh_setup) |
71049 | 150 |
} |
151 |
else if (Linux.user_description(name) != description) { |
|
152 |
error("User " + quote(name) + " already exists --" + |
|
153 |
" for Phabricator it should have the description:\n " + quote(description)) |
|
154 |
} |
|
155 |
} |
|
156 |
||
70967 | 157 |
def phabricator_setup( |
158 |
name: String = default_name, |
|
159 |
root: String = "", |
|
160 |
repo: String = "", |
|
71047 | 161 |
package_update: Boolean = false, |
70967 | 162 |
progress: Progress = No_Progress) |
163 |
{ |
|
164 |
/* system environment */ |
|
165 |
||
166 |
Linux.check_system_root() |
|
167 |
||
71079 | 168 |
progress.echo("System packages ...") |
169 |
||
71047 | 170 |
if (package_update) { |
171 |
Linux.package_update(progress = progress) |
|
172 |
Linux.check_reboot_required() |
|
173 |
} |
|
70967 | 174 |
|
175 |
Linux.package_install(packages, progress = progress) |
|
176 |
Linux.check_reboot_required() |
|
177 |
||
178 |
||
71049 | 179 |
/* users */ |
180 |
||
181 |
if (name == daemon_user) { |
|
182 |
error("Clash of installation name with daemon user " + quote(daemon_user)) |
|
183 |
} |
|
184 |
||
185 |
user_setup(daemon_user, "Phabricator Daemon User", ssh_setup = true) |
|
186 |
user_setup(name, "Phabricator SSH User") |
|
187 |
||
188 |
||
70967 | 189 |
/* basic installation */ |
190 |
||
71079 | 191 |
progress.echo("\nPhabricator installation ...") |
71076 | 192 |
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
193 |
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
|
194 |
val repo_path = if (repo.nonEmpty) Path.explode(repo) else default_repo(name) |
70967 | 195 |
|
196 |
val configs = read_config() |
|
197 |
||
198 |
for (config <- configs if config.name == name) { |
|
199 |
error("Duplicate Phabricator installation " + quote(name) + " in " + config.root) |
|
200 |
} |
|
201 |
||
202 |
if (!Isabelle_System.bash("mkdir -p " + File.bash_path(root_path)).ok) { |
|
203 |
error("Failed to create root directory " + root_path) |
|
204 |
} |
|
205 |
||
206 |
progress.bash(cwd = root_path.file, echo = true, |
|
207 |
script = """ |
|
208 |
set -e |
|
71050 | 209 |
chown """ + Bash.string(www_user) + ":" + Bash.string(www_user) + """ . |
70967 | 210 |
chmod 755 . |
211 |
||
212 |
git clone https://github.com/phacility/libphutil.git |
|
213 |
git clone https://github.com/phacility/arcanist.git |
|
214 |
git clone https://github.com/phacility/phabricator.git |
|
215 |
""").check |
|
216 |
||
217 |
val config = Config(name, root_path) |
|
218 |
write_config(configs ::: List(config)) |
|
70968 | 219 |
|
71051 | 220 |
config.execute("config set pygments.enabled true") |
221 |
||
70968 | 222 |
|
71050 | 223 |
/* local repository directory */ |
224 |
||
225 |
if (!Isabelle_System.bash("mkdir -p " + File.bash_path(repo_path)).ok) { |
|
226 |
error("Failed to create local repository directory " + repo_path) |
|
227 |
} |
|
228 |
||
229 |
Isabelle_System.bash(cwd = repo_path.file, |
|
230 |
script = """ |
|
231 |
set -e |
|
232 |
chown -R """ + Bash.string(daemon_user) + ":" + Bash.string(daemon_user) + """ . |
|
233 |
chmod 755 . |
|
234 |
""").check |
|
235 |
||
236 |
config.execute("config set repository.default-local-path " + File.bash_path(repo_path)) |
|
237 |
||
238 |
||
70969 | 239 |
/* MySQL setup */ |
240 |
||
71079 | 241 |
progress.echo("\nMySQL setup ...") |
70969 | 242 |
|
71055
27a998cdc0f4
back to plain name, to have it accepted my mysql;
wenzelm
parents:
71054
diff
changeset
|
243 |
File.write(Path.explode("/etc/mysql/mysql.conf.d/" + phabricator_name(ext = "cnf")), |
71051 | 244 |
"""[mysqld] |
245 |
max_allowed_packet = 32M |
|
246 |
innodb_buffer_pool_size = 1600M |
|
247 |
local_infile = 0 |
|
248 |
""") |
|
249 |
||
250 |
Linux.service_restart("mysql") |
|
251 |
||
252 |
||
70969 | 253 |
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
|
254 |
split_lines(File.read(Path.explode("/etc/mysql/debian.cnf"))).collectFirst({ case R(a) => a }) |
70969 | 255 |
|
256 |
for (user <- mysql_conf("""^user\s*=\s*(\S*)\s*$""".r)) { |
|
257 |
config.execute("config set mysql.user " + Bash.string(user)) |
|
258 |
} |
|
259 |
||
260 |
for (pass <- mysql_conf("""^password\s*=\s*(\S*)\s*$""".r)) { |
|
261 |
config.execute("config set mysql.pass " + Bash.string(pass)) |
|
262 |
} |
|
263 |
||
264 |
config.execute("config set storage.default-namespace " + |
|
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
265 |
Bash.string(phabricator_name(name = name).replace("-", "_"))) |
70969 | 266 |
|
71051 | 267 |
config.execute("config set storage.mysql-engine.max-size 8388608") |
268 |
||
71102 | 269 |
progress.bash("bin/storage upgrade --force", cwd = config.home.file, echo = true).check |
70969 | 270 |
|
271 |
||
71049 | 272 |
/* SSH hosting */ |
273 |
||
71079 | 274 |
progress.echo("\nSSH hosting setup ...") |
71049 | 275 |
|
276 |
val ssh_port = ssh_alternative2 |
|
277 |
||
278 |
config.execute("config set diffusion.ssh-user " + Bash.string(name)) |
|
279 |
config.execute("config set diffusion.ssh-port " + ssh_port) |
|
280 |
||
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
281 |
val sudoers_file = Path.explode("/etc/sudoers.d") + Path.basic(isabelle_phabricator_name()) |
71049 | 282 |
File.write(sudoers_file, |
283 |
www_user + " ALL=(" + daemon_user + ") SETENV: NOPASSWD: /usr/bin/git, /usr/bin/hg, /usr/bin/ssh, /usr/bin/id\n" + |
|
284 |
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") |
|
285 |
||
286 |
Isabelle_System.bash("chmod 0440 " + File.bash_path(sudoers_file)).check |
|
287 |
||
288 |
||
71051 | 289 |
/* PHP setup */ |
290 |
||
291 |
val php_version = |
|
292 |
Isabelle_System.bash("""php --run 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;'""") |
|
293 |
.check.out |
|
294 |
||
295 |
val php_conf = |
|
296 |
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
|
297 |
Path.explode("apache2/conf.d") + |
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
298 |
Path.basic(isabelle_phabricator_name(ext = "ini")) |
71051 | 299 |
|
300 |
File.write(php_conf, |
|
301 |
"post_max_size = 32M\n" + |
|
302 |
"opcache.validate_timestamps = 0\n" + |
|
303 |
"memory_limit = 512M\n") |
|
304 |
||
305 |
||
70968 | 306 |
/* Apache setup */ |
307 |
||
71079 | 308 |
progress.echo("Apache setup ...") |
70968 | 309 |
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
310 |
val apache_root = Path.explode("/etc/apache2") |
70968 | 311 |
val apache_sites = apache_root + Path.explode("sites-available") |
312 |
||
313 |
if (!apache_sites.is_dir) error("Bad Apache sites directory " + apache_sites) |
|
314 |
||
71058 | 315 |
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
|
316 |
val server_url = "http://" + server_name |
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
317 |
|
71058 | 318 |
File.write(apache_sites + Path.basic(isabelle_phabricator_name(name = name, ext = "conf")), |
70968 | 319 |
"""<VirtualHost *:80> |
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
320 |
ServerName """ + server_name + """ |
70968 | 321 |
ServerAdmin webmaster@localhost |
70969 | 322 |
DocumentRoot """ + config.home.implode + """/webroot |
70968 | 323 |
|
324 |
ErrorLog ${APACHE_LOG_DIR}/error.log |
|
325 |
RewriteEngine on |
|
326 |
RewriteRule ^(.*)$ /index.php?__path__=$1 [B,L,QSA] |
|
327 |
</VirtualHost> |
|
328 |
||
329 |
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet |
|
330 |
""") |
|
331 |
||
71051 | 332 |
Isabelle_System.bash( """ |
70968 | 333 |
set -e |
334 |
a2enmod rewrite |
|
71058 | 335 |
a2ensite """ + Bash.string(isabelle_phabricator_name(name = name))).check |
71051 | 336 |
|
71057 | 337 |
config.execute("config set phabricator.base-uri " + Bash.string(server_url)) |
338 |
||
71051 | 339 |
Linux.service_restart("apache2") |
70968 | 340 |
|
71053 | 341 |
|
342 |
/* PHP daemon */ |
|
343 |
||
71079 | 344 |
progress.echo("PHP daemon setup ...") |
71053 | 345 |
|
346 |
config.execute("config set phd.user " + Bash.string(daemon_user)) |
|
347 |
||
71056
ee3c43eb79ae
proper service name (again): it is specific to each installation;
wenzelm
parents:
71055
diff
changeset
|
348 |
Linux.service_install(isabelle_phabricator_name(name = name), |
71053 | 349 |
"""[Unit] |
350 |
Description=PHP daemon for Isabelle/Phabricator """ + quote(name) + """ |
|
351 |
After=syslog.target network.target apache2.service mysql.service |
|
352 |
||
353 |
[Service] |
|
354 |
Type=oneshot |
|
355 |
User=""" + daemon_user + """ |
|
356 |
Group=""" + daemon_user + """ |
|
357 |
Environment=PATH=/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin |
|
358 |
ExecStart=""" + config.home.implode + """/bin/phd start |
|
359 |
ExecStop=""" + config.home.implode + """/bin/phd stop |
|
360 |
RemainAfterExit=yes |
|
361 |
||
362 |
[Install] |
|
363 |
WantedBy=multi-user.target |
|
364 |
""") |
|
365 |
||
366 |
||
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
367 |
progress.echo("\nDONE\nWeb configuration via " + server_url) |
70967 | 368 |
} |
369 |
||
370 |
||
371 |
/* Isabelle tool wrapper */ |
|
372 |
||
71097 | 373 |
val isabelle_tool2 = |
70967 | 374 |
Isabelle_Tool("phabricator_setup", "setup Phabricator server on Ubuntu Linux", args => |
375 |
{ |
|
71047 | 376 |
var repo = "" |
377 |
var package_update = false |
|
71078 | 378 |
var name = default_name |
70967 | 379 |
var root = "" |
380 |
||
381 |
val getopts = |
|
382 |
Getopts(""" |
|
71078 | 383 |
Usage: isabelle phabricator_setup [OPTIONS] |
70967 | 384 |
|
385 |
Options are: |
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
386 |
-R DIR repository directory (default: """ + default_repo("NAME") + """) |
71047 | 387 |
-U full update of system packages before installation |
71078 | 388 |
-n NAME Phabricator installation name (default: """ + quote(default_name) + """) |
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
389 |
-r DIR installation root directory (default: """ + default_root("NAME") + """) |
70967 | 390 |
|
71103 | 391 |
Install Phabricator as LAMP application (Linux, Apache, MySQL, PHP). |
70967 | 392 |
|
71078 | 393 |
The installation name (default: """ + quote(default_name) + """) is mapped to a regular |
394 |
Unix user; this is relevant for public SSH access. |
|
70967 | 395 |
""", |
396 |
"R:" -> (arg => repo = arg), |
|
71047 | 397 |
"U" -> (_ => package_update = true), |
71078 | 398 |
"n:" -> (arg => name = arg), |
70967 | 399 |
"r:" -> (arg => root = arg)) |
400 |
||
401 |
val more_args = getopts(args) |
|
71078 | 402 |
if (more_args.nonEmpty) getopts.usage() |
70967 | 403 |
|
404 |
val progress = new Console_Progress |
|
405 |
||
71078 | 406 |
phabricator_setup(name = name, root = root, repo = repo, |
71047 | 407 |
package_update = package_update, progress = progress) |
70967 | 408 |
}) |
409 |
||
410 |
||
411 |
||
71066 | 412 |
/** setup mail **/ |
70967 | 413 |
|
71072 | 414 |
val mailers_template: String = |
415 |
"""[ |
|
416 |
{ |
|
417 |
"key": "example.org", |
|
418 |
"type": "smtp", |
|
419 |
"options": { |
|
420 |
"host": "mail.example.org", |
|
421 |
"port": 465, |
|
422 |
"user": "phabricator@example.org", |
|
423 |
"password": "********", |
|
424 |
"protocol": "ssl", |
|
425 |
"message-id": true |
|
426 |
} |
|
427 |
} |
|
428 |
]""" |
|
429 |
||
71066 | 430 |
def phabricator_setup_mail( |
431 |
name: String = default_name, |
|
432 |
config_file: Option[Path] = None, |
|
433 |
test_user: String = "", |
|
434 |
progress: Progress = No_Progress) |
|
70967 | 435 |
{ |
436 |
Linux.check_system_root() |
|
437 |
||
71066 | 438 |
val config = get_config(name) |
71073 | 439 |
val default_config_file = config.root + default_mailers |
71066 | 440 |
|
441 |
val mail_config = config_file getOrElse default_config_file |
|
442 |
||
443 |
def setup_mail |
|
444 |
{ |
|
445 |
progress.echo("Using mail configuration from " + mail_config) |
|
446 |
config.execute("config set cluster.mailers --stdin < " + File.bash_path(mail_config)) |
|
447 |
||
448 |
if (test_user.nonEmpty) { |
|
449 |
progress.echo("Sending test mail to " + quote(test_user)) |
|
450 |
progress.bash(cwd = config.home.file, echo = true, |
|
71102 | 451 |
script = """echo "Test from Phabricator ($(date))" | bin/mail send-test --subject "Test" --to """ + |
71066 | 452 |
Bash.string(test_user)).check |
453 |
} |
|
454 |
} |
|
455 |
||
456 |
if (config_file.isEmpty) { |
|
71070 | 457 |
if (!default_config_file.is_file) { |
458 |
File.write(default_config_file, mailers_template) |
|
459 |
Isabelle_System.bash("chmod 600 " + File.bash_path(default_config_file)).check |
|
460 |
} |
|
71066 | 461 |
if (File.read(default_config_file) == mailers_template) { |
462 |
progress.echo( |
|
71077 | 463 |
""" |
464 |
Please invoke the tool again, after providing details in |
|
465 |
""" + default_config_file.implode + """ |
|
466 |
||
467 |
See also section "Mailer: SMTP" in |
|
468 |
https://secure.phabricator.com/book/phabricator/article/configuring_outbound_email |
|
469 |
""") |
|
71066 | 470 |
} |
471 |
else setup_mail |
|
472 |
} |
|
473 |
else setup_mail |
|
70967 | 474 |
} |
475 |
||
476 |
||
477 |
/* Isabelle tool wrapper */ |
|
478 |
||
71097 | 479 |
val isabelle_tool3 = |
71066 | 480 |
Isabelle_Tool("phabricator_setup_mail", |
481 |
"setup mail configuration for existing Phabricator server", args => |
|
70967 | 482 |
{ |
71066 | 483 |
var test_user = "" |
484 |
var name = default_name |
|
485 |
var config_file: Option[Path] = None |
|
486 |
||
70967 | 487 |
val getopts = |
488 |
Getopts(""" |
|
71066 | 489 |
Usage: isabelle phabricator_setup_mail [OPTIONS] |
490 |
||
491 |
Options are: |
|
492 |
-T USER send test mail to Phabricator user |
|
71103 | 493 |
-f FILE config file (default: """ + default_mailers + """ within Phabricator root) |
71066 | 494 |
-n NAME Phabricator installation name (default: """ + quote(default_name) + """) |
70967 | 495 |
|
71077 | 496 |
Provide mail configuration for existing Phabricator installation. |
71066 | 497 |
""", |
498 |
"T:" -> (arg => test_user = arg), |
|
499 |
"f:" -> (arg => config_file = Some(Path.explode(arg))), |
|
500 |
"n:" -> (arg => name = arg)) |
|
70967 | 501 |
|
502 |
val more_args = getopts(args) |
|
71066 | 503 |
if (more_args.nonEmpty) getopts.usage() |
70967 | 504 |
|
505 |
val progress = new Console_Progress |
|
506 |
||
71066 | 507 |
phabricator_setup_mail(name = name, config_file = config_file, |
508 |
test_user = test_user, progress = progress) |
|
70967 | 509 |
}) |
510 |
} |