| author | wenzelm |
| Mon, 16 Dec 2019 13:58:46 +0100 | |
| changeset 71283 | cfcc1a2233ca |
| parent 71282 | de59dd86760f |
| child 71284 | 49bc17bf4384 |
| 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:" |
| 71283 | 287 |
git clone --branch stable https://github.com/phacility/libphutil.git |
288 |
git clone --branch stable https://github.com/phacility/arcanist.git |
|
289 |
git clone --branch stable https://github.com/phacility/phabricator.git |
|
| 70967 | 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 |
||
| 71283 | 383 |
/* Phabricator upgrade */ |
384 |
||
385 |
command_setup(isabelle_phabricator_name(name = "upgrade"), |
|
386 |
init = |
|
387 |
"""BRANCH="${1:stable}"
|
|
388 |
if [ "$BRANCH" != "master" -a "$BRANCH" != "stable" ] |
|
389 |
then |
|
390 |
echo "Bad branch: \"$BRANCH\"" |
|
391 |
exit 1 |
|
392 |
fi |
|
393 |
||
394 |
systemctl stop isabelle-phabricator-phd |
|
395 |
systemctl stop apache2 |
|
396 |
""", |
|
397 |
body = |
|
398 |
"""echo -e "\nUpgrading phabricator \"$NAME\" root \"$ROOT\" ..." |
|
399 |
for REPO in libphutil arcanist phabricator |
|
400 |
do |
|
401 |
cd "$ROOT/$REPO" |
|
402 |
echo -e "\nUpdating \"$REPO\" ..." |
|
403 |
git checkout "$BRANCH" |
|
404 |
git pull |
|
405 |
done |
|
406 |
echo -e "\nUpgrading storage ..." |
|
407 |
"$ROOT/phabricator/bin/storage" upgrade --force |
|
408 |
""", |
|
409 |
exit = |
|
410 |
"""systemctl start apache2 |
|
411 |
systemctl start isabelle-phabricator-phd""") |
|
412 |
||
413 |
||
| 71051 | 414 |
/* PHP setup */ |
415 |
||
416 |
val php_version = |
|
417 |
Isabelle_System.bash("""php --run 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;'""")
|
|
418 |
.check.out |
|
419 |
||
420 |
val php_conf = |
|
421 |
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
|
422 |
Path.explode("apache2/conf.d") +
|
|
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
423 |
Path.basic(isabelle_phabricator_name(ext = "ini")) |
| 71051 | 424 |
|
425 |
File.write(php_conf, |
|
426 |
"post_max_size = 32M\n" + |
|
427 |
"opcache.validate_timestamps = 0\n" + |
|
| 71129 | 428 |
"memory_limit = 512M\n" + |
429 |
"max_execution_time = 120\n") |
|
| 71051 | 430 |
|
431 |
||
| 70968 | 432 |
/* Apache setup */ |
433 |
||
| 71079 | 434 |
progress.echo("Apache setup ...")
|
| 70968 | 435 |
|
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
436 |
val apache_root = Path.explode("/etc/apache2")
|
| 70968 | 437 |
val apache_sites = apache_root + Path.explode("sites-available")
|
438 |
||
439 |
if (!apache_sites.is_dir) error("Bad Apache sites directory " + apache_sites)
|
|
440 |
||
| 71058 | 441 |
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
|
442 |
val server_url = "http://" + server_name |
|
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
443 |
|
| 71058 | 444 |
File.write(apache_sites + Path.basic(isabelle_phabricator_name(name = name, ext = "conf")), |
| 70968 | 445 |
"""<VirtualHost *:80> |
|
71052
6bf53035baf0
clarified name prefixes: global config always uses "isabelle-phabricator";
wenzelm
parents:
71051
diff
changeset
|
446 |
ServerName """ + server_name + """ |
| 70968 | 447 |
ServerAdmin webmaster@localhost |
| 70969 | 448 |
DocumentRoot """ + config.home.implode + """/webroot |
| 70968 | 449 |
|
450 |
ErrorLog ${APACHE_LOG_DIR}/error.log
|
|
451 |
RewriteEngine on |
|
452 |
RewriteRule ^(.*)$ /index.php?__path__=$1 [B,L,QSA] |
|
453 |
</VirtualHost> |
|
454 |
||
455 |
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet |
|
456 |
""") |
|
457 |
||
| 71051 | 458 |
Isabelle_System.bash( """ |
| 70968 | 459 |
set -e |
460 |
a2enmod rewrite |
|
| 71058 | 461 |
a2ensite """ + Bash.string(isabelle_phabricator_name(name = name))).check |
| 71051 | 462 |
|
| 71057 | 463 |
config.execute("config set phabricator.base-uri " + Bash.string(server_url))
|
464 |
||
| 71051 | 465 |
Linux.service_restart("apache2")
|
| 70968 | 466 |
|
|
71128
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
467 |
progress.echo("\nWeb configuration via " + server_url)
|
|
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
468 |
|
| 71053 | 469 |
|
470 |
/* PHP daemon */ |
|
471 |
||
|
71128
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
472 |
progress.echo("\nPHP daemon setup ...")
|
| 71053 | 473 |
|
| 71273 | 474 |
val phd_log_path = Path.explode("/var/tmp/phd")
|
475 |
Isabelle_System.mkdirs(phd_log_path) |
|
476 |
Isabelle_System.chown( |
|
477 |
"-R " + Bash.string(daemon_user) + ":" + Bash.string(daemon_user), phd_log_path) |
|
478 |
Isabelle_System.chmod("755", phd_log_path)
|
|
479 |
||
| 71053 | 480 |
config.execute("config set phd.user " + Bash.string(daemon_user))
|
| 71112 | 481 |
config.execute("config set phd.log-directory /var/tmp/phd/" +
|
482 |
isabelle_phabricator_name(name = name) + "/log") |
|
| 71053 | 483 |
|
|
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
|
484 |
val phd_name = isabelle_phabricator_name(name = "phd") |
| 71127 | 485 |
Linux.service_shutdown(phd_name) |
| 71282 | 486 |
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
|
487 |
try {
|
|
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
488 |
Linux.service_install(phd_name, |
| 71053 | 489 |
"""[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
|
490 |
Description=PHP daemon manager for Isabelle/Phabricator |
| 71053 | 491 |
After=syslog.target network.target apache2.service mysql.service |
492 |
||
493 |
[Service] |
|
494 |
Type=oneshot |
|
495 |
User=""" + daemon_user + """ |
|
496 |
Group=""" + daemon_user + """ |
|
497 |
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
|
498 |
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
|
499 |
ExecStop=""" + phd_command.implode + """ stop |
| 71053 | 500 |
RemainAfterExit=yes |
501 |
||
502 |
[Install] |
|
503 |
WantedBy=multi-user.target |
|
504 |
""") |
|
|
71128
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
505 |
} |
|
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
506 |
catch {
|
|
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
507 |
case ERROR(msg) => |
|
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
508 |
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
|
509 |
error(msg) |
|
f79006c533b0
clarified errors: PHP daemon can fail under odd circumstances;
wenzelm
parents:
71127
diff
changeset
|
510 |
} |
| 70967 | 511 |
} |
512 |
||
513 |
||
514 |
/* Isabelle tool wrapper */ |
|
515 |
||
| 71097 | 516 |
val isabelle_tool2 = |
| 70967 | 517 |
Isabelle_Tool("phabricator_setup", "setup Phabricator server on Ubuntu Linux", args =>
|
518 |
{
|
|
|
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
|
519 |
var mercurial_source = "" |
| 71047 | 520 |
var repo = "" |
521 |
var package_update = false |
|
| 71078 | 522 |
var name = default_name |
| 70967 | 523 |
var root = "" |
524 |
||
525 |
val getopts = |
|
526 |
Getopts("""
|
|
| 71078 | 527 |
Usage: isabelle phabricator_setup [OPTIONS] |
| 70967 | 528 |
|
529 |
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
|
530 |
-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
|
531 |
""" + standard_mercurial_source + """ |
|
71068
510b89906d86
discontinued somewhat pointless Isabelle options: setup implicitly assumes Ubuntu 18.04;
wenzelm
parents:
71066
diff
changeset
|
532 |
-R DIR repository directory (default: """ + default_repo("NAME") + """)
|
| 71047 | 533 |
-U full update of system packages before installation |
| 71078 | 534 |
-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
|
535 |
-r DIR installation root directory (default: """ + default_root("NAME") + """)
|
| 70967 | 536 |
|
| 71103 | 537 |
Install Phabricator as LAMP application (Linux, Apache, MySQL, PHP). |
| 70967 | 538 |
|
| 71078 | 539 |
The installation name (default: """ + quote(default_name) + """) is mapped to a regular |
540 |
Unix user; this is relevant for public SSH access. |
|
| 70967 | 541 |
""", |
|
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
|
542 |
"M:" -> (arg => mercurial_source = (if (arg == ":") standard_mercurial_source else arg)), |
| 70967 | 543 |
"R:" -> (arg => repo = arg), |
| 71047 | 544 |
"U" -> (_ => package_update = true), |
| 71078 | 545 |
"n:" -> (arg => name = arg), |
| 70967 | 546 |
"r:" -> (arg => root = arg)) |
547 |
||
548 |
val more_args = getopts(args) |
|
| 71078 | 549 |
if (more_args.nonEmpty) getopts.usage() |
| 70967 | 550 |
|
551 |
val progress = new Console_Progress |
|
552 |
||
| 71268 | 553 |
val release = Linux.Release() |
554 |
if (!release.is_ubuntu_18_04) error("Bad Linux version: Ubuntu 18.04 LTS required")
|
|
555 |
||
| 71078 | 556 |
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
|
557 |
package_update = package_update, mercurial_source = mercurial_source, progress = progress) |
| 70967 | 558 |
}) |
559 |
||
560 |
||
561 |
||
| 71066 | 562 |
/** setup mail **/ |
| 70967 | 563 |
|
| 71072 | 564 |
val mailers_template: String = |
565 |
"""[ |
|
566 |
{
|
|
567 |
"key": "example.org", |
|
568 |
"type": "smtp", |
|
569 |
"options": {
|
|
570 |
"host": "mail.example.org", |
|
571 |
"port": 465, |
|
572 |
"user": "phabricator@example.org", |
|
573 |
"password": "********", |
|
574 |
"protocol": "ssl", |
|
575 |
"message-id": true |
|
576 |
} |
|
577 |
} |
|
578 |
]""" |
|
579 |
||
| 71066 | 580 |
def phabricator_setup_mail( |
581 |
name: String = default_name, |
|
582 |
config_file: Option[Path] = None, |
|
583 |
test_user: String = "", |
|
584 |
progress: Progress = No_Progress) |
|
| 70967 | 585 |
{
|
586 |
Linux.check_system_root() |
|
587 |
||
| 71066 | 588 |
val config = get_config(name) |
| 71073 | 589 |
val default_config_file = config.root + default_mailers |
| 71066 | 590 |
|
591 |
val mail_config = config_file getOrElse default_config_file |
|
592 |
||
593 |
def setup_mail |
|
594 |
{
|
|
595 |
progress.echo("Using mail configuration from " + mail_config)
|
|
596 |
config.execute("config set cluster.mailers --stdin < " + File.bash_path(mail_config))
|
|
597 |
||
598 |
if (test_user.nonEmpty) {
|
|
599 |
progress.echo("Sending test mail to " + quote(test_user))
|
|
600 |
progress.bash(cwd = config.home.file, echo = true, |
|
| 71102 | 601 |
script = """echo "Test from Phabricator ($(date))" | bin/mail send-test --subject "Test" --to """ + |
| 71066 | 602 |
Bash.string(test_user)).check |
603 |
} |
|
604 |
} |
|
605 |
||
606 |
if (config_file.isEmpty) {
|
|
| 71070 | 607 |
if (!default_config_file.is_file) {
|
608 |
File.write(default_config_file, mailers_template) |
|
| 71114 | 609 |
Isabelle_System.chmod("600", default_config_file)
|
| 71070 | 610 |
} |
| 71066 | 611 |
if (File.read(default_config_file) == mailers_template) {
|
| 71131 | 612 |
progress.echo("Please invoke the tool again, after providing details in\n " +
|
613 |
default_config_file.implode + "\n") |
|
| 71066 | 614 |
} |
615 |
else setup_mail |
|
616 |
} |
|
617 |
else setup_mail |
|
| 70967 | 618 |
} |
619 |
||
620 |
||
621 |
/* Isabelle tool wrapper */ |
|
622 |
||
| 71097 | 623 |
val isabelle_tool3 = |
| 71066 | 624 |
Isabelle_Tool("phabricator_setup_mail",
|
|
71109
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
625 |
"setup mail for one Phabricator installation", args => |
| 70967 | 626 |
{
|
| 71066 | 627 |
var test_user = "" |
628 |
var name = default_name |
|
629 |
var config_file: Option[Path] = None |
|
630 |
||
| 70967 | 631 |
val getopts = |
632 |
Getopts("""
|
|
| 71066 | 633 |
Usage: isabelle phabricator_setup_mail [OPTIONS] |
634 |
||
635 |
Options are: |
|
636 |
-T USER send test mail to Phabricator user |
|
| 71103 | 637 |
-f FILE config file (default: """ + default_mailers + """ within Phabricator root) |
| 71066 | 638 |
-n NAME Phabricator installation name (default: """ + quote(default_name) + """) |
| 70967 | 639 |
|
| 71077 | 640 |
Provide mail configuration for existing Phabricator installation. |
| 71066 | 641 |
""", |
642 |
"T:" -> (arg => test_user = arg), |
|
643 |
"f:" -> (arg => config_file = Some(Path.explode(arg))), |
|
644 |
"n:" -> (arg => name = arg)) |
|
| 70967 | 645 |
|
646 |
val more_args = getopts(args) |
|
| 71066 | 647 |
if (more_args.nonEmpty) getopts.usage() |
| 70967 | 648 |
|
649 |
val progress = new Console_Progress |
|
650 |
||
| 71066 | 651 |
phabricator_setup_mail(name = name, config_file = config_file, |
652 |
test_user = test_user, progress = progress) |
|
| 70967 | 653 |
}) |
|
71109
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 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
656 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
657 |
/** setup ssh **/ |
|
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 |
/* sshd config */ |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
660 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
661 |
private val Port = """^\s*Port\s+(\d+)\s*$""".r |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
662 |
private val No_Port = """^#\s*Port\b.*$""".r |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
663 |
private val Any_Port = """^#?\s*Port\b.*$""".r |
|
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 |
def conf_ssh_port(port: Int): String = |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
666 |
if (port == 22) "#Port 22" else "Port " + port |
|
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 read_ssh_port(conf: Path): Int = |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
669 |
{
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
670 |
val lines = split_lines(File.read(conf)) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
671 |
val ports = |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
672 |
lines.flatMap({
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
673 |
case Port(Value.Int(p)) => Some(p) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
674 |
case No_Port() => Some(22) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
675 |
case _ => None |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
676 |
}) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
677 |
ports match {
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
678 |
case List(port) => port |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
679 |
case Nil => error("Missing Port specification in " + conf)
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
680 |
case _ => error("Multiple Port specifications in " + conf)
|
|
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 |
} |
|
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 |
def write_ssh_port(conf: Path, port: Int): Boolean = |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
685 |
{
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
686 |
val old_port = read_ssh_port(conf) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
687 |
if (old_port == port) false |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
688 |
else {
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
689 |
val lines = split_lines(File.read(conf)) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
690 |
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
|
691 |
File.write(conf, cat_lines(lines1)) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
692 |
true |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
693 |
} |
|
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 |
/* phabricator_setup_ssh */ |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
698 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
699 |
def phabricator_setup_ssh( |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
700 |
server_port: Int = default_server_port, |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
701 |
system_port: Int = default_system_port, |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
702 |
test_server: Boolean = false, |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
703 |
progress: Progress = No_Progress) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
704 |
{
|
|
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))
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
780 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
781 |
if (test_server) {
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
782 |
progress.bash( |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
783 |
"""unset DISPLAY |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
784 |
echo "{}" | ssh -p """ + Bash.string(server_port.toString) +
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
785 |
" -o StrictHostKeyChecking=false " + |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
786 |
Bash.string(config.name) + """@localhost conduit conduit.ping""").print |
|
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 |
} |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
789 |
} |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
790 |
|
|
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 |
/* Isabelle tool wrapper */ |
|
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 isabelle_tool4 = |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
795 |
Isabelle_Tool("phabricator_setup_ssh",
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
796 |
"setup ssh service for all Phabricator installations", args => |
|
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 |
var server_port = default_server_port |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
799 |
var system_port = default_system_port |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
800 |
var test_server = false |
|
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 |
val getopts = |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
803 |
Getopts("""
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
804 |
Usage: isabelle phabricator_setup_ssh [OPTIONS] |
|
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 |
Options are: |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
807 |
-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
|
808 |
-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
|
809 |
-T test the ssh service for each Phabricator installation |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
810 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
811 |
Configure ssh service for all Phabricator installations: a separate sshd |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
812 |
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
|
813 |
be distinct. |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
814 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
815 |
A particular Phabricator installation is addressed by using its |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
816 |
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
|
817 |
stored ssh keys. |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
818 |
""", |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
819 |
"p:" -> (arg => server_port = Value.Int.parse(arg)), |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
820 |
"q:" -> (arg => system_port = Value.Int.parse(arg)), |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
821 |
"T" -> (_ => test_server = true)) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
822 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
823 |
val more_args = getopts(args) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
824 |
if (more_args.nonEmpty) getopts.usage() |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
825 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
826 |
val progress = new Console_Progress |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
827 |
|
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
828 |
phabricator_setup_ssh( |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
829 |
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
|
830 |
progress = progress) |
|
8c1c717a830b
configure SSH hosting via "isabelle phabricator_setup_ssh";
wenzelm
parents:
71103
diff
changeset
|
831 |
}) |
| 70967 | 832 |
} |