forked from google/orbit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_client_ssh.ps1
63 lines (48 loc) · 2.21 KB
/
run_client_ssh.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright (c) 2020 The Orbit Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Connects to the instance and starts OrbitClientGgp. To also deploy OrbitClientGgp,
# invoke with a the argument -deploy and a path to the OrbitClientGgp executable
# e.g. run_client_ssh.ps1 -deploy build/bin/OrbitClientGgp
# All other arguments will be passed to OrbitClientGgp.
param (
[Parameter(Mandatory=$false)][string]$deploy,
[Parameter(ValueFromRemainingArguments = $true)]$remainingArgs
)
$ggp_sdk_path = $env:GGP_SDK_PATH
IF(!$ggp_sdk_path) {
throw "GGP_SDK_PATH environment variable not found"
}
$ggp_path = "$($ggp_sdk_path)dev\bin\ggp.exe"
IF($deploy) {
$ggp_put_command = "`"$($ggp_path)`" ssh put `"$($deploy)`""
Invoke-Expression "& $ggp_put_command"
$ggp_chmod_command = "`"$($ggp_path)`" ssh shell -- chmod u+x /mnt/developer/OrbitClientGgp"
Invoke-Expression "& $ggp_chmod_command"
}
$ggp_ssh_init_command = "`"$($ggp_path)`" ssh init"
Invoke-Expression "& $ggp_ssh_init_command" | Tee-Object -Variable ggp_out
$lines = $ggp_out -split "\n"
ForEach ($line in $lines) {
if ($line.Contains("User:")) {
$ggp_user = $line.Replace("User:", "").Trim()
}
if ($line.Contains("Host:")) {
$ggp_host = $line.Replace("Host:", "").Trim()
}
if ($line.Contains("Port:")) {
$ggp_port = $line.Replace("Port:", "").Trim()
}
if ($line.Contains("Key Path:")) {
$ggp_key_path = $line.Replace("Key Path:", "").Trim()
}
if ($line.Contains("Known Hosts Path:")) {
$ggp_known_hosts_path = $line.Replace("Known Hosts Path:", "").Trim()
}
}
IF (!$ggp_user -Or !$ggp_host -Or !$ggp_port -Or !$ggp_key_path -Or !$ggp_known_hosts_path) {
throw "Unable to get all necessary information from ggp ssh init"
}
$ssh_path = "$($ggp_sdk_path)tools\OpenSSH-Win64\ssh.exe"
$ssh_command = "`"$($ssh_path)`" -t -p`"$($ggp_port)`" -i`"$($ggp_key_path)`" -oStrictHostKeyChecking=yes -oUserKnownHostsFile=`"$($ggp_known_hosts_path)`" -L44766:localhost:44766 -L44765:localhost:44765 $($ggp_user)@$($ggp_host) -- /mnt/developer/OrbitClientGgp $($remainingArgs)"
Invoke-Expression "& $ssh_command"