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