| author | wenzelm |
| Tue, 23 Jan 2024 12:28:02 +0100 | |
| changeset 79516 | eeacad2a7aaa |
| parent 79515 | fa581264522e |
| child 79517 | 0856026e2c88 |
| permissions | -rw-r--r-- |
| 70967 | 1 |
/* Title: Pure/Tools/phabricator.scala |
2 |
Author: Makarius |
|
3 |
||
| 79496 | 4 |
Support for Phabricator server, notably for Ubuntu 20.04 or 22.04 LTS. |
|
71068
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 |
||
| 71330 | 14 |
import scala.collection.mutable |
| 70969 | 15 |
import scala.util.matching.Regex |
16 |
||
17 |
||
| 75393 | 18 |
object Phabricator {
|
| 70967 | 19 |
/** defaults **/ |
20 |
||
| 79512 | 21 |
/* webservers */ |
22 |
||
23 |
sealed abstract class Webserver {
|
|
24 |
override def toString: String = title |
|
25 |
def title: String |
|
26 |
def short_name: String |
|
27 |
def system_name: String = short_name |
|
| 79513 | 28 |
def php_name: String = short_name |
| 79512 | 29 |
|
30 |
def packages(): List[String] |
|
31 |
||
32 |
def system_path: Path = Path.basic(system_name) |
|
33 |
def root_dir: Path = Path.explode("/etc") + system_path
|
|
34 |
def sites_dir: Path = root_dir + Path.explode("sites-available")
|
|
35 |
||
36 |
def restart(): Unit = Linux.service_restart(system_name) |
|
37 |
||
| 79513 | 38 |
def php_init(): Unit = |
| 79515 | 39 |
File.write(Linux.php_conf_dir(php_name) + Path.basic(isabelle_phabricator_name(ext = "ini")), |
| 79513 | 40 |
"post_max_size = 32M\n" + |
41 |
"opcache.validate_timestamps = 0\n" + |
|
42 |
"memory_limit = 512M\n" + |
|
43 |
"max_execution_time = 120\n") |
|
| 79512 | 44 |
|
45 |
def site_name(name: String): String = isabelle_phabricator_name(name = name) |
|
46 |
||
47 |
def site_conf(name: String): Path = |
|
48 |
sites_dir + Path.basic(isabelle_phabricator_name(name = name, ext = "conf")) |
|
49 |
||
50 |
def site_init(name: String, server_name: String, webroot: String): Unit |
|
51 |
} |
|
52 |
||
53 |
object Apache extends Webserver {
|
|
54 |
override val title = "Apache" |
|
55 |
override val short_name = "apache" |
|
56 |
override def system_name = "apache2" |
|
57 |
override def packages(): List[String] = List("apache2", "libapache2-mod-php")
|
|
58 |
||
59 |
override def site_init(name: String, server_name: String, webroot: String): Unit = {
|
|
60 |
File.write(site_conf(name), |
|
61 |
"""<VirtualHost *:80> |
|
62 |
ServerName """ + server_name + """ |
|
63 |
ServerAdmin webmaster@localhost |
|
64 |
DocumentRoot """ + webroot + """ |
|
65 |
||
66 |
ErrorLog ${APACHE_LOG_DIR}/error.log
|
|
67 |
CustomLog ${APACHE_LOG_DIR}/access.log combined
|
|
68 |
||
69 |
RewriteEngine on |
|
70 |
RewriteRule ^(.*)$ /index.php?__path__=$1 [B,L,QSA] |
|
71 |
</VirtualHost> |
|
72 |
||
73 |
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet |
|
74 |
""") |
|
75 |
Isabelle_System.bash("""
|
|
76 |
set -e |
|
77 |
a2enmod rewrite |
|
78 |
a2ensite """ + Bash.string(site_name(name))).check |
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
object Nginx extends Webserver {
|
|
83 |
override val title = "Nginx" |
|
84 |
override val short_name = "nginx" |
|
| 79513 | 85 |
override val php_name = "fpm" |
| 79512 | 86 |
override def packages(): List[String] = List("nginx", "php-fpm")
|
87 |
||
88 |
override def site_init(name: String, server_name: String, webroot: String): Unit = {
|
|
89 |
File.write(site_conf(name), |
|
90 |
""" |
|
91 |
server {
|
|
92 |
server_name """ + server_name + """; |
|
93 |
root """ + webroot + """; |
|
94 |
||
95 |
location / {
|
|
96 |
index index.php; |
|
97 |
rewrite ^/(.*)$ /index.php?__path__=/$1 last; |
|
98 |
} |
|
99 |
||
100 |
location ~ \.php$ {
|
|
101 |
include snippets/fastcgi-php.conf; |
|
| 79515 | 102 |
fastcgi_pass unix:/var/run/php/php""" + Linux.php_version() + """-fpm.sock; |
| 79512 | 103 |
} |
104 |
||
105 |
location /index.php {
|
|
106 |
fastcgi_index index.php; |
|
107 |
||
108 |
#required if PHP was built with --enable-force-cgi-redirect |
|
109 |
fastcgi_param REDIRECT_STATUS 200; |
|
110 |
||
111 |
#variables to make the $_SERVER populate in PHP |
|
112 |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |
|
113 |
fastcgi_param QUERY_STRING $query_string; |
|
114 |
fastcgi_param REQUEST_METHOD $request_method; |
|
115 |
fastcgi_param CONTENT_TYPE $content_type; |
|
116 |
fastcgi_param CONTENT_LENGTH $content_length; |
|
117 |
||
118 |
fastcgi_param SCRIPT_NAME $fastcgi_script_name; |
|
119 |
||
120 |
fastcgi_param GATEWAY_INTERFACE CGI/1.1; |
|
121 |
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; |
|
122 |
||
123 |
fastcgi_param REMOTE_ADDR $remote_addr; |
|
124 |
} |
|
125 |
} |
|
126 |
""") |
|
127 |
Isabelle_System.bash( |
|
128 |
"ln -sf " + File.bash_path(site_conf(name)) + " /etc/nginx/sites-enabled/.").check |
|
129 |
} |
|
130 |
} |
|
131 |
||
132 |
val all_webservers: List[Webserver] = List(Apache, Nginx) |
|
133 |
||
134 |
def get_webserver(name: String): Webserver = |
|
135 |
all_webservers.find(w => w.short_name == name) getOrElse |
|
136 |
error("Bad webserver " + quote(name))
|
|
137 |
||
138 |
val default_webserver: Webserver = Apache |
|
139 |
||
140 |
||
141 |
||
142 |
/* system packages */ |
|
| 71049 | 143 |
|
|
73534
e7fb17bca374
discontinue old Ubuntu 18.04 LTS, e.g. it cannot build documentation "prog-prove";
wenzelm
parents:
73415
diff
changeset
|
144 |
val packages_ubuntu_20_04: List[String] = |
|
77567
b975f5aaf6b8
renamed "isabelle build_docker" to "isabelle docker_build" (unrelated to "isabelle build");
wenzelm
parents:
77369
diff
changeset
|
145 |
Docker_Build.packages ::: |
| 71049 | 146 |
List( |
147 |
// https://secure.phabricator.com/source/phabricator/browse/master/scripts/install/install_ubuntu.sh 15e6e2adea61 |
|
| 79512 | 148 |
"git", "mysql-server", "php", "php-mysql", "php-gd", "php-curl", "php-apcu", "php-cli", |
149 |
"php-json", "php-mbstring", |
|
| 71049 | 150 |
// more packages |
|
73534
e7fb17bca374
discontinue old Ubuntu 18.04 LTS, e.g. it cannot build documentation "prog-prove";
wenzelm
parents:
73415
diff
changeset
|
151 |
"php-xml", "php-zip", "python3-pygments", "ssh", "subversion", "python-pygments", |
|
71280
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
152 |
// mercurial build packages |
|
73534
e7fb17bca374
discontinue old Ubuntu 18.04 LTS, e.g. it cannot build documentation "prog-prove";
wenzelm
parents:
73415
diff
changeset
|
153 |
"make", "gcc", "python", "python2-dev", "python-docutils", "python-openssl") |
| 72521 | 154 |
|
|
79487
47272fac86d8
support Phabricator on Ubuntu 22.04 LTS with PHP 8.1, using community form we.phorge.it version "2023 week 49";
wenzelm
parents:
79482
diff
changeset
|
155 |
val packages_ubuntu_22_04: List[String] = |
|
47272fac86d8
support Phabricator on Ubuntu 22.04 LTS with PHP 8.1, using community form we.phorge.it version "2023 week 49";
wenzelm
parents:
79482
diff
changeset
|
156 |
Docker_Build.packages ::: |
|
47272fac86d8
support Phabricator on Ubuntu 22.04 LTS with PHP 8.1, using community form we.phorge.it version "2023 week 49";
wenzelm
parents:
79482
diff
changeset
|
157 |
List( |
|
47272fac86d8
support Phabricator on Ubuntu 22.04 LTS with PHP 8.1, using community form we.phorge.it version "2023 week 49";
wenzelm
parents:
79482
diff
changeset
|
158 |
// https://secure.phabricator.com/source/phabricator/browse/master/scripts/install/install_ubuntu.sh 15e6e2adea61 |
| 79512 | 159 |
"git", "mysql-server", "php", "php-mysql", "php-gd", "php-curl", "php-apcu", "php-cli", |
160 |
"php-json", "php-mbstring", |
|
|
79487
47272fac86d8
support Phabricator on Ubuntu 22.04 LTS with PHP 8.1, using community form we.phorge.it version "2023 week 49";
wenzelm
parents:
79482
diff
changeset
|
161 |
// more packages |
|
47272fac86d8
support Phabricator on Ubuntu 22.04 LTS with PHP 8.1, using community form we.phorge.it version "2023 week 49";
wenzelm
parents:
79482
diff
changeset
|
162 |
"php-xml", "php-zip", "python3-pygments", "ssh", "subversion") |
|
47272fac86d8
support Phabricator on Ubuntu 22.04 LTS with PHP 8.1, using community form we.phorge.it version "2023 week 49";
wenzelm
parents:
79482
diff
changeset
|
163 |
|
| 79512 | 164 |
def packages(webserver: Webserver): List[String] = {
|
| 72521 | 165 |
val release = Linux.Release() |
| 79512 | 166 |
val pkgs = |
167 |
if (release.is_ubuntu_20_04) packages_ubuntu_20_04 |
|
168 |
else if (release.is_ubuntu_22_04) packages_ubuntu_22_04 |
|
169 |
else error("Bad Linux version: expected Ubuntu 20.04 or 22.04 LTS")
|
|
170 |
pkgs ::: webserver.packages() |
|
| 72521 | 171 |
} |
172 |
||
| 71049 | 173 |
|
174 |
/* global system resources */ |
|
175 |
||
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
176 |
val www_user = "www-data" |
|
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
177 |
|
| 71049 | 178 |
val daemon_user = "phabricator" |
179 |
||
| 71601 | 180 |
val sshd_config: Path = Path.explode("/etc/ssh/sshd_config")
|
| 71049 | 181 |
|
182 |
||
183 |
/* installation parameters */ |
|
184 |
||
| 70967 | 185 |
val default_name = "vcs" |
186 |
||
|
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
187 |
def phabricator_name(name: String = "", ext: String = ""): String = |
| 77368 | 188 |
"phabricator" + if_proper(name, "-" + name) + if_proper(ext, "." + ext) |
|
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
189 |
|
|
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
190 |
def isabelle_phabricator_name(name: String = "", ext: String = ""): String = |
|
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
191 |
"isabelle-" + phabricator_name(name = name, ext = ext) |
| 70967 | 192 |
|
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
193 |
def default_root(name: String): Path = |
|
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
194 |
Path.explode("/var/www") + Path.basic(phabricator_name(name = name))
|
| 70967 | 195 |
|
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
196 |
def default_repo(name: String): Path = default_root(name) + Path.basic("repo")
|
| 70967 | 197 |
|
| 71072 | 198 |
val default_mailers: Path = Path.explode("mailers.json")
|
| 71066 | 199 |
|
| 76129 | 200 |
val default_system_port: Int = 22 |
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
201 |
val alternative_system_port = 222 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
202 |
val default_server_port = 2222 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
203 |
|
|
71440
8b0b8b9ea653
afford newer Mercurial version, just before odd problems in 4.0 and 4.1;
wenzelm
parents:
71439
diff
changeset
|
204 |
val standard_mercurial_source = "https://www.mercurial-scm.org/release/mercurial-3.9.2.tar.gz" |
|
71280
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
205 |
|
| 70967 | 206 |
|
207 |
||
208 |
/** global configuration **/ |
|
209 |
||
| 71601 | 210 |
val global_config: Path = Path.explode("/etc/" + isabelle_phabricator_name(ext = "conf"))
|
| 70967 | 211 |
|
| 71122 | 212 |
def global_config_script( |
213 |
init: String = "", |
|
214 |
body: String = "", |
|
| 75393 | 215 |
exit: String = ""): String = {
|
| 71282 | 216 |
"""#!/bin/bash |
| 77369 | 217 |
""" + if_proper(init, "\n" + init) + """ |
| 71284 | 218 |
{
|
| 71122 | 219 |
while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
|
220 |
do |
|
221 |
NAME="$(echo "$REPLY" | cut -d: -f1)" |
|
222 |
ROOT="$(echo "$REPLY" | cut -d: -f2)" |
|
| 71284 | 223 |
{
|
| 73736 | 224 |
""" + Library.indent_lines(6, body) + """ |
| 71284 | 225 |
} < /dev/null |
226 |
done |
|
227 |
} < """ + File.bash_path(global_config) + "\n" + |
|
| 77369 | 228 |
if_proper(exit, "\n" + exit + "\n") |
| 71122 | 229 |
} |
230 |
||
| 75393 | 231 |
sealed case class Config(name: String, root: Path) {
|
|
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
232 |
def home: Path = root + Path.explode(phabricator_name()) |
| 70969 | 233 |
|
234 |
def execute(command: String): Process_Result = |
|
| 71102 | 235 |
Isabelle_System.bash("bin/" + command, cwd = home.file, redirect = true).check
|
| 79512 | 236 |
|
237 |
def webroot: String = home.implode + "/webroot" |
|
| 70968 | 238 |
} |
| 70967 | 239 |
|
| 75393 | 240 |
def read_config(): List[Config] = {
|
| 70967 | 241 |
if (global_config.is_file) {
|
242 |
for (entry <- Library.trim_split_lines(File.read(global_config)) if entry.nonEmpty) |
|
243 |
yield {
|
|
244 |
space_explode(':', entry) match {
|
|
245 |
case List(name, root) => Config(name, Path.explode(root)) |
|
246 |
case _ => error("Malformed config file " + global_config + "\nentry " + quote(entry))
|
|
247 |
} |
|
248 |
} |
|
249 |
} |
|
250 |
else Nil |
|
251 |
} |
|
252 |
||
| 75393 | 253 |
def write_config(configs: List[Config]): Unit = {
|
| 70967 | 254 |
File.write(global_config, |
255 |
configs.map(config => config.name + ":" + config.root.implode).mkString("", "\n", "\n"))
|
|
256 |
} |
|
257 |
||
258 |
def get_config(name: String): Config = |
|
259 |
read_config().find(config => config.name == name) getOrElse |
|
260 |
error("Bad Isabelle/Phabricator installation " + quote(name))
|
|
261 |
||
262 |
||
263 |
||
| 71299 | 264 |
/** administrative tools **/ |
| 71097 | 265 |
|
266 |
/* Isabelle tool wrapper */ |
|
267 |
||
268 |
val isabelle_tool1 = |
|
| 72763 | 269 |
Isabelle_Tool("phabricator", "invoke command-line tool within Phabricator home directory",
|
| 75393 | 270 |
Scala_Project.here, |
| 75394 | 271 |
{ args =>
|
272 |
var list = false |
|
273 |
var name = default_name |
|
| 71097 | 274 |
|
| 75394 | 275 |
val getopts = Getopts("""
|
| 71097 | 276 |
Usage: isabelle phabricator [OPTIONS] COMMAND [ARGS...] |
277 |
||
278 |
Options are: |
|
| 71101 | 279 |
-l list available Phabricator installations |
| 71097 | 280 |
-n NAME Phabricator installation name (default: """ + quote(default_name) + """) |
281 |
||
| 71103 | 282 |
Invoke a command-line tool within the home directory of the named |
283 |
Phabricator installation. |
|
| 71097 | 284 |
""", |
| 71101 | 285 |
"l" -> (_ => list = true), |
| 71097 | 286 |
"n:" -> (arg => name = arg)) |
287 |
||
| 75394 | 288 |
val more_args = getopts(args) |
289 |
if (more_args.isEmpty && !list) getopts.usage() |
|
| 71097 | 290 |
|
| 75394 | 291 |
val progress = new Console_Progress |
| 71097 | 292 |
|
| 75394 | 293 |
if (list) {
|
294 |
for (config <- read_config()) {
|
|
295 |
progress.echo("phabricator " + quote(config.name) + " root " + config.root)
|
|
296 |
} |
|
| 71101 | 297 |
} |
| 75394 | 298 |
else {
|
299 |
val config = get_config(name) |
|
300 |
val result = progress.bash(Bash.strings(more_args), cwd = config.home.file, echo = true) |
|
301 |
if (!result.ok) error(result.print_return_code) |
|
302 |
} |
|
303 |
}) |
|
| 71097 | 304 |
|
305 |
||
306 |
||
| 70967 | 307 |
/** setup **/ |
308 |
||
| 75393 | 309 |
def user_setup(name: String, description: String, ssh_setup: Boolean = false): Unit = {
|
| 71049 | 310 |
if (!Linux.user_exists(name)) {
|
|
71054
b64fc38327ae
prefer system user setup, e.g. avoid occurrence on login screen;
wenzelm
parents:
71053
diff
changeset
|
311 |
Linux.user_add(name, description = description, system = true, ssh_setup = ssh_setup) |
| 71049 | 312 |
} |
313 |
else if (Linux.user_description(name) != description) {
|
|
314 |
error("User " + quote(name) + " already exists --" +
|
|
315 |
" for Phabricator it should have the description:\n " + quote(description)) |
|
316 |
} |
|
317 |
} |
|
318 |
||
| 71282 | 319 |
def command_setup(name: String, |
320 |
init: String = "", |
|
321 |
body: String = "", |
|
| 75393 | 322 |
exit: String = "" |
323 |
): Path = {
|
|
| 71270 | 324 |
val command = Path.explode("/usr/local/bin") + Path.basic(name)
|
| 71282 | 325 |
File.write(command, global_config_script(init = init, body = body, exit = exit)) |
| 71270 | 326 |
Isabelle_System.chmod("755", command)
|
327 |
Isabelle_System.chown("root:root", command)
|
|
328 |
command |
|
329 |
} |
|
330 |
||
| 75393 | 331 |
def mercurial_setup(mercurial_source: String, progress: Progress = new Progress): Unit = {
|
| 71281 | 332 |
progress.echo("\nMercurial installation from source " + quote(mercurial_source) + " ...")
|
| 75394 | 333 |
Isabelle_System.with_tmp_dir("mercurial") { tmp_dir =>
|
|
71280
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
334 |
val archive = |
|
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
335 |
if (Url.is_wellformed(mercurial_source)) {
|
|
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
336 |
val archive = tmp_dir + Path.basic("mercurial.tar.gz")
|
| 73566 | 337 |
Isabelle_System.download_file(mercurial_source, archive) |
|
71280
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
338 |
archive |
|
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
339 |
} |
|
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
340 |
else Path.explode(mercurial_source) |
|
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
341 |
|
|
76540
83de6e9ae983
clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents:
76529
diff
changeset
|
342 |
Isabelle_System.extract(archive, tmp_dir) |
| 76529 | 343 |
val build_dir = File.get_dir(tmp_dir, title = mercurial_source) |
|
71280
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
344 |
|
| 72442 | 345 |
progress.bash("make all && make install", cwd = build_dir.file, echo = true).check
|
| 75394 | 346 |
} |
|
71280
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
347 |
} |
|
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
348 |
|
| 70967 | 349 |
def phabricator_setup( |
|
71422
5d5be87330b5
allow to override repository versions at runtime;
wenzelm
parents:
71421
diff
changeset
|
350 |
options: Options, |
| 70967 | 351 |
name: String = default_name, |
352 |
root: String = "", |
|
353 |
repo: String = "", |
|
| 79512 | 354 |
webserver: Webserver = default_webserver, |
| 71047 | 355 |
package_update: Boolean = false, |
|
71280
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
356 |
mercurial_source: String = "", |
| 75393 | 357 |
progress: Progress = new Progress |
358 |
): Unit = {
|
|
| 70967 | 359 |
/* system environment */ |
360 |
||
361 |
Linux.check_system_root() |
|
362 |
||
| 71079 | 363 |
progress.echo("System packages ...")
|
364 |
||
| 71047 | 365 |
if (package_update) {
|
366 |
Linux.package_update(progress = progress) |
|
367 |
Linux.check_reboot_required() |
|
368 |
} |
|
| 70967 | 369 |
|
| 79512 | 370 |
Linux.package_install(packages(webserver), progress = progress) |
| 70967 | 371 |
Linux.check_reboot_required() |
372 |
||
373 |
||
|
71280
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
374 |
if (mercurial_source.nonEmpty) {
|
|
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
375 |
for { name <- List("mercurial", "mercurial-common") if Linux.package_installed(name) } {
|
| 71326 | 376 |
error("Cannot install Mercurial from source:\n" +
|
|
71280
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
377 |
"package package " + quote(name) + " already installed") |
|
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
378 |
} |
|
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
379 |
mercurial_setup(mercurial_source, progress = progress) |
|
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
380 |
} |
|
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
381 |
|
|
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
382 |
|
| 71049 | 383 |
/* users */ |
384 |
||
| 72520 | 385 |
if (name.exists((c: Char) => !(Symbol.is_ascii_letter(c) || Symbol.is_ascii_digit(c))) || |
| 71269 | 386 |
Set("", "ssh", "phd", "dump", daemon_user).contains(name)) {
|
| 71125 | 387 |
error("Bad installation name: " + quote(name))
|
| 71049 | 388 |
} |
389 |
||
390 |
user_setup(daemon_user, "Phabricator Daemon User", ssh_setup = true) |
|
391 |
user_setup(name, "Phabricator SSH User") |
|
392 |
||
393 |
||
| 70967 | 394 |
/* basic installation */ |
395 |
||
| 71079 | 396 |
progress.echo("\nPhabricator installation ...")
|
| 71076 | 397 |
|
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
398 |
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
|
399 |
val repo_path = if (repo.nonEmpty) Path.explode(repo) else default_repo(name) |
| 70967 | 400 |
|
401 |
val configs = read_config() |
|
402 |
||
403 |
for (config <- configs if config.name == name) {
|
|
404 |
error("Duplicate Phabricator installation " + quote(name) + " in " + config.root)
|
|
405 |
} |
|
406 |
||
407 |
if (!Isabelle_System.bash("mkdir -p " + File.bash_path(root_path)).ok) {
|
|
408 |
error("Failed to create root directory " + root_path)
|
|
409 |
} |
|
410 |
||
| 71116 | 411 |
Isabelle_System.chown(Bash.string(www_user) + ":" + Bash.string(www_user), root_path) |
412 |
Isabelle_System.chmod("755", root_path)
|
|
413 |
||
| 70967 | 414 |
progress.bash(cwd = root_path.file, echo = true, |
415 |
script = """ |
|
416 |
set -e |
|
| 71126 | 417 |
echo "Cloning distribution repositories:" |
|
71287
71fd25a7bbe2
more robust setup: avoid blind shot at "the latest" version;
wenzelm
parents:
71285
diff
changeset
|
418 |
|
|
79487
47272fac86d8
support Phabricator on Ubuntu 22.04 LTS with PHP 8.1, using community form we.phorge.it version "2023 week 49";
wenzelm
parents:
79482
diff
changeset
|
419 |
git clone --branch stable https://we.phorge.it/source/arcanist.git |
|
71422
5d5be87330b5
allow to override repository versions at runtime;
wenzelm
parents:
71421
diff
changeset
|
420 |
git -C arcanist reset --hard """ + |
|
5d5be87330b5
allow to override repository versions at runtime;
wenzelm
parents:
71421
diff
changeset
|
421 |
Bash.string(options.string("phabricator_version_arcanist")) + """
|
|
71287
71fd25a7bbe2
more robust setup: avoid blind shot at "the latest" version;
wenzelm
parents:
71285
diff
changeset
|
422 |
|
|
79487
47272fac86d8
support Phabricator on Ubuntu 22.04 LTS with PHP 8.1, using community form we.phorge.it version "2023 week 49";
wenzelm
parents:
79482
diff
changeset
|
423 |
git clone --branch stable https://we.phorge.it/source/phorge.git phabricator |
|
71422
5d5be87330b5
allow to override repository versions at runtime;
wenzelm
parents:
71421
diff
changeset
|
424 |
git -C phabricator reset --hard """ + |
|
5d5be87330b5
allow to override repository versions at runtime;
wenzelm
parents:
71421
diff
changeset
|
425 |
Bash.string(options.string("phabricator_version_phabricator")) + """
|
| 70967 | 426 |
""").check |
427 |
||
428 |
val config = Config(name, root_path) |
|
429 |
write_config(configs ::: List(config)) |
|
| 70968 | 430 |
|
| 71051 | 431 |
config.execute("config set pygments.enabled true")
|
432 |
||
| 70968 | 433 |
|
| 71050 | 434 |
/* local repository directory */ |
435 |
||
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
436 |
progress.echo("\nRepository hosting setup ...")
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
437 |
|
| 71050 | 438 |
if (!Isabelle_System.bash("mkdir -p " + File.bash_path(repo_path)).ok) {
|
439 |
error("Failed to create local repository directory " + repo_path)
|
|
440 |
} |
|
441 |
||
| 71114 | 442 |
Isabelle_System.chown( |
443 |
"-R " + Bash.string(daemon_user) + ":" + Bash.string(daemon_user), repo_path) |
|
444 |
Isabelle_System.chmod("755", repo_path)
|
|
| 71050 | 445 |
|
446 |
config.execute("config set repository.default-local-path " + File.bash_path(repo_path))
|
|
447 |
||
448 |
||
| 71277 | 449 |
val sudoers_file = |
450 |
Path.explode("/etc/sudoers.d") + Path.basic(isabelle_phabricator_name(name = name))
|
|
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
451 |
File.write(sudoers_file, |
|
71280
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
452 |
www_user + " ALL=(" + daemon_user + ") SETENV: NOPASSWD: /usr/bin/git, /usr/local/bin/hg, /usr/bin/hg, /usr/bin/ssh, /usr/bin/id\n" +
|
|
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
453 |
name + " ALL=(" + daemon_user + ") SETENV: NOPASSWD: /usr/bin/git, /usr/bin/git-upload-pack, /usr/bin/git-receive-pack, /usr/local/bin/hg, /usr/bin/hg, /usr/bin/svnserve, /usr/bin/ssh, /usr/bin/id\n")
|
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
454 |
|
| 71115 | 455 |
Isabelle_System.chmod("440", sudoers_file)
|
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
456 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
457 |
config.execute("config set diffusion.ssh-user " + Bash.string(config.name))
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
458 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
459 |
|
| 70969 | 460 |
/* MySQL setup */ |
461 |
||
| 71079 | 462 |
progress.echo("\nMySQL setup ...")
|
| 70969 | 463 |
|
|
71055
27a998cdc0f4
back to plain name, to have it accepted my mysql;
wenzelm
parents:
71054
diff
changeset
|
464 |
File.write(Path.explode("/etc/mysql/mysql.conf.d/" + phabricator_name(ext = "cnf")),
|
| 71051 | 465 |
"""[mysqld] |
466 |
max_allowed_packet = 32M |
|
467 |
innodb_buffer_pool_size = 1600M |
|
468 |
local_infile = 0 |
|
469 |
""") |
|
470 |
||
471 |
Linux.service_restart("mysql")
|
|
472 |
||
473 |
||
| 75393 | 474 |
def mysql_conf(R: Regex, which: String): String = {
|
|
71266
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
475 |
val conf = Path.explode("/etc/mysql/debian.cnf")
|
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
476 |
split_lines(File.read(conf)).collectFirst({ case R(a) => a }) match {
|
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
477 |
case Some(res) => res |
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
478 |
case None => error("Cannot determine " + which + " from " + conf)
|
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
479 |
} |
| 70969 | 480 |
} |
481 |
||
|
71266
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
482 |
val mysql_root_user = mysql_conf("""^user\s*=\s*(\S*)\s*$""".r, "superuser name")
|
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
483 |
val mysql_root_password = mysql_conf("""^password\s*=\s*(\S*)\s*$""".r, "superuser password")
|
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
484 |
|
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
485 |
val mysql_name = phabricator_name(name = name).replace("-", "_")
|
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
486 |
val mysql_user_string = SQL.string(mysql_name) + "@'localhost'" |
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
487 |
val mysql_password = Linux.generate_password() |
| 70969 | 488 |
|
|
71266
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
489 |
Isabelle_System.bash("mysql --user=" + Bash.string(mysql_root_user) +
|
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
490 |
" --password=" + Bash.string(mysql_root_password) + " --execute=" + |
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
491 |
Bash.string( |
| 71274 | 492 |
"""DROP USER IF EXISTS """ + mysql_user_string + "; " + |
493 |
"""CREATE USER """ + mysql_user_string + |
|
|
71266
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
494 |
""" IDENTIFIED BY """ + SQL.string(mysql_password) + """ PASSWORD EXPIRE NEVER; """ + |
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
495 |
"""GRANT ALL ON `""" + (mysql_name + "_%").replace("_", "\\_") +
|
|
72522
6e27af808c17
more privileges for the sake of mysqldump (avoid workaround --no-tablespaces);
wenzelm
parents:
72521
diff
changeset
|
496 |
"""`.* TO """ + mysql_user_string + ";" + |
|
6e27af808c17
more privileges for the sake of mysqldump (avoid workaround --no-tablespaces);
wenzelm
parents:
72521
diff
changeset
|
497 |
"""GRANT PROCESS ON *.* TO """ + mysql_user_string + ";")).check |
| 70969 | 498 |
|
|
71266
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
499 |
config.execute("config set mysql.user " + Bash.string(mysql_name))
|
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
500 |
config.execute("config set mysql.pass " + Bash.string(mysql_password))
|
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
501 |
|
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
502 |
config.execute("config set phabricator.cache-namespace " + Bash.string(mysql_name))
|
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
503 |
config.execute("config set storage.default-namespace " + Bash.string(mysql_name))
|
| 71051 | 504 |
config.execute("config set storage.mysql-engine.max-size 8388608")
|
505 |
||
| 71102 | 506 |
progress.bash("bin/storage upgrade --force", cwd = config.home.file, echo = true).check
|
| 70969 | 507 |
|
508 |
||
| 71269 | 509 |
/* database dump */ |
510 |
||
511 |
val dump_name = isabelle_phabricator_name(name = "dump") |
|
| 71282 | 512 |
command_setup(dump_name, body = |
| 71269 | 513 |
"""mkdir -p "$ROOT/database" && chown root:root "$ROOT/database" && chmod 700 "$ROOT/database" |
514 |
[ -e "$ROOT/database/dump.sql.gz" ] && mv -f "$ROOT/database/dump.sql.gz" "$ROOT/database/dump-old.sql.gz" |
|
| 71328 | 515 |
echo -n "Creating $ROOT/database/dump.sql.gz ..." |
516 |
"$ROOT/phabricator/bin/storage" dump --compress --output "$ROOT/database/dump.sql.gz" 2>&1 | fgrep -v '[Warning] Using a password on the command line interface can be insecure' |
|
517 |
echo " $(ls -hs "$ROOT/database/dump.sql.gz" | cut -d" " -f1)" """) |
|
| 71269 | 518 |
|
519 |
||
| 71283 | 520 |
/* Phabricator upgrade */ |
521 |
||
522 |
command_setup(isabelle_phabricator_name(name = "upgrade"), |
|
523 |
init = |
|
| 71285 | 524 |
"""BRANCH="${1:-stable}"
|
| 71283 | 525 |
if [ "$BRANCH" != "master" -a "$BRANCH" != "stable" ] |
526 |
then |
|
527 |
echo "Bad branch: \"$BRANCH\"" |
|
528 |
exit 1 |
|
529 |
fi |
|
530 |
||
531 |
systemctl stop isabelle-phabricator-phd |
|
| 79516 | 532 |
systemctl stop """ + webserver.system_name, |
| 71283 | 533 |
body = |
534 |
"""echo -e "\nUpgrading phabricator \"$NAME\" root \"$ROOT\" ..." |
|
| 71845 | 535 |
for REPO in arcanist phabricator |
| 71283 | 536 |
do |
537 |
cd "$ROOT/$REPO" |
|
538 |
echo -e "\nUpdating \"$REPO\" ..." |
|
539 |
git checkout "$BRANCH" |
|
540 |
git pull |
|
541 |
done |
|
542 |
echo -e "\nUpgrading storage ..." |
|
543 |
"$ROOT/phabricator/bin/storage" upgrade --force |
|
544 |
""", |
|
545 |
exit = |
|
| 79516 | 546 |
"""systemctl start """ + webserver.system_name + """ |
| 71283 | 547 |
systemctl start isabelle-phabricator-phd""") |
548 |
||
549 |
||
| 79512 | 550 |
/* webserver setup */ |
| 71051 | 551 |
|
| 79512 | 552 |
progress.echo(webserver.title + " setup ...") |
| 71051 | 553 |
|
| 79512 | 554 |
val sites_dir = webserver.sites_dir |
555 |
if (!sites_dir.is_dir) error("Bad " + webserver + " sites directory " + sites_dir)
|
|
| 70968 | 556 |
|
| 79482 | 557 |
val server_name = phabricator_name(name = name, ext = "localhost") // alias for "localhost" for testing |
|
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
558 |
val server_url = "http://" + server_name |
|
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
559 |
|
| 79512 | 560 |
webserver.php_init() |
|
71439
760e19aa9b09
afford more logging (following defaults on Ubuntu);
wenzelm
parents:
71422
diff
changeset
|
561 |
|
| 79512 | 562 |
webserver.site_init(name, server_name, config.webroot) |
| 71051 | 563 |
|
| 71057 | 564 |
config.execute("config set phabricator.base-uri " + Bash.string(server_url))
|
565 |
||
| 79512 | 566 |
webserver.restart() |
| 70968 | 567 |
|
| 71328 | 568 |
progress.echo("\nFurther manual configuration via " + server_url)
|
|
71128
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
569 |
|
| 71053 | 570 |
|
571 |
/* PHP daemon */ |
|
572 |
||
|
71128
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
573 |
progress.echo("\nPHP daemon setup ...")
|
| 71053 | 574 |
|
| 72376 | 575 |
val phd_log_path = Isabelle_System.make_directory(Path.explode("/var/tmp/phd"))
|
| 71273 | 576 |
Isabelle_System.chown( |
577 |
"-R " + Bash.string(daemon_user) + ":" + Bash.string(daemon_user), phd_log_path) |
|
578 |
Isabelle_System.chmod("755", phd_log_path)
|
|
579 |
||
| 71053 | 580 |
config.execute("config set phd.user " + Bash.string(daemon_user))
|
| 71112 | 581 |
config.execute("config set phd.log-directory /var/tmp/phd/" +
|
582 |
isabelle_phabricator_name(name = name) + "/log") |
|
| 71053 | 583 |
|
|
71124
7dbadecdc118
just one isabelle-phabricator-phd service, which manages all processes uniformly (NB: "bin/phd stop" affects all installations);
wenzelm
parents:
71122
diff
changeset
|
584 |
val phd_name = isabelle_phabricator_name(name = "phd") |
| 71127 | 585 |
Linux.service_shutdown(phd_name) |
| 71282 | 586 |
val phd_command = command_setup(phd_name, body = """"$ROOT/phabricator/bin/phd" "$@" """) |
|
71128
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
587 |
try {
|
|
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
588 |
Linux.service_install(phd_name, |
| 71053 | 589 |
"""[Unit] |
|
71124
7dbadecdc118
just one isabelle-phabricator-phd service, which manages all processes uniformly (NB: "bin/phd stop" affects all installations);
wenzelm
parents:
71122
diff
changeset
|
590 |
Description=PHP daemon manager for Isabelle/Phabricator |
| 79512 | 591 |
After=syslog.target network.target """ + webserver.system_name + """.service mysql.service |
| 71053 | 592 |
|
593 |
[Service] |
|
594 |
Type=oneshot |
|
595 |
User=""" + daemon_user + """ |
|
596 |
Group=""" + daemon_user + """ |
|
597 |
Environment=PATH=/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin |
|
|
71124
7dbadecdc118
just one isabelle-phabricator-phd service, which manages all processes uniformly (NB: "bin/phd stop" affects all installations);
wenzelm
parents:
71122
diff
changeset
|
598 |
ExecStart=""" + phd_command.implode + """ start --force |
|
7dbadecdc118
just one isabelle-phabricator-phd service, which manages all processes uniformly (NB: "bin/phd stop" affects all installations);
wenzelm
parents:
71122
diff
changeset
|
599 |
ExecStop=""" + phd_command.implode + """ stop |
| 71053 | 600 |
RemainAfterExit=yes |
601 |
||
602 |
[Install] |
|
603 |
WantedBy=multi-user.target |
|
604 |
""") |
|
|
71128
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
605 |
} |
|
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
606 |
catch {
|
|
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
607 |
case ERROR(msg) => |
|
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
608 |
progress.bash("bin/phd status", cwd = config.home.file, echo = true).check
|
|
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
609 |
error(msg) |
|
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
610 |
} |
| 70967 | 611 |
} |
612 |
||
613 |
||
614 |
/* Isabelle tool wrapper */ |
|
615 |
||
| 71097 | 616 |
val isabelle_tool2 = |
| 72763 | 617 |
Isabelle_Tool("phabricator_setup", "setup Phabricator server on Ubuntu Linux",
|
| 75393 | 618 |
Scala_Project.here, |
| 75394 | 619 |
{ args =>
|
620 |
var mercurial_source = "" |
|
621 |
var repo = "" |
|
622 |
var package_update = false |
|
623 |
var name = default_name |
|
624 |
var options = Options.init() |
|
625 |
var root = "" |
|
| 79512 | 626 |
var webserver = default_webserver |
| 70967 | 627 |
|
| 75394 | 628 |
val getopts = Getopts("""
|
| 71078 | 629 |
Usage: isabelle phabricator_setup [OPTIONS] |
| 70967 | 630 |
|
631 |
Options are: |
|
|
71280
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
632 |
-M SOURCE install Mercurial from source: local PATH, or URL, or ":" for |
|
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
633 |
""" + standard_mercurial_source + """ |
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
634 |
-R DIR repository directory (default: """ + default_repo("NAME") + """)
|
| 71047 | 635 |
-U full update of system packages before installation |
| 71078 | 636 |
-n NAME Phabricator installation name (default: """ + quote(default_name) + """) |
|
71422
5d5be87330b5
allow to override repository versions at runtime;
wenzelm
parents:
71421
diff
changeset
|
637 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
638 |
-r DIR installation root directory (default: """ + default_root("NAME") + """)
|
| 79512 | 639 |
-w NAME webserver name (""" +
|
640 |
all_webservers.map(w => quote(w.short_name)).mkString (" or ") +
|
|
641 |
", default: " + quote(default_webserver.short_name) + """) |
|
| 70967 | 642 |
|
| 79512 | 643 |
Install Phabricator as Linux service, based on webserver + PHP + MySQL. |
| 70967 | 644 |
|
| 71078 | 645 |
The installation name (default: """ + quote(default_name) + """) is mapped to a regular |
646 |
Unix user; this is relevant for public SSH access. |
|
| 70967 | 647 |
""", |
|
71280
5a2033fc8f3d
avoid odd (harmless) problem with Mercurial 4.5.3 provided by Ubuntu 18.04 on first push: "couldn't write revision branch cache names";
wenzelm
parents:
71277
diff
changeset
|
648 |
"M:" -> (arg => mercurial_source = (if (arg == ":") standard_mercurial_source else arg)), |
| 70967 | 649 |
"R:" -> (arg => repo = arg), |
| 71047 | 650 |
"U" -> (_ => package_update = true), |
| 71078 | 651 |
"n:" -> (arg => name = arg), |
|
71422
5d5be87330b5
allow to override repository versions at runtime;
wenzelm
parents:
71421
diff
changeset
|
652 |
"o:" -> (arg => options = options + arg), |
| 79512 | 653 |
"r:" -> (arg => root = arg), |
654 |
"w:" -> (arg => webserver = get_webserver(arg))) |
|
| 70967 | 655 |
|
| 75394 | 656 |
val more_args = getopts(args) |
657 |
if (more_args.nonEmpty) getopts.usage() |
|
| 70967 | 658 |
|
| 75394 | 659 |
val progress = new Console_Progress |
| 70967 | 660 |
|
| 79512 | 661 |
phabricator_setup(options, name = name, root = root, repo = repo, webserver = webserver, |
| 75394 | 662 |
package_update = package_update, mercurial_source = mercurial_source, progress = progress) |
663 |
}) |
|
| 70967 | 664 |
|
665 |
||
666 |
||
| 71066 | 667 |
/** setup mail **/ |
| 70967 | 668 |
|
| 71072 | 669 |
val mailers_template: String = |
|
75659
9bd92ac9328f
more robust Scala 3 indentation, for the sake of IntelliJ IDEA;
wenzelm
parents:
75394
diff
changeset
|
670 |
"""[ |
| 71072 | 671 |
{
|
672 |
"key": "example.org", |
|
673 |
"type": "smtp", |
|
674 |
"options": {
|
|
675 |
"host": "mail.example.org", |
|
676 |
"port": 465, |
|
677 |
"user": "phabricator@example.org", |
|
678 |
"password": "********", |
|
679 |
"protocol": "ssl", |
|
680 |
"message-id": true |
|
681 |
} |
|
682 |
} |
|
683 |
]""" |
|
684 |
||
| 71066 | 685 |
def phabricator_setup_mail( |
686 |
name: String = default_name, |
|
687 |
config_file: Option[Path] = None, |
|
688 |
test_user: String = "", |
|
| 75393 | 689 |
progress: Progress = new Progress |
690 |
): Unit = {
|
|
| 70967 | 691 |
Linux.check_system_root() |
692 |
||
| 71066 | 693 |
val config = get_config(name) |
| 71073 | 694 |
val default_config_file = config.root + default_mailers |
| 71066 | 695 |
|
696 |
val mail_config = config_file getOrElse default_config_file |
|
697 |
||
| 75393 | 698 |
def setup_mail: Unit = {
|
| 71066 | 699 |
progress.echo("Using mail configuration from " + mail_config)
|
700 |
config.execute("config set cluster.mailers --stdin < " + File.bash_path(mail_config))
|
|
701 |
||
702 |
if (test_user.nonEmpty) {
|
|
703 |
progress.echo("Sending test mail to " + quote(test_user))
|
|
704 |
progress.bash(cwd = config.home.file, echo = true, |
|
| 71102 | 705 |
script = """echo "Test from Phabricator ($(date))" | bin/mail send-test --subject "Test" --to """ + |
| 71066 | 706 |
Bash.string(test_user)).check |
707 |
} |
|
708 |
} |
|
709 |
||
710 |
if (config_file.isEmpty) {
|
|
| 71070 | 711 |
if (!default_config_file.is_file) {
|
712 |
File.write(default_config_file, mailers_template) |
|
| 71114 | 713 |
Isabelle_System.chmod("600", default_config_file)
|
| 71070 | 714 |
} |
| 71066 | 715 |
if (File.read(default_config_file) == mailers_template) {
|
| 71131 | 716 |
progress.echo("Please invoke the tool again, after providing details in\n " +
|
717 |
default_config_file.implode + "\n") |
|
| 71066 | 718 |
} |
719 |
else setup_mail |
|
720 |
} |
|
721 |
else setup_mail |
|
| 70967 | 722 |
} |
723 |
||
724 |
||
725 |
/* Isabelle tool wrapper */ |
|
726 |
||
| 71097 | 727 |
val isabelle_tool3 = |
| 72763 | 728 |
Isabelle_Tool("phabricator_setup_mail", "setup mail for one Phabricator installation",
|
| 75393 | 729 |
Scala_Project.here, |
| 75394 | 730 |
{ args =>
|
731 |
var test_user = "" |
|
732 |
var name = default_name |
|
733 |
var config_file: Option[Path] = None |
|
| 71066 | 734 |
|
| 75394 | 735 |
val getopts = Getopts("""
|
| 71066 | 736 |
Usage: isabelle phabricator_setup_mail [OPTIONS] |
737 |
||
738 |
Options are: |
|
739 |
-T USER send test mail to Phabricator user |
|
| 71103 | 740 |
-f FILE config file (default: """ + default_mailers + """ within Phabricator root) |
| 71066 | 741 |
-n NAME Phabricator installation name (default: """ + quote(default_name) + """) |
| 70967 | 742 |
|
| 71077 | 743 |
Provide mail configuration for existing Phabricator installation. |
| 71066 | 744 |
""", |
745 |
"T:" -> (arg => test_user = arg), |
|
746 |
"f:" -> (arg => config_file = Some(Path.explode(arg))), |
|
747 |
"n:" -> (arg => name = arg)) |
|
| 70967 | 748 |
|
| 75394 | 749 |
val more_args = getopts(args) |
750 |
if (more_args.nonEmpty) getopts.usage() |
|
| 70967 | 751 |
|
| 75394 | 752 |
val progress = new Console_Progress |
| 70967 | 753 |
|
| 75394 | 754 |
phabricator_setup_mail(name = name, config_file = config_file, |
755 |
test_user = test_user, progress = progress) |
|
756 |
}) |
|
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
757 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
758 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
759 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
760 |
/** setup ssh **/ |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
761 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
762 |
/* sshd config */ |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
763 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
764 |
private val Port = """^\s*Port\s+(\d+)\s*$""".r |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
765 |
private val No_Port = """^#\s*Port\b.*$""".r |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
766 |
private val Any_Port = """^#?\s*Port\b.*$""".r |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
767 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
768 |
def conf_ssh_port(port: Int): String = |
| 76129 | 769 |
if (port == default_system_port) "#Port " + default_system_port else "Port " + port |
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
770 |
|
| 75393 | 771 |
def read_ssh_port(conf: Path): Int = {
|
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
772 |
val lines = split_lines(File.read(conf)) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
773 |
val ports = |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
774 |
lines.flatMap({
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
775 |
case Port(Value.Int(p)) => Some(p) |
| 76129 | 776 |
case No_Port() => Some(default_system_port) |
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
777 |
case _ => None |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
778 |
}) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
779 |
ports match {
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
780 |
case List(port) => port |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
781 |
case Nil => error("Missing Port specification in " + conf)
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
782 |
case _ => error("Multiple Port specifications in " + conf)
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
783 |
} |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
784 |
} |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
785 |
|
| 75393 | 786 |
def write_ssh_port(conf: Path, port: Int): Boolean = {
|
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
787 |
val old_port = read_ssh_port(conf) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
788 |
if (old_port == port) false |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
789 |
else {
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
790 |
val lines = split_lines(File.read(conf)) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
791 |
val lines1 = lines.map({ case Any_Port() => conf_ssh_port(port) case line => line })
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
792 |
File.write(conf, cat_lines(lines1)) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
793 |
true |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
794 |
} |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
795 |
} |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
796 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
797 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
798 |
/* phabricator_setup_ssh */ |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
799 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
800 |
def phabricator_setup_ssh( |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
801 |
server_port: Int = default_server_port, |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
802 |
system_port: Int = default_system_port, |
| 75393 | 803 |
progress: Progress = new Progress |
804 |
): Unit = {
|
|
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
805 |
Linux.check_system_root() |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
806 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
807 |
val configs = read_config() |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
808 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
809 |
if (server_port == system_port) {
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
810 |
error("Port for Phabricator sshd coincides with system port: " + system_port)
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
811 |
} |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
812 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
813 |
val sshd_conf_system = Path.explode("/etc/ssh/sshd_config")
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
814 |
val sshd_conf_server = sshd_conf_system.ext(isabelle_phabricator_name()) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
815 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
816 |
val ssh_name = isabelle_phabricator_name(name = "ssh") |
|
71111
cd166c3904dd
more robust: system ssh service is required for Phabricator ssh service;
wenzelm
parents:
71109
diff
changeset
|
817 |
Linux.service_shutdown(ssh_name) |
|
cd166c3904dd
more robust: system ssh service is required for Phabricator ssh service;
wenzelm
parents:
71109
diff
changeset
|
818 |
|
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
819 |
val old_system_port = read_ssh_port(sshd_conf_system) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
820 |
if (old_system_port != system_port) {
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
821 |
progress.echo("Reconfigurig system ssh service")
|
|
71111
cd166c3904dd
more robust: system ssh service is required for Phabricator ssh service;
wenzelm
parents:
71109
diff
changeset
|
822 |
Linux.service_shutdown("ssh")
|
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
823 |
write_ssh_port(sshd_conf_system, system_port) |
|
71111
cd166c3904dd
more robust: system ssh service is required for Phabricator ssh service;
wenzelm
parents:
71109
diff
changeset
|
824 |
Linux.service_start("ssh")
|
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
825 |
} |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
826 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
827 |
progress.echo("Configuring " + ssh_name + " service")
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
828 |
|
| 71282 | 829 |
val ssh_command = command_setup(ssh_name, body = |
| 71122 | 830 |
"""if [ "$1" = "$NAME" ] |
831 |
then |
|
832 |
exec "$ROOT/phabricator/bin/ssh-auth" "$@" |
|
| 71270 | 833 |
fi""", exit = "exit 1") |
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
834 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
835 |
File.write(sshd_conf_server, |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
836 |
"""# OpenBSD Secure Shell server for Isabelle/Phabricator |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
837 |
AuthorizedKeysCommand """ + ssh_command.implode + """ |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
838 |
AuthorizedKeysCommandUser """ + daemon_user + """ |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
839 |
AuthorizedKeysFile none |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
840 |
AllowUsers """ + configs.map(_.name).mkString(" ") + """
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
841 |
Port """ + server_port + """ |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
842 |
Protocol 2 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
843 |
PermitRootLogin no |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
844 |
AllowAgentForwarding no |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
845 |
AllowTcpForwarding no |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
846 |
PrintMotd no |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
847 |
PrintLastLog no |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
848 |
PasswordAuthentication no |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
849 |
ChallengeResponseAuthentication no |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
850 |
PidFile /var/run/""" + ssh_name + """.pid |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
851 |
""") |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
852 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
853 |
Linux.service_install(ssh_name, |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
854 |
"""[Unit] |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
855 |
Description=OpenBSD Secure Shell server for Isabelle/Phabricator |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
856 |
After=network.target auditd.service |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
857 |
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
858 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
859 |
[Service] |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
860 |
EnvironmentFile=-/etc/default/ssh |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
861 |
ExecStartPre=/usr/sbin/sshd -f """ + sshd_conf_server.implode + """ -t |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
862 |
ExecStart=/usr/sbin/sshd -f """ + sshd_conf_server.implode + """ -D $SSHD_OPTS |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
863 |
ExecReload=/usr/sbin/sshd -f """ + sshd_conf_server.implode + """ -t |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
864 |
ExecReload=/bin/kill -HUP $MAINPID |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
865 |
KillMode=process |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
866 |
Restart=on-failure |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
867 |
RestartPreventExitStatus=255 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
868 |
Type=notify |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
869 |
RuntimeDirectory=sshd-phabricator |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
870 |
RuntimeDirectoryMode=0755 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
871 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
872 |
[Install] |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
873 |
WantedBy=multi-user.target |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
874 |
Alias=""" + ssh_name + """.service |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
875 |
""") |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
876 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
877 |
for (config <- configs) {
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
878 |
progress.echo("phabricator " + quote(config.name) + " port " + server_port)
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
879 |
config.execute("config set diffusion.ssh-port " + Bash.string(server_port.toString))
|
| 76129 | 880 |
if (server_port == default_system_port) config.execute("config delete diffusion.ssh-port")
|
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
881 |
} |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
882 |
} |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
883 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
884 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
885 |
/* Isabelle tool wrapper */ |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
886 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
887 |
val isabelle_tool4 = |
| 72763 | 888 |
Isabelle_Tool("phabricator_setup_ssh", "setup ssh service for all Phabricator installations",
|
| 75393 | 889 |
Scala_Project.here, |
| 75394 | 890 |
{ args =>
|
891 |
var server_port = default_server_port |
|
892 |
var system_port = default_system_port |
|
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
893 |
|
| 75394 | 894 |
val getopts = Getopts("""
|
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
895 |
Usage: isabelle phabricator_setup_ssh [OPTIONS] |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
896 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
897 |
Options are: |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
898 |
-p PORT sshd port for Phabricator servers (default: """ + default_server_port + """) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
899 |
-q PORT sshd port for the operating system (default: """ + default_system_port + """) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
900 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
901 |
Configure ssh service for all Phabricator installations: a separate sshd |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
902 |
is run in addition to the one of the operating system, and ports need to |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
903 |
be distinct. |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
904 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
905 |
A particular Phabricator installation is addressed by using its |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
906 |
name as the ssh user; the actual Phabricator user is determined via |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
907 |
stored ssh keys. |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
908 |
""", |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
909 |
"p:" -> (arg => server_port = Value.Int.parse(arg)), |
|
71295
6aadbd650280
eliminated pointless option -T: it merely tests ssh config of root, which is not required later;
wenzelm
parents:
71292
diff
changeset
|
910 |
"q:" -> (arg => system_port = Value.Int.parse(arg))) |
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
911 |
|
| 75394 | 912 |
val more_args = getopts(args) |
913 |
if (more_args.nonEmpty) getopts.usage() |
|
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
914 |
|
| 75394 | 915 |
val progress = new Console_Progress |
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
916 |
|
| 75394 | 917 |
phabricator_setup_ssh( |
918 |
server_port = server_port, system_port = system_port, progress = progress) |
|
919 |
}) |
|
| 71299 | 920 |
|
921 |
||
922 |
||
923 |
/** conduit API **/ |
|
924 |
||
| 75393 | 925 |
object API {
|
| 71332 | 926 |
/* user information */ |
927 |
||
928 |
sealed case class User( |
|
929 |
id: Long, |
|
930 |
phid: String, |
|
931 |
name: String, |
|
932 |
real_name: String, |
|
| 75393 | 933 |
roles: List[String] |
934 |
) {
|
|
| 71332 | 935 |
def is_valid: Boolean = |
936 |
roles.contains("verified") &&
|
|
937 |
roles.contains("approved") &&
|
|
938 |
roles.contains("activated")
|
|
939 |
def is_admin: Boolean = roles.contains("admin")
|
|
940 |
def is_regular: Boolean = !(roles.contains("bot") || roles.contains("list"))
|
|
941 |
} |
|
942 |
||
943 |
||
| 71314 | 944 |
/* repository information */ |
945 |
||
946 |
sealed case class Repository( |
|
| 78602 | 947 |
vcs: VCS, |
| 71314 | 948 |
id: Long, |
949 |
phid: String, |
|
950 |
name: String, |
|
951 |
callsign: String, |
|
952 |
short_name: String, |
|
953 |
importing: Boolean, |
|
| 75393 | 954 |
ssh_url: String |
955 |
) {
|
|
| 71314 | 956 |
def is_hg: Boolean = vcs == VCS.hg |
957 |
} |
|
958 |
||
| 78602 | 959 |
enum VCS { case hg, git, svn }
|
960 |
||
961 |
def read_vcs(s: String): VCS = |
|
962 |
try { VCS.valueOf(s) }
|
|
963 |
catch { case _: IllegalArgumentException => error("Unknown vcs type " + quote(s)) }
|
|
| 71314 | 964 |
|
965 |
def edits(typ: String, value: JSON.T): List[JSON.Object.T] = |
|
966 |
List(JSON.Object("type" -> typ, "value" -> value))
|
|
967 |
||
968 |
def opt_edits(typ: String, value: Option[JSON.T]): List[JSON.Object.T] = |
|
969 |
value.toList.flatMap(edits(typ, _)) |
|
970 |
||
971 |
||
972 |
/* result with optional error */ |
|
973 |
||
| 75393 | 974 |
sealed case class Result(result: JSON.T, error: Option[String]) {
|
| 71314 | 975 |
def ok: Boolean = error.isEmpty |
976 |
def get: JSON.T = if (ok) result else Exn.error(error.get) |
|
977 |
||
978 |
def get_value[A](unapply: JSON.T => Option[A]): A = |
|
979 |
unapply(get) getOrElse Exn.error("Bad JSON result: " + JSON.Format(result))
|
|
980 |
||
981 |
def get_string: String = get_value(JSON.Value.String.unapply) |
|
982 |
} |
|
983 |
||
| 75393 | 984 |
def make_result(json: JSON.T): Result = {
|
| 71314 | 985 |
val result = JSON.value(json, "result").getOrElse(JSON.Object.empty) |
986 |
val error_info = JSON.string(json, "error_info") |
|
987 |
val error_code = JSON.string(json, "error_code") |
|
988 |
Result(result, error_info orElse error_code) |
|
989 |
} |
|
990 |
||
991 |
||
992 |
/* context for operations */ |
|
993 |
||
| 76173 | 994 |
def apply(server: String, port: Int = 0): API = new API(server, port) |
| 71299 | 995 |
} |
996 |
||
| 76172 | 997 |
final class API private(server: String, port: Int) {
|
| 71299 | 998 |
/* connection */ |
999 |
||
| 76172 | 1000 |
private def port_suffix: String = if (port > 0) ":" + port else "" |
1001 |
override def toString: String = server + port_suffix |
|
1002 |
def hg_url: String = "ssh://" + server + port_suffix |
|
| 71299 | 1003 |
|
1004 |
||
1005 |
/* execute methods */ |
|
1006 |
||
| 75393 | 1007 |
def execute_raw(method: String, params: JSON.T = JSON.Object.empty): JSON.T = {
|
| 75394 | 1008 |
Isabelle_System.with_tmp_file("params", "json") { params_file =>
|
| 71300 | 1009 |
File.write(params_file, JSON.Format(JSON.Object("params" -> JSON.Format(params))))
|
| 71299 | 1010 |
val result = |
1011 |
Isabelle_System.bash( |
|
| 76172 | 1012 |
SSH.client_command(port = port) + " -- " + Bash.string(server) + |
| 71300 | 1013 |
" conduit " + Bash.string(method) + " < " + File.bash_path(params_file)).check |
| 71299 | 1014 |
JSON.parse(result.out, strict = false) |
| 75394 | 1015 |
} |
| 71299 | 1016 |
} |
1017 |
||
| 71300 | 1018 |
def execute(method: String, params: JSON.T = JSON.Object.empty): API.Result = |
1019 |
API.make_result(execute_raw(method, params = params)) |
|
| 71299 | 1020 |
|
| 71330 | 1021 |
def execute_search[A]( |
| 75393 | 1022 |
method: String, |
1023 |
params: JSON.Object.T, |
|
1024 |
unapply: JSON.T => Option[A] |
|
1025 |
): List[A] = {
|
|
| 71330 | 1026 |
val results = new mutable.ListBuffer[A] |
1027 |
var after = "" |
|
1028 |
||
|
75382
81673c441ce3
tuned: eliminted do-while for the sake of scala3;
wenzelm
parents:
74944
diff
changeset
|
1029 |
var cont = true |
|
81673c441ce3
tuned: eliminted do-while for the sake of scala3;
wenzelm
parents:
74944
diff
changeset
|
1030 |
while (cont) {
|
| 71330 | 1031 |
val result = |
1032 |
execute(method, params = params ++ JSON.optional("after" -> proper_string(after)))
|
|
1033 |
results ++= result.get_value(JSON.list(_, "data", unapply)) |
|
1034 |
after = result.get_value(JSON.value(_, "cursor", JSON.string0(_, "after"))) |
|
|
75382
81673c441ce3
tuned: eliminted do-while for the sake of scala3;
wenzelm
parents:
74944
diff
changeset
|
1035 |
cont = after.nonEmpty |
|
81673c441ce3
tuned: eliminted do-while for the sake of scala3;
wenzelm
parents:
74944
diff
changeset
|
1036 |
} |
| 71330 | 1037 |
|
1038 |
results.toList |
|
1039 |
} |
|
1040 |
||
| 71332 | 1041 |
def ping(): String = execute("conduit.ping").get_string
|
| 71299 | 1042 |
|
1043 |
||
| 71332 | 1044 |
/* users */ |
| 71299 | 1045 |
|
| 71300 | 1046 |
lazy val user_phid: String = execute("user.whoami").get_value(JSON.string(_, "phid"))
|
1047 |
lazy val user_name: String = execute("user.whoami").get_value(JSON.string(_, "userName"))
|
|
| 71301 | 1048 |
|
| 71332 | 1049 |
def get_users( |
1050 |
all: Boolean = false, |
|
1051 |
phid: String = "", |
|
| 75393 | 1052 |
name: String = "" |
1053 |
): List[API.User] = {
|
|
| 71332 | 1054 |
val constraints: JSON.Object.T = |
1055 |
(for { (key, value) <- List("phids" -> phid, "usernames" -> name) if value.nonEmpty }
|
|
1056 |
yield (key, List(value))).toMap |
|
1057 |
||
1058 |
execute_search("user.search",
|
|
1059 |
JSON.Object("queryKey" -> (if (all) "all" else "active"), "constraints" -> constraints),
|
|
1060 |
data => JSON.value(data, "fields", fields => |
|
1061 |
for {
|
|
1062 |
id <- JSON.long(data, "id") |
|
1063 |
phid <- JSON.string(data, "phid") |
|
1064 |
name <- JSON.string(fields, "username") |
|
1065 |
real_name <- JSON.string0(fields, "realName") |
|
1066 |
roles <- JSON.strings(fields, "roles") |
|
1067 |
} yield API.User(id, phid, name, real_name, roles))) |
|
1068 |
} |
|
1069 |
||
1070 |
def the_user(phid: String): API.User = |
|
1071 |
get_users(phid = phid) match {
|
|
1072 |
case List(user) => user |
|
1073 |
case _ => error("Bad user PHID " + quote(phid))
|
|
1074 |
} |
|
1075 |
||
1076 |
||
1077 |
/* repositories */ |
|
1078 |
||
| 71306 | 1079 |
def get_repositories( |
| 71331 | 1080 |
all: Boolean = false, |
1081 |
phid: String = "", |
|
1082 |
callsign: String = "", |
|
| 75393 | 1083 |
short_name: String = "" |
1084 |
): List[API.Repository] = {
|
|
| 71306 | 1085 |
val constraints: JSON.Object.T = |
1086 |
(for {
|
|
1087 |
(key, value) <- List("phids" -> phid, "callsigns" -> callsign, "shortNames" -> short_name)
|
|
1088 |
if value.nonEmpty |
|
1089 |
} yield (key, List(value))).toMap |
|
1090 |
||
| 71330 | 1091 |
execute_search("diffusion.repository.search",
|
| 71331 | 1092 |
JSON.Object("queryKey" -> (if (all) "all" else "active"), "constraints" -> constraints),
|
| 71330 | 1093 |
data => JSON.value(data, "fields", fields => |
1094 |
for {
|
|
1095 |
vcs_name <- JSON.string(fields, "vcs") |
|
1096 |
id <- JSON.long(data, "id") |
|
1097 |
phid <- JSON.string(data, "phid") |
|
1098 |
name <- JSON.string(fields, "name") |
|
1099 |
callsign <- JSON.string0(fields, "callsign") |
|
1100 |
short_name <- JSON.string0(fields, "shortName") |
|
1101 |
importing <- JSON.bool(fields, "isImporting") |
|
| 71306 | 1102 |
} |
| 71330 | 1103 |
yield {
|
| 78602 | 1104 |
val vcs = API.read_vcs(vcs_name) |
| 71330 | 1105 |
val url_path = |
1106 |
if (short_name.isEmpty) "/diffusion/" + id else "/source/" + short_name |
|
1107 |
val ssh_url = |
|
1108 |
vcs match {
|
|
1109 |
case API.VCS.hg => hg_url + url_path |
|
1110 |
case API.VCS.git => hg_url + url_path + ".git" |
|
1111 |
case API.VCS.svn => "" |
|
1112 |
} |
|
1113 |
API.Repository(vcs, id, phid, name, callsign, short_name, importing, ssh_url) |
|
1114 |
})) |
|
| 71306 | 1115 |
} |
| 71309 | 1116 |
|
| 71311 | 1117 |
def the_repository(phid: String): API.Repository = |
1118 |
get_repositories(phid = phid) match {
|
|
1119 |
case List(repo) => repo |
|
| 71314 | 1120 |
case _ => error("Bad repository PHID " + quote(phid))
|
| 71311 | 1121 |
} |
1122 |
||
| 71309 | 1123 |
def create_repository( |
1124 |
name: String, |
|
1125 |
callsign: String = "", // unique name, UPPERCASE |
|
1126 |
short_name: String = "", // unique name |
|
1127 |
description: String = "", |
|
1128 |
public: Boolean = false, |
|
| 78602 | 1129 |
vcs: API.VCS = API.VCS.hg |
| 75393 | 1130 |
): API.Repository = {
|
|
73120
c3589f2dff31
more informative errors: simplify diagnosis of spurious failures reported by users;
wenzelm
parents:
72763
diff
changeset
|
1131 |
require(name.nonEmpty, "bad repository name") |
| 71309 | 1132 |
|
1133 |
val transactions = |
|
1134 |
API.edits("vcs", vcs.toString) :::
|
|
1135 |
API.edits("name", name) :::
|
|
1136 |
API.opt_edits("callsign", proper_string(callsign)) :::
|
|
1137 |
API.opt_edits("shortName", proper_string(short_name)) :::
|
|
1138 |
API.opt_edits("description", proper_string(description)) :::
|
|
1139 |
(if (public) Nil |
|
1140 |
else API.edits("view", user_phid) ::: API.edits("policy.push", user_phid)) :::
|
|
1141 |
API.edits("status", "active")
|
|
1142 |
||
| 71310 | 1143 |
val phid = |
| 71309 | 1144 |
execute("diffusion.repository.edit", params = JSON.Object("transactions" -> transactions))
|
1145 |
.get_value(JSON.value(_, "object", JSON.string(_, "phid"))) |
|
1146 |
||
| 71310 | 1147 |
execute("diffusion.looksoon", params = JSON.Object("repositories" -> List(phid))).get
|
| 71309 | 1148 |
|
| 71311 | 1149 |
the_repository(phid) |
| 71309 | 1150 |
} |
| 71299 | 1151 |
} |
| 70967 | 1152 |
} |