author | wenzelm |
Mon, 16 Dec 2019 13:24:36 +0100 | |
changeset 71282 | de59dd86760f |
parent 71281 | 5b3a813853bb |
child 71283 | cfcc1a2233ca |
permissions | -rw-r--r-- |
70967 | 1 |
/* Title: Pure/Tools/phabricator.scala |
2 |
Author: Makarius |
|
3 |
||
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
4 |
Support for Phabricator server, notably for Ubuntu 18.04 LTS. |
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
5 |
|
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
6 |
See also: |
70967 | 7 |
- https://www.phacility.com/phabricator |
8 |
- https://secure.phabricator.com/book/phabricator |
|
9 |
*/ |
|
10 |
||
11 |
package isabelle |
|
12 |
||
13 |
||
70969 | 14 |
import scala.util.matching.Regex |
15 |
||
16 |
||
70967 | 17 |
object Phabricator |
18 |
{ |
|
19 |
/** defaults **/ |
|
20 |
||
71049 | 21 |
/* required packages */ |
22 |
||
23 |
val packages: List[String] = |
|
71265 | 24 |
Build_Docker.packages ::: Linux.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 |
|
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
|
30 |
"php-zip", "python-pygments", "ssh", "subversion", |
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 |
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
|
32 |
"make", "gcc", "python", "python-dev", "python-docutils", "python-pygments", "python-openssl") |
71049 | 33 |
|
34 |
||
35 |
/* global system resources */ |
|
36 |
||
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
37 |
val www_user = "www-data" |
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
38 |
|
71049 | 39 |
val daemon_user = "phabricator" |
40 |
||
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
41 |
val sshd_config = Path.explode("/etc/ssh/sshd_config") |
71049 | 42 |
|
43 |
||
44 |
/* installation parameters */ |
|
45 |
||
70967 | 46 |
val default_name = "vcs" |
47 |
||
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
48 |
def phabricator_name(name: String = "", ext: String = ""): String = |
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
49 |
"phabricator" + (if (name.isEmpty) "" else "-" + name) + (if (ext.isEmpty) "" else "." + ext) |
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
50 |
|
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
51 |
def isabelle_phabricator_name(name: String = "", ext: String = ""): String = |
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
52 |
"isabelle-" + phabricator_name(name = name, ext = ext) |
70967 | 53 |
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
54 |
def default_root(name: String): Path = |
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
55 |
Path.explode("/var/www") + Path.basic(phabricator_name(name = name)) |
70967 | 56 |
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
57 |
def default_repo(name: String): Path = default_root(name) + Path.basic("repo") |
70967 | 58 |
|
71072 | 59 |
val default_mailers: Path = Path.explode("mailers.json") |
71066 | 60 |
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
61 |
val default_system_port = 22 |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
62 |
val alternative_system_port = 222 |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
63 |
val default_server_port = 2222 |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
64 |
|
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
|
65 |
val standard_mercurial_source = "https://www.mercurial-scm.org/release/mercurial-5.2.1.tar.gz" |
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
|
66 |
|
70967 | 67 |
|
68 |
||
69 |
/** global configuration **/ |
|
70 |
||
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
71 |
val global_config = Path.explode("/etc/" + isabelle_phabricator_name(ext = "conf")) |
70967 | 72 |
|
71122 | 73 |
def global_config_script( |
74 |
init: String = "", |
|
75 |
body: String = "", |
|
76 |
exit: String = ""): String = |
|
77 |
{ |
|
71282 | 78 |
"""#!/bin/bash |
79 |
||
71122 | 80 |
{""" + (if (init.nonEmpty) "\n" + Library.prefix_lines(" ", init) else "") + """ |
81 |
while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; } |
|
82 |
do |
|
83 |
NAME="$(echo "$REPLY" | cut -d: -f1)" |
|
84 |
ROOT="$(echo "$REPLY" | cut -d: -f2)" |
|
85 |
""" + Library.prefix_lines(" ", body) + """ |
|
86 |
done""" + |
|
87 |
(if (exit.nonEmpty) "\n" + Library.prefix_lines(" ", exit) else "") + """ |
|
88 |
} < """ + File.bash_path(global_config) + """ |
|
89 |
""" |
|
90 |
} |
|
91 |
||
70967 | 92 |
sealed case class Config(name: String, root: Path) |
70968 | 93 |
{ |
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
94 |
def home: Path = root + Path.explode(phabricator_name()) |
70969 | 95 |
|
96 |
def execute(command: String): Process_Result = |
|
71102 | 97 |
Isabelle_System.bash("bin/" + command, cwd = home.file, redirect = true).check |
70968 | 98 |
} |
70967 | 99 |
|
100 |
def read_config(): List[Config] = |
|
101 |
{ |
|
102 |
if (global_config.is_file) { |
|
103 |
for (entry <- Library.trim_split_lines(File.read(global_config)) if entry.nonEmpty) |
|
104 |
yield { |
|
105 |
space_explode(':', entry) match { |
|
106 |
case List(name, root) => Config(name, Path.explode(root)) |
|
107 |
case _ => error("Malformed config file " + global_config + "\nentry " + quote(entry)) |
|
108 |
} |
|
109 |
} |
|
110 |
} |
|
111 |
else Nil |
|
112 |
} |
|
113 |
||
114 |
def write_config(configs: List[Config]) |
|
115 |
{ |
|
116 |
File.write(global_config, |
|
117 |
configs.map(config => config.name + ":" + config.root.implode).mkString("", "\n", "\n")) |
|
118 |
} |
|
119 |
||
120 |
def get_config(name: String): Config = |
|
121 |
read_config().find(config => config.name == name) getOrElse |
|
122 |
error("Bad Isabelle/Phabricator installation " + quote(name)) |
|
123 |
||
124 |
||
125 |
||
71097 | 126 |
/** command-line tools **/ |
127 |
||
128 |
/* Isabelle tool wrapper */ |
|
129 |
||
130 |
val isabelle_tool1 = |
|
131 |
Isabelle_Tool("phabricator", "invoke command-line tool within Phabricator home directory", args => |
|
132 |
{ |
|
71101 | 133 |
var list = false |
71097 | 134 |
var name = default_name |
135 |
||
136 |
val getopts = |
|
137 |
Getopts(""" |
|
138 |
Usage: isabelle phabricator [OPTIONS] COMMAND [ARGS...] |
|
139 |
||
140 |
Options are: |
|
71101 | 141 |
-l list available Phabricator installations |
71097 | 142 |
-n NAME Phabricator installation name (default: """ + quote(default_name) + """) |
143 |
||
71103 | 144 |
Invoke a command-line tool within the home directory of the named |
145 |
Phabricator installation. |
|
71097 | 146 |
""", |
71101 | 147 |
"l" -> (_ => list = true), |
71097 | 148 |
"n:" -> (arg => name = arg)) |
149 |
||
150 |
val more_args = getopts(args) |
|
71101 | 151 |
if (more_args.isEmpty && !list) getopts.usage() |
71097 | 152 |
|
153 |
val progress = new Console_Progress |
|
154 |
||
71101 | 155 |
if (list) { |
156 |
for (config <- read_config()) { |
|
71103 | 157 |
progress.echo("phabricator " + quote(config.name) + " root " + config.root) |
71101 | 158 |
} |
159 |
} |
|
71276
b4401dfd6544
clarified "isabelle phabricator -l": avoid surprise with non-existent default installation;
wenzelm
parents:
71274
diff
changeset
|
160 |
else { |
b4401dfd6544
clarified "isabelle phabricator -l": avoid surprise with non-existent default installation;
wenzelm
parents:
71274
diff
changeset
|
161 |
val config = get_config(name) |
b4401dfd6544
clarified "isabelle phabricator -l": avoid surprise with non-existent default installation;
wenzelm
parents:
71274
diff
changeset
|
162 |
val result = progress.bash(Bash.strings(more_args), cwd = config.home.file, echo = true) |
b4401dfd6544
clarified "isabelle phabricator -l": avoid surprise with non-existent default installation;
wenzelm
parents:
71274
diff
changeset
|
163 |
if (!result.ok) error("Return code: " + result.rc.toString) |
b4401dfd6544
clarified "isabelle phabricator -l": avoid surprise with non-existent default installation;
wenzelm
parents:
71274
diff
changeset
|
164 |
} |
71097 | 165 |
}) |
166 |
||
167 |
||
168 |
||
70967 | 169 |
/** setup **/ |
170 |
||
71049 | 171 |
def user_setup(name: String, description: String, ssh_setup: Boolean = false) |
172 |
{ |
|
173 |
if (!Linux.user_exists(name)) { |
|
71054
b64fc38327ae
prefer system user setup, e.g. avoid occurrence on login screen;
wenzelm
parents:
71053
diff
changeset
|
174 |
Linux.user_add(name, description = description, system = true, ssh_setup = ssh_setup) |
71049 | 175 |
} |
176 |
else if (Linux.user_description(name) != description) { |
|
177 |
error("User " + quote(name) + " already exists --" + |
|
178 |
" for Phabricator it should have the description:\n " + quote(description)) |
|
179 |
} |
|
180 |
} |
|
181 |
||
71282 | 182 |
def command_setup(name: String, |
183 |
init: String = "", |
|
184 |
body: String = "", |
|
185 |
exit: String = ""): Path = |
|
71270 | 186 |
{ |
187 |
val command = Path.explode("/usr/local/bin") + Path.basic(name) |
|
71282 | 188 |
File.write(command, global_config_script(init = init, body = body, exit = exit)) |
71270 | 189 |
Isabelle_System.chmod("755", command) |
190 |
Isabelle_System.chown("root:root", command) |
|
191 |
command |
|
192 |
} |
|
193 |
||
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
|
194 |
def mercurial_setup(mercurial_source: String, progress: Progress = No_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
|
195 |
{ |
71281 | 196 |
progress.echo("\nMercurial installation from source " + quote(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
|
197 |
Isabelle_System.with_tmp_dir("mercurial")(tmp_dir => |
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
|
198 |
{ |
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
|
199 |
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
|
200 |
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
|
201 |
val archive = tmp_dir + Path.basic("mercurial.tar.gz") |
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 |
Bytes.write(archive, Url.read_bytes(Url(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
|
203 |
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
|
204 |
} |
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 |
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
|
206 |
|
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 |
Isabelle_System.gnutar("-xzf " + File.bash_path(archive), dir = tmp_dir).check |
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 |
|
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
|
209 |
File.read_dir(tmp_dir).filter(name => (tmp_dir + Path.basic(name)).is_dir) match { |
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 |
case List(dir) => |
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
|
211 |
val build_dir = tmp_dir + Path.basic(dir) |
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 |
progress.bash("make all && make install", cwd = build_dir.file, echo = true).check |
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 |
case dirs => |
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 |
error("Bad archive " + 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
|
215 |
(if (dirs.isEmpty) "" else "\nmultiple directory entries " + commas_quote(dirs))) |
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
|
216 |
} |
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
|
217 |
}) |
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
|
218 |
} |
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
|
219 |
|
70967 | 220 |
def phabricator_setup( |
221 |
name: String = default_name, |
|
222 |
root: String = "", |
|
223 |
repo: String = "", |
|
71047 | 224 |
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
|
225 |
mercurial_source: String = "", |
70967 | 226 |
progress: Progress = No_Progress) |
227 |
{ |
|
228 |
/* system environment */ |
|
229 |
||
230 |
Linux.check_system_root() |
|
231 |
||
71079 | 232 |
progress.echo("System packages ...") |
233 |
||
71047 | 234 |
if (package_update) { |
235 |
Linux.package_update(progress = progress) |
|
236 |
Linux.check_reboot_required() |
|
237 |
} |
|
70967 | 238 |
|
239 |
Linux.package_install(packages, progress = progress) |
|
240 |
Linux.check_reboot_required() |
|
241 |
||
242 |
||
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
|
243 |
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
|
244 |
for { name <- List("mercurial", "mercurial-common") if Linux.package_installed(name) } { |
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 |
error("Cannot install Mercurial from 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
|
246 |
"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
|
247 |
} |
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
|
248 |
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
|
249 |
} |
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
|
250 |
|
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
|
251 |
|
71049 | 252 |
/* users */ |
253 |
||
71125 | 254 |
if (name.contains((c: Char) => !(Symbol.is_ascii_letter(c) || Symbol.is_ascii_digit(c))) || |
71269 | 255 |
Set("", "ssh", "phd", "dump", daemon_user).contains(name)) { |
71125 | 256 |
error("Bad installation name: " + quote(name)) |
71049 | 257 |
} |
258 |
||
259 |
user_setup(daemon_user, "Phabricator Daemon User", ssh_setup = true) |
|
260 |
user_setup(name, "Phabricator SSH User") |
|
261 |
||
262 |
||
70967 | 263 |
/* basic installation */ |
264 |
||
71079 | 265 |
progress.echo("\nPhabricator installation ...") |
71076 | 266 |
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
267 |
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
|
268 |
val repo_path = if (repo.nonEmpty) Path.explode(repo) else default_repo(name) |
70967 | 269 |
|
270 |
val configs = read_config() |
|
271 |
||
272 |
for (config <- configs if config.name == name) { |
|
273 |
error("Duplicate Phabricator installation " + quote(name) + " in " + config.root) |
|
274 |
} |
|
275 |
||
276 |
if (!Isabelle_System.bash("mkdir -p " + File.bash_path(root_path)).ok) { |
|
277 |
error("Failed to create root directory " + root_path) |
|
278 |
} |
|
279 |
||
71116 | 280 |
Isabelle_System.chown(Bash.string(www_user) + ":" + Bash.string(www_user), root_path) |
281 |
Isabelle_System.chmod("755", root_path) |
|
282 |
||
70967 | 283 |
progress.bash(cwd = root_path.file, echo = true, |
284 |
script = """ |
|
285 |
set -e |
|
71126 | 286 |
echo "Cloning distribution repositories:" |
70967 | 287 |
git clone https://github.com/phacility/libphutil.git |
288 |
git clone https://github.com/phacility/arcanist.git |
|
289 |
git clone https://github.com/phacility/phabricator.git |
|
290 |
""").check |
|
291 |
||
292 |
val config = Config(name, root_path) |
|
293 |
write_config(configs ::: List(config)) |
|
70968 | 294 |
|
71051 | 295 |
config.execute("config set pygments.enabled true") |
296 |
||
70968 | 297 |
|
71050 | 298 |
/* local repository directory */ |
299 |
||
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
300 |
progress.echo("\nRepository hosting setup ...") |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
301 |
|
71050 | 302 |
if (!Isabelle_System.bash("mkdir -p " + File.bash_path(repo_path)).ok) { |
303 |
error("Failed to create local repository directory " + repo_path) |
|
304 |
} |
|
305 |
||
71114 | 306 |
Isabelle_System.chown( |
307 |
"-R " + Bash.string(daemon_user) + ":" + Bash.string(daemon_user), repo_path) |
|
308 |
Isabelle_System.chmod("755", repo_path) |
|
71050 | 309 |
|
310 |
config.execute("config set repository.default-local-path " + File.bash_path(repo_path)) |
|
311 |
||
312 |
||
71277 | 313 |
val sudoers_file = |
314 |
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
|
315 |
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
|
316 |
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
|
317 |
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
|
318 |
|
71115 | 319 |
Isabelle_System.chmod("440", sudoers_file) |
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
320 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
321 |
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
|
322 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
323 |
|
70969 | 324 |
/* MySQL setup */ |
325 |
||
71079 | 326 |
progress.echo("\nMySQL setup ...") |
70969 | 327 |
|
71055
27a998cdc0f4
back to plain name, to have it accepted my mysql;
wenzelm
parents:
71054
diff
changeset
|
328 |
File.write(Path.explode("/etc/mysql/mysql.conf.d/" + phabricator_name(ext = "cnf")), |
71051 | 329 |
"""[mysqld] |
330 |
max_allowed_packet = 32M |
|
331 |
innodb_buffer_pool_size = 1600M |
|
332 |
local_infile = 0 |
|
333 |
""") |
|
334 |
||
335 |
Linux.service_restart("mysql") |
|
336 |
||
337 |
||
71266
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
338 |
def mysql_conf(R: Regex, which: String): String = |
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
339 |
{ |
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("_", "\\_") + |
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
361 |
"""`.* TO """ + mysql_user_string + ";")).check |
70969 | 362 |
|
71266
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
363 |
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
|
364 |
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
|
365 |
|
8451c86ffa85
proper mysql user setup: avoid superuser powers in production;
wenzelm
parents:
71265
diff
changeset
|
366 |
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
|
367 |
config.execute("config set storage.default-namespace " + Bash.string(mysql_name)) |
71051 | 368 |
config.execute("config set storage.mysql-engine.max-size 8388608") |
369 |
||
71102 | 370 |
progress.bash("bin/storage upgrade --force", cwd = config.home.file, echo = true).check |
70969 | 371 |
|
372 |
||
71269 | 373 |
/* database dump */ |
374 |
||
375 |
val dump_name = isabelle_phabricator_name(name = "dump") |
|
71282 | 376 |
command_setup(dump_name, body = |
71269 | 377 |
"""mkdir -p "$ROOT/database" && chown root:root "$ROOT/database" && chmod 700 "$ROOT/database" |
378 |
[ -e "$ROOT/database/dump.sql.gz" ] && mv -f "$ROOT/database/dump.sql.gz" "$ROOT/database/dump-old.sql.gz" |
|
379 |
echo "Creating $ROOT/database/dump.sql.gz" |
|
71270 | 380 |
"$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' """) |
71269 | 381 |
|
382 |
||
71051 | 383 |
/* PHP setup */ |
384 |
||
385 |
val php_version = |
|
386 |
Isabelle_System.bash("""php --run 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;'""") |
|
387 |
.check.out |
|
388 |
||
389 |
val php_conf = |
|
390 |
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
|
391 |
Path.explode("apache2/conf.d") + |
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
392 |
Path.basic(isabelle_phabricator_name(ext = "ini")) |
71051 | 393 |
|
394 |
File.write(php_conf, |
|
395 |
"post_max_size = 32M\n" + |
|
396 |
"opcache.validate_timestamps = 0\n" + |
|
71129 | 397 |
"memory_limit = 512M\n" + |
398 |
"max_execution_time = 120\n") |
|
71051 | 399 |
|
400 |
||
70968 | 401 |
/* Apache setup */ |
402 |
||
71079 | 403 |
progress.echo("Apache setup ...") |
70968 | 404 |
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
405 |
val apache_root = Path.explode("/etc/apache2") |
70968 | 406 |
val apache_sites = apache_root + Path.explode("sites-available") |
407 |
||
408 |
if (!apache_sites.is_dir) error("Bad Apache sites directory " + apache_sites) |
|
409 |
||
71058 | 410 |
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
|
411 |
val server_url = "http://" + server_name |
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
412 |
|
71058 | 413 |
File.write(apache_sites + Path.basic(isabelle_phabricator_name(name = name, ext = "conf")), |
70968 | 414 |
"""<VirtualHost *:80> |
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
415 |
ServerName """ + server_name + """ |
70968 | 416 |
ServerAdmin webmaster@localhost |
70969 | 417 |
DocumentRoot """ + config.home.implode + """/webroot |
70968 | 418 |
|
419 |
ErrorLog ${APACHE_LOG_DIR}/error.log |
|
420 |
RewriteEngine on |
|
421 |
RewriteRule ^(.*)$ /index.php?__path__=$1 [B,L,QSA] |
|
422 |
</VirtualHost> |
|
423 |
||
424 |
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet |
|
425 |
""") |
|
426 |
||
71051 | 427 |
Isabelle_System.bash( """ |
70968 | 428 |
set -e |
429 |
a2enmod rewrite |
|
71058 | 430 |
a2ensite """ + Bash.string(isabelle_phabricator_name(name = name))).check |
71051 | 431 |
|
71057 | 432 |
config.execute("config set phabricator.base-uri " + Bash.string(server_url)) |
433 |
||
71051 | 434 |
Linux.service_restart("apache2") |
70968 | 435 |
|
71128
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
436 |
progress.echo("\nWeb configuration via " + server_url) |
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
437 |
|
71053 | 438 |
|
439 |
/* PHP daemon */ |
|
440 |
||
71128
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
441 |
progress.echo("\nPHP daemon setup ...") |
71053 | 442 |
|
71273 | 443 |
val phd_log_path = Path.explode("/var/tmp/phd") |
444 |
Isabelle_System.mkdirs(phd_log_path) |
|
445 |
Isabelle_System.chown( |
|
446 |
"-R " + Bash.string(daemon_user) + ":" + Bash.string(daemon_user), phd_log_path) |
|
447 |
Isabelle_System.chmod("755", phd_log_path) |
|
448 |
||
71053 | 449 |
config.execute("config set phd.user " + Bash.string(daemon_user)) |
71112 | 450 |
config.execute("config set phd.log-directory /var/tmp/phd/" + |
451 |
isabelle_phabricator_name(name = name) + "/log") |
|
71053 | 452 |
|
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
|
453 |
val phd_name = isabelle_phabricator_name(name = "phd") |
71127 | 454 |
Linux.service_shutdown(phd_name) |
71282 | 455 |
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
|
456 |
try { |
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
457 |
Linux.service_install(phd_name, |
71053 | 458 |
"""[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
|
459 |
Description=PHP daemon manager for Isabelle/Phabricator |
71053 | 460 |
After=syslog.target network.target apache2.service mysql.service |
461 |
||
462 |
[Service] |
|
463 |
Type=oneshot |
|
464 |
User=""" + daemon_user + """ |
|
465 |
Group=""" + daemon_user + """ |
|
466 |
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
|
467 |
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
|
468 |
ExecStop=""" + phd_command.implode + """ stop |
71053 | 469 |
RemainAfterExit=yes |
470 |
||
471 |
[Install] |
|
472 |
WantedBy=multi-user.target |
|
473 |
""") |
|
71128
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
474 |
} |
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
475 |
catch { |
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
476 |
case ERROR(msg) => |
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
477 |
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
|
478 |
error(msg) |
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
479 |
} |
70967 | 480 |
} |
481 |
||
482 |
||
483 |
/* Isabelle tool wrapper */ |
|
484 |
||
71097 | 485 |
val isabelle_tool2 = |
70967 | 486 |
Isabelle_Tool("phabricator_setup", "setup Phabricator server on Ubuntu Linux", args => |
487 |
{ |
|
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
|
488 |
var mercurial_source = "" |
71047 | 489 |
var repo = "" |
490 |
var package_update = false |
|
71078 | 491 |
var name = default_name |
70967 | 492 |
var root = "" |
493 |
||
494 |
val getopts = |
|
495 |
Getopts(""" |
|
71078 | 496 |
Usage: isabelle phabricator_setup [OPTIONS] |
70967 | 497 |
|
498 |
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
|
499 |
-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
|
500 |
""" + standard_mercurial_source + """ |
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
501 |
-R DIR repository directory (default: """ + default_repo("NAME") + """) |
71047 | 502 |
-U full update of system packages before installation |
71078 | 503 |
-n NAME Phabricator installation name (default: """ + quote(default_name) + """) |
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
504 |
-r DIR installation root directory (default: """ + default_root("NAME") + """) |
70967 | 505 |
|
71103 | 506 |
Install Phabricator as LAMP application (Linux, Apache, MySQL, PHP). |
70967 | 507 |
|
71078 | 508 |
The installation name (default: """ + quote(default_name) + """) is mapped to a regular |
509 |
Unix user; this is relevant for public SSH access. |
|
70967 | 510 |
""", |
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
|
511 |
"M:" -> (arg => mercurial_source = (if (arg == ":") standard_mercurial_source else arg)), |
70967 | 512 |
"R:" -> (arg => repo = arg), |
71047 | 513 |
"U" -> (_ => package_update = true), |
71078 | 514 |
"n:" -> (arg => name = arg), |
70967 | 515 |
"r:" -> (arg => root = arg)) |
516 |
||
517 |
val more_args = getopts(args) |
|
71078 | 518 |
if (more_args.nonEmpty) getopts.usage() |
70967 | 519 |
|
520 |
val progress = new Console_Progress |
|
521 |
||
71268 | 522 |
val release = Linux.Release() |
523 |
if (!release.is_ubuntu_18_04) error("Bad Linux version: Ubuntu 18.04 LTS required") |
|
524 |
||
71078 | 525 |
phabricator_setup(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
|
526 |
package_update = package_update, mercurial_source = mercurial_source, progress = progress) |
70967 | 527 |
}) |
528 |
||
529 |
||
530 |
||
71066 | 531 |
/** setup mail **/ |
70967 | 532 |
|
71072 | 533 |
val mailers_template: String = |
534 |
"""[ |
|
535 |
{ |
|
536 |
"key": "example.org", |
|
537 |
"type": "smtp", |
|
538 |
"options": { |
|
539 |
"host": "mail.example.org", |
|
540 |
"port": 465, |
|
541 |
"user": "phabricator@example.org", |
|
542 |
"password": "********", |
|
543 |
"protocol": "ssl", |
|
544 |
"message-id": true |
|
545 |
} |
|
546 |
} |
|
547 |
]""" |
|
548 |
||
71066 | 549 |
def phabricator_setup_mail( |
550 |
name: String = default_name, |
|
551 |
config_file: Option[Path] = None, |
|
552 |
test_user: String = "", |
|
553 |
progress: Progress = No_Progress) |
|
70967 | 554 |
{ |
555 |
Linux.check_system_root() |
|
556 |
||
71066 | 557 |
val config = get_config(name) |
71073 | 558 |
val default_config_file = config.root + default_mailers |
71066 | 559 |
|
560 |
val mail_config = config_file getOrElse default_config_file |
|
561 |
||
562 |
def setup_mail |
|
563 |
{ |
|
564 |
progress.echo("Using mail configuration from " + mail_config) |
|
565 |
config.execute("config set cluster.mailers --stdin < " + File.bash_path(mail_config)) |
|
566 |
||
567 |
if (test_user.nonEmpty) { |
|
568 |
progress.echo("Sending test mail to " + quote(test_user)) |
|
569 |
progress.bash(cwd = config.home.file, echo = true, |
|
71102 | 570 |
script = """echo "Test from Phabricator ($(date))" | bin/mail send-test --subject "Test" --to """ + |
71066 | 571 |
Bash.string(test_user)).check |
572 |
} |
|
573 |
} |
|
574 |
||
575 |
if (config_file.isEmpty) { |
|
71070 | 576 |
if (!default_config_file.is_file) { |
577 |
File.write(default_config_file, mailers_template) |
|
71114 | 578 |
Isabelle_System.chmod("600", default_config_file) |
71070 | 579 |
} |
71066 | 580 |
if (File.read(default_config_file) == mailers_template) { |
71131 | 581 |
progress.echo("Please invoke the tool again, after providing details in\n " + |
582 |
default_config_file.implode + "\n") |
|
71066 | 583 |
} |
584 |
else setup_mail |
|
585 |
} |
|
586 |
else setup_mail |
|
70967 | 587 |
} |
588 |
||
589 |
||
590 |
/* Isabelle tool wrapper */ |
|
591 |
||
71097 | 592 |
val isabelle_tool3 = |
71066 | 593 |
Isabelle_Tool("phabricator_setup_mail", |
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
594 |
"setup mail for one Phabricator installation", args => |
70967 | 595 |
{ |
71066 | 596 |
var test_user = "" |
597 |
var name = default_name |
|
598 |
var config_file: Option[Path] = None |
|
599 |
||
70967 | 600 |
val getopts = |
601 |
Getopts(""" |
|
71066 | 602 |
Usage: isabelle phabricator_setup_mail [OPTIONS] |
603 |
||
604 |
Options are: |
|
605 |
-T USER send test mail to Phabricator user |
|
71103 | 606 |
-f FILE config file (default: """ + default_mailers + """ within Phabricator root) |
71066 | 607 |
-n NAME Phabricator installation name (default: """ + quote(default_name) + """) |
70967 | 608 |
|
71077 | 609 |
Provide mail configuration for existing Phabricator installation. |
71066 | 610 |
""", |
611 |
"T:" -> (arg => test_user = arg), |
|
612 |
"f:" -> (arg => config_file = Some(Path.explode(arg))), |
|
613 |
"n:" -> (arg => name = arg)) |
|
70967 | 614 |
|
615 |
val more_args = getopts(args) |
|
71066 | 616 |
if (more_args.nonEmpty) getopts.usage() |
70967 | 617 |
|
618 |
val progress = new Console_Progress |
|
619 |
||
71066 | 620 |
phabricator_setup_mail(name = name, config_file = config_file, |
621 |
test_user = test_user, progress = progress) |
|
70967 | 622 |
}) |
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
623 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
624 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
625 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
626 |
/** setup ssh **/ |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
627 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
628 |
/* sshd config */ |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
629 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
630 |
private val Port = """^\s*Port\s+(\d+)\s*$""".r |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
631 |
private val No_Port = """^#\s*Port\b.*$""".r |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
632 |
private val Any_Port = """^#?\s*Port\b.*$""".r |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
633 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
634 |
def conf_ssh_port(port: Int): String = |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
635 |
if (port == 22) "#Port 22" else "Port " + port |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
636 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
637 |
def read_ssh_port(conf: Path): Int = |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
638 |
{ |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
639 |
val lines = split_lines(File.read(conf)) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
640 |
val ports = |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
641 |
lines.flatMap({ |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
642 |
case Port(Value.Int(p)) => Some(p) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
643 |
case No_Port() => Some(22) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
644 |
case _ => None |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
645 |
}) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
646 |
ports match { |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
647 |
case List(port) => port |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
648 |
case Nil => error("Missing Port specification in " + conf) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
649 |
case _ => error("Multiple Port specifications in " + conf) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
650 |
} |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
651 |
} |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
652 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
653 |
def write_ssh_port(conf: Path, port: Int): Boolean = |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
654 |
{ |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
655 |
val old_port = read_ssh_port(conf) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
656 |
if (old_port == port) false |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
657 |
else { |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
658 |
val lines = split_lines(File.read(conf)) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
659 |
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
|
660 |
File.write(conf, cat_lines(lines1)) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
661 |
true |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
662 |
} |
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 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
665 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
666 |
/* phabricator_setup_ssh */ |
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 phabricator_setup_ssh( |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
669 |
server_port: Int = default_server_port, |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
670 |
system_port: Int = default_system_port, |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
671 |
test_server: Boolean = false, |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
672 |
progress: Progress = No_Progress) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
673 |
{ |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
674 |
Linux.check_system_root() |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
675 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
676 |
val configs = read_config() |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
677 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
678 |
if (server_port == system_port) { |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
679 |
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
|
680 |
} |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
681 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
682 |
val sshd_conf_system = Path.explode("/etc/ssh/sshd_config") |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
683 |
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
|
684 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
685 |
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
|
686 |
Linux.service_shutdown(ssh_name) |
cd166c3904dd
more robust: system ssh service is required for Phabricator ssh service;
wenzelm
parents:
71109
diff
changeset
|
687 |
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
688 |
val old_system_port = read_ssh_port(sshd_conf_system) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
689 |
if (old_system_port != system_port) { |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
690 |
progress.echo("Reconfigurig system ssh service") |
71111
cd166c3904dd
more robust: system ssh service is required for Phabricator ssh service;
wenzelm
parents:
71109
diff
changeset
|
691 |
Linux.service_shutdown("ssh") |
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
692 |
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
|
693 |
Linux.service_start("ssh") |
71109
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 |
progress.echo("Configuring " + ssh_name + " service") |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
697 |
|
71282 | 698 |
val ssh_command = command_setup(ssh_name, body = |
71122 | 699 |
"""if [ "$1" = "$NAME" ] |
700 |
then |
|
701 |
exec "$ROOT/phabricator/bin/ssh-auth" "$@" |
|
71270 | 702 |
fi""", exit = "exit 1") |
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
703 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
704 |
File.write(sshd_conf_server, |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
705 |
"""# OpenBSD Secure Shell server for Isabelle/Phabricator |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
706 |
AuthorizedKeysCommand """ + ssh_command.implode + """ |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
707 |
AuthorizedKeysCommandUser """ + daemon_user + """ |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
708 |
AuthorizedKeysFile none |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
709 |
AllowUsers """ + configs.map(_.name).mkString(" ") + """ |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
710 |
Port """ + server_port + """ |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
711 |
Protocol 2 |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
712 |
PermitRootLogin no |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
713 |
AllowAgentForwarding no |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
714 |
AllowTcpForwarding no |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
715 |
PrintMotd no |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
716 |
PrintLastLog no |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
717 |
PasswordAuthentication no |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
718 |
ChallengeResponseAuthentication no |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
719 |
PidFile /var/run/""" + ssh_name + """.pid |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
720 |
""") |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
721 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
722 |
Linux.service_install(ssh_name, |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
723 |
"""[Unit] |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
724 |
Description=OpenBSD Secure Shell server for Isabelle/Phabricator |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
725 |
After=network.target auditd.service |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
726 |
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
727 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
728 |
[Service] |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
729 |
EnvironmentFile=-/etc/default/ssh |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
730 |
ExecStartPre=/usr/sbin/sshd -f """ + sshd_conf_server.implode + """ -t |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
731 |
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
|
732 |
ExecReload=/usr/sbin/sshd -f """ + sshd_conf_server.implode + """ -t |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
733 |
ExecReload=/bin/kill -HUP $MAINPID |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
734 |
KillMode=process |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
735 |
Restart=on-failure |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
736 |
RestartPreventExitStatus=255 |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
737 |
Type=notify |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
738 |
RuntimeDirectory=sshd-phabricator |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
739 |
RuntimeDirectoryMode=0755 |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
740 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
741 |
[Install] |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
742 |
WantedBy=multi-user.target |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
743 |
Alias=""" + ssh_name + """.service |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
744 |
""") |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
745 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
746 |
for (config <- configs) { |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
747 |
progress.echo("phabricator " + quote(config.name) + " port " + server_port) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
748 |
config.execute("config set diffusion.ssh-port " + Bash.string(server_port.toString)) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
749 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
750 |
if (test_server) { |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
751 |
progress.bash( |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
752 |
"""unset DISPLAY |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
753 |
echo "{}" | ssh -p """ + Bash.string(server_port.toString) + |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
754 |
" -o StrictHostKeyChecking=false " + |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
755 |
Bash.string(config.name) + """@localhost conduit conduit.ping""").print |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
756 |
} |
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 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
761 |
/* Isabelle tool wrapper */ |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
762 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
763 |
val isabelle_tool4 = |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
764 |
Isabelle_Tool("phabricator_setup_ssh", |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
765 |
"setup ssh service for all Phabricator installations", args => |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
766 |
{ |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
767 |
var server_port = default_server_port |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
768 |
var system_port = default_system_port |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
769 |
var test_server = false |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
770 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
771 |
val getopts = |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
772 |
Getopts(""" |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
773 |
Usage: isabelle phabricator_setup_ssh [OPTIONS] |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
774 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
775 |
Options are: |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
776 |
-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
|
777 |
-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
|
778 |
-T test the ssh service for each Phabricator installation |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
779 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
780 |
Configure ssh service for all Phabricator installations: a separate sshd |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
781 |
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
|
782 |
be distinct. |
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 |
A particular Phabricator installation is addressed by using its |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
785 |
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
|
786 |
stored ssh keys. |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
787 |
""", |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
788 |
"p:" -> (arg => server_port = Value.Int.parse(arg)), |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
789 |
"q:" -> (arg => system_port = Value.Int.parse(arg)), |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
790 |
"T" -> (_ => test_server = true)) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
791 |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
792 |
val more_args = getopts(args) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
793 |
if (more_args.nonEmpty) getopts.usage() |
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 |
val progress = new Console_Progress |
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 |
phabricator_setup_ssh( |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
798 |
server_port = server_port, system_port = system_port, test_server = test_server, |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
799 |
progress = progress) |
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
800 |
}) |
70967 | 801 |
} |