author | wenzelm |
Fri, 24 Feb 2023 20:52:35 +0100 | |
changeset 77369 | df17355f1e2c |
parent 77130 | 2b8cf3b94cde |
child 77509 | 3bc49507bae5 |
permissions | -rw-r--r-- |
64123 | 1 |
/* Title: Pure/General/ssh.scala |
2 |
Author: Makarius |
|
3 |
||
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
4 |
SSH client on OpenSSH command-line tools, preferably with connection |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
5 |
multiplexing, but this does not work on Windows. |
64123 | 6 |
*/ |
7 |
||
8 |
package isabelle |
|
9 |
||
10 |
||
73909 | 11 |
import java.util.{Map => JMap} |
76164
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
12 |
import java.io.{File => JFile} |
64123 | 13 |
|
14 |
||
75393 | 15 |
object SSH { |
76170 | 16 |
/* client command */ |
17 |
||
18 |
def client_command(port: Int = 0, control_path: String = ""): String = |
|
19 |
if (control_path.isEmpty || control_path == Bash.string(control_path)) { |
|
20 |
"ssh" + |
|
21 |
(if (port > 0) " -p " + port else "") + |
|
77369 | 22 |
if_proper(control_path, " -o ControlPath=" + control_path) |
76170 | 23 |
} |
24 |
else error ("Malformed SSH control socket: " + quote(control_path)) |
|
25 |
||
26 |
||
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
27 |
/* OpenSSH configuration and command-line */ |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
28 |
|
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
29 |
// see https://linux.die.net/man/5/ssh_config |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
30 |
object Config { |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
31 |
def entry(x: String, y: String): String = x + "=" + y |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
32 |
def entry(x: String, y: Int): String = entry(x, y.toString) |
76165 | 33 |
def entry(x: String, y: Long): String = entry(x, y.toString) |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
34 |
def entry(x: String, y: Boolean): String = entry(x, if (y) "yes" else "no") |
64141 | 35 |
|
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
36 |
def make(options: Options, |
76131
8b695e59db3f
clarified default: do not override port from ssh_config, which could be different from 22;
wenzelm
parents:
76130
diff
changeset
|
37 |
port: Int = 0, |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
38 |
user: String = "", |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
39 |
control_master: Boolean = false, |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
40 |
control_path: String = "" |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
41 |
): List[String] = { |
76168 | 42 |
val ssh_batch_mode = options.bool("ssh_batch_mode") |
76167 | 43 |
val ssh_compression = options.bool("ssh_compression") |
44 |
val ssh_alive_interval = options.real("ssh_alive_interval").round |
|
45 |
val ssh_alive_count_max = options.int("ssh_alive_count_max") |
|
46 |
||
76168 | 47 |
List( |
48 |
entry("BatchMode", ssh_batch_mode), |
|
49 |
entry("Compression", ssh_compression)) ::: |
|
76167 | 50 |
(if (ssh_alive_interval >= 0) List(entry("ServerAliveInterval", ssh_alive_interval)) else Nil) ::: |
51 |
(if (ssh_alive_count_max >= 0) List(entry("ServerAliveCountMax", ssh_alive_count_max)) else Nil) ::: |
|
76131
8b695e59db3f
clarified default: do not override port from ssh_config, which could be different from 22;
wenzelm
parents:
76130
diff
changeset
|
52 |
(if (port > 0) List(entry("Port", port)) else Nil) ::: |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
53 |
(if (user.nonEmpty) List(entry("User", user)) else Nil) ::: |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
54 |
(if (control_master) List("ControlMaster=yes", "ControlPersist=yes") else Nil) ::: |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
55 |
(if (control_path.nonEmpty) List("ControlPath=" + control_path) else Nil) |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
56 |
} |
64325 | 57 |
|
76147 | 58 |
def option(entry: String): String = "-o " + Bash.string(entry) |
59 |
def option(x: String, y: String): String = option(entry(x, y)) |
|
60 |
def option(x: String, y: Int): String = option(entry(x, y)) |
|
76165 | 61 |
def option(x: String, y: Long): String = option(entry(x, y)) |
76147 | 62 |
def option(x: String, y: Boolean): String = option(entry(x, y)) |
63 |
||
64 |
def command(command: String, config: List[String]): String = |
|
65 |
Bash.string(command) + config.map(entry => " " + option(entry)).mkString |
|
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
66 |
} |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
67 |
|
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
68 |
def sftp_string(str: String): String = { |
76150 | 69 |
val special = "[]?*\\{} \"'" |
70 |
if (str.isEmpty) "\"\"" |
|
71 |
else if (str.exists(special.contains)) { |
|
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
72 |
val res = new StringBuilder |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
73 |
for (c <- str) { |
76150 | 74 |
if (special.contains(c)) res += '\\' |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
75 |
res += c |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
76 |
} |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
77 |
res.toString() |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
78 |
} |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
79 |
else str |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
80 |
} |
67273
c573cfb2c407
more robust connection: prefer ServerAliveCountMax=3 (ssh default) instead of 1 (jsch default);
wenzelm
parents:
67067
diff
changeset
|
81 |
|
64123 | 82 |
|
76115
f17393e21388
clarified signature: discontinue somewhat pointless SSH.Context;
wenzelm
parents:
76100
diff
changeset
|
83 |
/* open session */ |
f17393e21388
clarified signature: discontinue somewhat pointless SSH.Context;
wenzelm
parents:
76100
diff
changeset
|
84 |
|
f17393e21388
clarified signature: discontinue somewhat pointless SSH.Context;
wenzelm
parents:
76100
diff
changeset
|
85 |
def open_session( |
f17393e21388
clarified signature: discontinue somewhat pointless SSH.Context;
wenzelm
parents:
76100
diff
changeset
|
86 |
options: Options, |
f17393e21388
clarified signature: discontinue somewhat pointless SSH.Context;
wenzelm
parents:
76100
diff
changeset
|
87 |
host: String, |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
88 |
port: Int = 0, |
76148
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
89 |
user: String = "" |
76115
f17393e21388
clarified signature: discontinue somewhat pointless SSH.Context;
wenzelm
parents:
76100
diff
changeset
|
90 |
): Session = { |
76148
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
91 |
val multiplex = options.bool("ssh_multiplexing") && !Platform.is_windows |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
92 |
val (control_master, control_path) = |
76161 | 93 |
if (multiplex) (true, Isabelle_System.tmp_file("ssh", initialized = false).getPath) |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
94 |
else (false, "") |
76131
8b695e59db3f
clarified default: do not override port from ssh_config, which could be different from 22;
wenzelm
parents:
76130
diff
changeset
|
95 |
new Session(options, host, port, user, control_master, control_path) |
64257 | 96 |
} |
64130 | 97 |
|
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
98 |
class Session private[SSH]( |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
99 |
val options: Options, |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
100 |
val host: String, |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
101 |
val port: Int, |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
102 |
val user: String, |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
103 |
control_master: Boolean, |
76136
1bb677cceea4
let rsync re-use ssh connection via control path;
wenzelm
parents:
76133
diff
changeset
|
104 |
val control_path: String |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
105 |
) extends System { |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
106 |
ssh => |
64128 | 107 |
|
76133 | 108 |
def port_suffix: String = if (port > 0) ":" + port else "" |
109 |
def user_prefix: String = if (user.nonEmpty) user + "@" else "" |
|
110 |
||
111 |
override def toString: String = user_prefix + host + port_suffix |
|
76132 | 112 |
override def hg_url: String = "ssh://" + toString + "/" |
76133 | 113 |
override def rsync_prefix: String = user_prefix + host + ":" |
64191 | 114 |
|
115 |
||
76147 | 116 |
/* local ssh commands */ |
64256
c3197aeae90b
simplified SSH.Session: sftp channel is always open and its operations provided by the main interface;
wenzelm
parents:
64254
diff
changeset
|
117 |
|
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
118 |
def run_command(command: String, |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
119 |
master: Boolean = false, |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
120 |
opts: String = "", |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
121 |
args: String = "", |
76164
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
122 |
cwd: JFile = null, |
77092 | 123 |
redirect: Boolean = false, |
64134
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
124 |
progress_stdout: String => Unit = (_: String) => (), |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
125 |
progress_stderr: String => Unit = (_: String) => (), |
75393 | 126 |
strict: Boolean = true |
127 |
): Process_Result = { |
|
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
128 |
val config = |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
129 |
Config.make(options, port = port, user = user, |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
130 |
control_master = master, control_path = control_path) |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
131 |
val cmd = |
76147 | 132 |
Config.command(command, config) + |
77369 | 133 |
if_proper(opts, " " + opts) + |
134 |
if_proper(args, " -- " + args) |
|
77092 | 135 |
Isabelle_System.bash(cmd, cwd = cwd, |
136 |
redirect = redirect, |
|
137 |
progress_stdout = progress_stdout, |
|
138 |
progress_stderr = progress_stderr, |
|
139 |
strict = strict) |
|
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
140 |
} |
64134
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
141 |
|
76164
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
142 |
def run_sftp( |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
143 |
script: String, |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
144 |
init: Path => Unit = _ => (), |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
145 |
exit: Path => Unit = _ => () |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
146 |
): Process_Result = { |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
147 |
Isabelle_System.with_tmp_dir("ssh") { dir => |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
148 |
init(dir) |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
149 |
File.write(dir + Path.explode("script"), script) |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
150 |
val result = |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
151 |
run_command("sftp", opts = "-b script", args = Bash.string(host), cwd = dir.file).check |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
152 |
exit(dir) |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
153 |
result |
76116
c4dc343fdbcb
clarified signature: avoid exposure of JSch types;
wenzelm
parents:
76115
diff
changeset
|
154 |
} |
c4dc343fdbcb
clarified signature: avoid exposure of JSch types;
wenzelm
parents:
76115
diff
changeset
|
155 |
} |
65009 | 156 |
|
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
157 |
def run_ssh(master: Boolean = false, opts: String = "", args: String = ""): Process_Result = { |
77369 | 158 |
val args1 = Bash.string(host) + if_proper(args, " " + args) |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
159 |
run_command("ssh", master = master, opts = opts, args = args1) |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
160 |
} |
64256
c3197aeae90b
simplified SSH.Session: sftp channel is always open and its operations provided by the main interface;
wenzelm
parents:
64254
diff
changeset
|
161 |
|
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
162 |
|
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
163 |
/* init and exit */ |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
164 |
|
76151 | 165 |
val user_home: String = { |
76154
dfddb80fc515
more robust: do not assume Bash syntax while testing for it;
wenzelm
parents:
76151
diff
changeset
|
166 |
run_ssh(master = control_master, args = "printenv HOME \";\" printenv SHELL").check.out_lines |
dfddb80fc515
more robust: do not assume Bash syntax while testing for it;
wenzelm
parents:
76151
diff
changeset
|
167 |
match { |
76149
ccc748255342
more robust: Bash.string operations require remote bash;
wenzelm
parents:
76148
diff
changeset
|
168 |
case List(user_home, shell) => |
ccc748255342
more robust: Bash.string operations require remote bash;
wenzelm
parents:
76148
diff
changeset
|
169 |
if (shell.endsWith("/bash")) user_home |
ccc748255342
more robust: Bash.string operations require remote bash;
wenzelm
parents:
76148
diff
changeset
|
170 |
else { |
ccc748255342
more robust: Bash.string operations require remote bash;
wenzelm
parents:
76148
diff
changeset
|
171 |
error("Bad SHELL for " + quote(toString) + " -- expected GNU bash, but found " + shell) |
ccc748255342
more robust: Bash.string operations require remote bash;
wenzelm
parents:
76148
diff
changeset
|
172 |
} |
ccc748255342
more robust: Bash.string operations require remote bash;
wenzelm
parents:
76148
diff
changeset
|
173 |
case _ => error("Malformed remote environment for " + quote(toString)) |
ccc748255342
more robust: Bash.string operations require remote bash;
wenzelm
parents:
76148
diff
changeset
|
174 |
} |
76151 | 175 |
} |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
176 |
|
77079
395a0701a125
clarified signature: minimal interface for getenv/expand_env, instead of bulky java.util.Map;
wenzelm
parents:
77077
diff
changeset
|
177 |
val settings: Isabelle_System.Settings = |
395a0701a125
clarified signature: minimal interface for getenv/expand_env, instead of bulky java.util.Map;
wenzelm
parents:
77077
diff
changeset
|
178 |
(name: String) => if (name == "HOME" || name == "USER_HOME") user_home else "" |
64256
c3197aeae90b
simplified SSH.Session: sftp channel is always open and its operations provided by the main interface;
wenzelm
parents:
64254
diff
changeset
|
179 |
|
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
180 |
override def close(): Unit = { |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
181 |
if (control_path.nonEmpty) run_ssh(opts = "-O exit").check |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
182 |
} |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
183 |
|
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
184 |
|
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
185 |
/* remote commands */ |
64256
c3197aeae90b
simplified SSH.Session: sftp channel is always open and its operations provided by the main interface;
wenzelm
parents:
64254
diff
changeset
|
186 |
|
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
187 |
override def execute(cmd_line: String, |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
188 |
progress_stdout: String => Unit = (_: String) => (), |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
189 |
progress_stderr: String => Unit = (_: String) => (), |
77092 | 190 |
redirect: Boolean = false, |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
191 |
settings: Boolean = true, |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
192 |
strict: Boolean = true |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
193 |
): Process_Result = { |
77077
c2e8ba15a10a
discontinued adhoc change of environment (from c62b99e3ec07), which has been mostly superseded by expand_path / remote_path (from ef6f7e8a018c);
wenzelm
parents:
77076
diff
changeset
|
194 |
run_command("ssh", |
c2e8ba15a10a
discontinued adhoc change of environment (from c62b99e3ec07), which has been mostly superseded by expand_path / remote_path (from ef6f7e8a018c);
wenzelm
parents:
77076
diff
changeset
|
195 |
args = Bash.string(host) + " " + Bash.string(cmd_line), |
c2e8ba15a10a
discontinued adhoc change of environment (from c62b99e3ec07), which has been mostly superseded by expand_path / remote_path (from ef6f7e8a018c);
wenzelm
parents:
77076
diff
changeset
|
196 |
progress_stdout = progress_stdout, |
c2e8ba15a10a
discontinued adhoc change of environment (from c62b99e3ec07), which has been mostly superseded by expand_path / remote_path (from ef6f7e8a018c);
wenzelm
parents:
77076
diff
changeset
|
197 |
progress_stderr = progress_stderr, |
77092 | 198 |
redirect = redirect, |
77077
c2e8ba15a10a
discontinued adhoc change of environment (from c62b99e3ec07), which has been mostly superseded by expand_path / remote_path (from ef6f7e8a018c);
wenzelm
parents:
77076
diff
changeset
|
199 |
strict = strict) |
64256
c3197aeae90b
simplified SSH.Session: sftp channel is always open and its operations provided by the main interface;
wenzelm
parents:
64254
diff
changeset
|
200 |
} |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
201 |
|
77054 | 202 |
override def download_file( |
203 |
url_name: String, |
|
204 |
file: Path, |
|
205 |
progress: Progress = new Progress |
|
206 |
): Unit = { |
|
207 |
val cmd_line = |
|
208 |
File.read(Path.explode("~~/lib/scripts/download_file")) + "\n" + |
|
209 |
"download_file " + Bash.string(url_name) + " " + bash_path(file) |
|
210 |
execute(cmd_line, |
|
211 |
progress_stdout = progress.echo, |
|
212 |
progress_stderr = progress.echo).check |
|
213 |
} |
|
214 |
||
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
215 |
override lazy val isabelle_platform: Isabelle_Platform = Isabelle_Platform(ssh = Some(ssh)) |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
216 |
|
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
217 |
|
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
218 |
/* remote file-system */ |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
219 |
|
66570 | 220 |
override def expand_path(path: Path): Path = path.expand_env(settings) |
77076 | 221 |
override def absolute_path(path: Path): Path = { |
222 |
val path1 = expand_path(path) |
|
223 |
if (path1.is_absolute) path1 else Path.explode(user_home) + path1 |
|
224 |
} |
|
225 |
||
64256
c3197aeae90b
simplified SSH.Session: sftp channel is always open and its operations provided by the main interface;
wenzelm
parents:
64254
diff
changeset
|
226 |
def remote_path(path: Path): String = expand_path(path).implode |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
227 |
|
67066 | 228 |
override def bash_path(path: Path): String = Bash.string(remote_path(path)) |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
229 |
def sftp_path(path: Path): String = sftp_string(remote_path(path)) |
64256
c3197aeae90b
simplified SSH.Session: sftp channel is always open and its operations provided by the main interface;
wenzelm
parents:
64254
diff
changeset
|
230 |
|
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
231 |
override def is_dir(path: Path): Boolean = run_ssh(args = "test -d " + bash_path(path)).ok |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
232 |
override def is_file(path: Path): Boolean = run_ssh(args = "test -f " + bash_path(path)).ok |
69300
8b6ab9989bcd
is_file/is_dir/read_dir: more uniform treatment of errors and boundary cases, notably for symlinks in ssh;
wenzelm
parents:
67771
diff
changeset
|
233 |
|
77092 | 234 |
override def delete(path: Path): Unit = { |
235 |
val cmd = if (is_dir(path)) "rmdir" else if (is_file(path)) "rm" else "" |
|
236 |
if (cmd.nonEmpty) run_sftp(cmd + " " + sftp_path(path)) |
|
237 |
} |
|
238 |
||
239 |
override def set_executable(path: Path, flag: Boolean): Unit = |
|
240 |
if (!execute("chmod a" + (if (flag) "+" else "-") + "x " + bash_path(path)).ok) { |
|
241 |
error("Failed to change executable status of " + quote(remote_path(path))) |
|
242 |
} |
|
243 |
||
75393 | 244 |
override def make_directory(path: Path): Path = { |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
245 |
if (!execute("mkdir -p " + bash_path(path)).ok) { |
76118 | 246 |
error("Failed to create directory: " + quote(remote_path(path))) |
64256
c3197aeae90b
simplified SSH.Session: sftp channel is always open and its operations provided by the main interface;
wenzelm
parents:
64254
diff
changeset
|
247 |
} |
72376 | 248 |
path |
249 |
} |
|
64256
c3197aeae90b
simplified SSH.Session: sftp channel is always open and its operations provided by the main interface;
wenzelm
parents:
64254
diff
changeset
|
250 |
|
77059 | 251 |
override def copy_file(src: Path, dst: Path): Unit = { |
252 |
val direct = if (is_dir(dst)) "/." else "" |
|
253 |
if (!execute("cp -a " + bash_path(src) + " " + bash_path(dst) + direct).ok) { |
|
254 |
error("Failed to copy file " + expand_path(src) + " to " + |
|
255 |
expand_path(dst) + " (ssh " + toString + ")") |
|
256 |
} |
|
257 |
} |
|
258 |
||
77096 | 259 |
override def read_dir(path: Path): List[String] = |
76241 | 260 |
run_sftp("@cd " + sftp_path(path) + "\n@ls -1 -a").out_lines.flatMap(s => |
261 |
if (s == "." || s == "..") None |
|
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
262 |
else Some(Library.perhaps_unprefix("./", s))) |
64256
c3197aeae90b
simplified SSH.Session: sftp channel is always open and its operations provided by the main interface;
wenzelm
parents:
64254
diff
changeset
|
263 |
|
76164
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
264 |
private def get_file[A](path: Path, f: Path => A): A = { |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
265 |
var result: Option[A] = None |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
266 |
run_sftp("get -p " + sftp_path(path) + " local", |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
267 |
exit = dir => result = Some(f(dir + Path.explode("local")))) |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
268 |
result.get |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
269 |
} |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
270 |
|
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
271 |
private def put_file(path: Path, f: Path => Unit): Unit = |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
272 |
run_sftp("put -p local " + sftp_path(path), |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
273 |
init = dir => f(dir + Path.explode("local"))) |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
274 |
|
73634 | 275 |
override def read_file(path: Path, local_path: Path): Unit = |
76164
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
276 |
get_file(path, Isabelle_System.copy_file(_, local_path)) |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
277 |
override def read_bytes(path: Path): Bytes = |
76164
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
278 |
get_file(path, Bytes.read) |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
279 |
override def read(path: Path): String = |
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
280 |
get_file(path, File.read) |
64256
c3197aeae90b
simplified SSH.Session: sftp channel is always open and its operations provided by the main interface;
wenzelm
parents:
64254
diff
changeset
|
281 |
|
73634 | 282 |
override def write_file(path: Path, local_path: Path): Unit = |
76164
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
283 |
put_file(path, Isabelle_System.copy_file(local_path, _)) |
77092 | 284 |
override def write_bytes(path: Path, bytes: Bytes): Unit = |
76164
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
285 |
put_file(path, Bytes.write(_, bytes)) |
77092 | 286 |
override def write(path: Path, text: String): Unit = |
76164
5e8bc80df6b3
clarified run_sftp: avoid platform_path via careful use of tmp_dir, to support both Windows and Cygwin ssh;
wenzelm
parents:
76163
diff
changeset
|
287 |
put_file(path, File.write(_, text)) |
72338 | 288 |
|
64137 | 289 |
|
290 |
/* tmp dirs */ |
|
291 |
||
77092 | 292 |
override def rm_tree(dir: Path): Unit = rm_tree(remote_path(dir)) |
64306
7b6dc1b36f20
tuned signature, in accordance to Isabelle_System;
wenzelm
parents:
64304
diff
changeset
|
293 |
|
64137 | 294 |
def rm_tree(remote_dir: String): Unit = |
64304 | 295 |
execute("rm -r -f " + Bash.string(remote_dir)).check |
64137 | 296 |
|
297 |
def tmp_dir(): String = |
|
76163
9df6f51ebf45
more robust, notably for macOS (see also ff92d6edff2c);
wenzelm
parents:
76161
diff
changeset
|
298 |
execute("mktemp -d /tmp/ssh-XXXXXXXXXXXX").check.out |
64137 | 299 |
|
75393 | 300 |
override def with_tmp_dir[A](body: Path => A): A = { |
64137 | 301 |
val remote_dir = tmp_dir() |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
302 |
try { body(Path.explode(remote_dir)) } |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
303 |
finally { rm_tree(remote_dir) } |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
304 |
} |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
305 |
|
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
306 |
|
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
307 |
/* port forwarding */ |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
308 |
|
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
309 |
def port_forwarding( |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
310 |
remote_port: Int, |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
311 |
remote_host: String = "localhost", |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
312 |
local_port: Int = 0, |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
313 |
local_host: String = "localhost", |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
314 |
ssh_close: Boolean = false |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
315 |
): Port_Forwarding = { |
76145 | 316 |
val port = if (local_port > 0) local_port else Isabelle_System.local_port() |
317 |
||
76147 | 318 |
val forward = List(local_host, port, remote_host, remote_port).mkString(":") |
319 |
val forward_option = "-L " + Bash.string(forward) |
|
320 |
||
321 |
val cancel: () => Unit = |
|
322 |
if (control_path.nonEmpty) { |
|
323 |
run_ssh(opts = forward_option + " -O forward").check |
|
324 |
() => run_ssh(opts = forward_option + " -O cancel") // permissive |
|
325 |
} |
|
76148
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
326 |
else { |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
327 |
val result = Synchronized[Exn.Result[Boolean]](Exn.Res(false)) |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
328 |
val thread = Isabelle_Thread.fork("port_forwarding") { |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
329 |
val opts = |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
330 |
forward_option + |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
331 |
" " + Config.option("SessionType", "none") + |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
332 |
" " + Config.option("PermitLocalCommand", true) + |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
333 |
" " + Config.option("LocalCommand", "pwd") |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
334 |
try { |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
335 |
run_command("ssh", opts = opts, args = Bash.string(host), |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
336 |
progress_stdout = _ => result.change(_ => Exn.Res(true))).check |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
337 |
} |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
338 |
catch { case exn: Throwable => result.change(_ => Exn.Exn(exn)) } |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
339 |
} |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
340 |
result.guarded_access { |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
341 |
case res@Exn.Res(ok) => if (ok) Some((), res) else None |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
342 |
case Exn.Exn(exn) => throw exn |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
343 |
} |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
344 |
() => thread.interrupt() |
769ebb139a32
support port forwarding without multiplexing (for the sake of Windows);
wenzelm
parents:
76147
diff
changeset
|
345 |
} |
76147 | 346 |
|
347 |
val shutdown_hook = |
|
348 |
Isabelle_System.create_shutdown_hook { cancel() } |
|
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
349 |
|
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
350 |
new Port_Forwarding(host, port, remote_host, remote_port) { |
76147 | 351 |
override def toString: String = forward |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
352 |
override def close(): Unit = { |
76147 | 353 |
cancel() |
354 |
Isabelle_System.remove_shutdown_hook(shutdown_hook) |
|
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
355 |
if (ssh_close) ssh.close() |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
356 |
} |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
357 |
} |
64137 | 358 |
} |
64123 | 359 |
} |
66570 | 360 |
|
76116
c4dc343fdbcb
clarified signature: avoid exposure of JSch types;
wenzelm
parents:
76115
diff
changeset
|
361 |
abstract class Port_Forwarding private[SSH]( |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
362 |
val host: String, |
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
363 |
val port: Int, |
76116
c4dc343fdbcb
clarified signature: avoid exposure of JSch types;
wenzelm
parents:
76115
diff
changeset
|
364 |
val remote_host: String, |
c4dc343fdbcb
clarified signature: avoid exposure of JSch types;
wenzelm
parents:
76115
diff
changeset
|
365 |
val remote_port: Int |
76122
b8f26c20d3b1
ssh client via regular OpenSSH tools, with authentic use of .ssh/config (notably proxy configuration);
wenzelm
parents:
76119
diff
changeset
|
366 |
) extends AutoCloseable |
76116
c4dc343fdbcb
clarified signature: avoid exposure of JSch types;
wenzelm
parents:
76115
diff
changeset
|
367 |
|
66570 | 368 |
|
369 |
/* system operations */ |
|
370 |
||
75393 | 371 |
trait System extends AutoCloseable { |
73634 | 372 |
def close(): Unit = () |
373 |
||
66570 | 374 |
def hg_url: String = "" |
375 |
||
75500 | 376 |
def rsync_prefix: String = "" |
75517 | 377 |
def rsync_path(path: Path): String = rsync_prefix + expand_path(path).implode |
75500 | 378 |
|
66570 | 379 |
def expand_path(path: Path): Path = path.expand |
77076 | 380 |
def absolute_path(path: Path): Path = path.absolute |
67066 | 381 |
def bash_path(path: Path): String = File.bash_path(path) |
69300
8b6ab9989bcd
is_file/is_dir/read_dir: more uniform treatment of errors and boundary cases, notably for symlinks in ssh;
wenzelm
parents:
67771
diff
changeset
|
382 |
def is_dir(path: Path): Boolean = path.is_dir |
66570 | 383 |
def is_file(path: Path): Boolean = path.is_file |
77092 | 384 |
def delete(path: Path): Unit = path.file.delete |
385 |
def set_executable(path: Path, flag: Boolean): Unit = File.set_executable(path, flag) |
|
72376 | 386 |
def make_directory(path: Path): Path = Isabelle_System.make_directory(path) |
77092 | 387 |
def rm_tree(dir: Path): Unit = Isabelle_System.rm_tree(dir) |
73634 | 388 |
def with_tmp_dir[A](body: Path => A): A = Isabelle_System.with_tmp_dir("tmp")(body) |
77096 | 389 |
def read_dir(path: Path): List[String] = File.read_dir(path) |
77059 | 390 |
def copy_file(path1: Path, path2: Path): Unit = Isabelle_System.copy_file(path1, path2) |
73634 | 391 |
def read_file(path1: Path, path2: Path): Unit = Isabelle_System.copy_file(path1, path2) |
75513 | 392 |
def read_bytes(path: Path): Bytes = Bytes.read(path) |
393 |
def read(path: Path): String = File.read(path) |
|
77092 | 394 |
def write_file(path1: Path, path2: Path): Unit = Isabelle_System.copy_file(path2, path1) |
395 |
def write_bytes(path: Path, bytes: Bytes): Unit = Bytes.write(path, bytes) |
|
396 |
def write(path: Path, text: String): Unit = File.write(path, text) |
|
66570 | 397 |
|
398 |
def execute(command: String, |
|
399 |
progress_stdout: String => Unit = (_: String) => (), |
|
400 |
progress_stderr: String => Unit = (_: String) => (), |
|
77092 | 401 |
redirect: Boolean = false, |
73634 | 402 |
settings: Boolean = true, |
66570 | 403 |
strict: Boolean = true): Process_Result = |
73634 | 404 |
Isabelle_System.bash(command, |
405 |
progress_stdout = progress_stdout, |
|
406 |
progress_stderr = progress_stderr, |
|
77092 | 407 |
redirect = redirect, |
73634 | 408 |
env = if (settings) Isabelle_System.settings() else null, |
409 |
strict = strict) |
|
72338 | 410 |
|
77054 | 411 |
def download_file(url_name: String, file: Path, progress: Progress = new Progress): Unit = |
412 |
Isabelle_System.download_file(url_name, file, progress = progress) |
|
413 |
||
72340 | 414 |
def isabelle_platform: Isabelle_Platform = Isabelle_Platform() |
77130 | 415 |
|
416 |
def isabelle_platform_family: Platform.Family.Value = |
|
417 |
Platform.Family.parse(isabelle_platform.ISABELLE_PLATFORM_FAMILY) |
|
66570 | 418 |
} |
419 |
||
420 |
object Local extends System |
|
64123 | 421 |
} |