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