|
let https = require('https') |
|
let URL = require('url'); |
|
let querystring = require('querystring'); |
|
let DockerClient = require('docker-exec-websocket-server').DockerExecClient; |
|
|
|
https.get(process.argv[2], res => { |
|
if (res.statusCode != 303) { |
|
console.log("Bad request"); |
|
} |
|
let socketUrl = querystring.parse(URL.parse(res.headers.location).query).socketUrl; |
|
|
|
let client = new DockerClient({ |
|
url: socketUrl, |
|
tty: true, |
|
command: [ |
|
'sh', '-c', [ |
|
'if [ -f "/etc/taskcluster-motd" ]; then cat /etc/taskcluster-motd; fi;', |
|
'if [ -z "$TERM" ]; then export TERM=xterm; fi;', |
|
'if [ -z "$HOME" ]; then export HOME=/root; fi;', |
|
'if [ -z "$USER" ]; then export USER=root; fi;', |
|
'if [ -z "$LOGNAME" ]; then export LOGNAME=root; fi;', |
|
'if [ -z `which "$SHELL"` ]; then export SHELL=bash; fi;', |
|
'if [ -z `which "$SHELL"` ]; then export SHELL=sh; fi;', |
|
'if [ -z `which "$SHELL"` ]; then export SHELL="/.taskclusterutils/busybox sh"; fi;', |
|
'SPAWN="$SHELL";', |
|
'if [ "$SHELL" = "bash" ]; then SPAWN="bash -li"; fi;', |
|
'if [ -f "/bin/taskcluster-interactive-shell" ]; then SPAWN="/bin/taskcluster-interactive-shell"; fi;', |
|
'exec $SPAWN;' |
|
].join('') |
|
] |
|
}); |
|
|
|
client.execute().then(() => { |
|
process.stdin.setRawMode(true); |
|
process.on('exit', () => { |
|
process.stdin.setRawMode(false); |
|
}); |
|
process.stdout.on('resize', () => { |
|
client.resize(process.stdout.rows, process.stdout.columns); |
|
}); |
|
process.stdin.pipe(client.stdin); |
|
client.stdout.pipe(process.stdout); |
|
client.stderr.pipe(process.stderr); |
|
client.on('exit', (exitCode) => { |
|
process.exit(exitCode); |
|
}); |
|
client.resize(process.stdout.rows, process.stdout.columns); |
|
}).catch(err => { |
|
console.log("Error: %s", err); |
|
}); |
|
}); |