diff options
author | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2017-04-26 07:31:32 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2017-04-27 12:07:39 +0000 |
commit | 67ce42d689de2f7c07e9d96e0eafbcb09cb54a24 (patch) | |
tree | 70234dbf912ad991435733b7bccd3ed21aaf311d /start-container-docker.sh | |
parent | 53641e699037d402b1bafccd7af3314da655e151 (diff) |
start-container-docker: Add container_exec command.
This command allows transparently execute commands inside container
via SSH. Arguments are properly quoted to allow drop-in replacement
for local/schroot shell.
Parameters are carefully quoted so that both will print the same result:
$ echo 'A B'
A B
$ container_exec echo 'A B'
A B
A naive remote shell would print:
$ ssh dev-01.tcwglab echo 'A B'
A B
Change-Id: Ie367a4566bcaf6af06c4d9c7bfc9e91065e196ff
Diffstat (limited to 'start-container-docker.sh')
-rwxr-xr-x | start-container-docker.sh | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/start-container-docker.sh b/start-container-docker.sh index eb0fb3dc..020e3fd8 100755 --- a/start-container-docker.sh +++ b/start-container-docker.sh @@ -242,6 +242,14 @@ ${prefix}container_stop () { $DOCKER stop $session_id } +${prefix}container_exec () +{ + local -a cmd + cmd=() + # Add quotes to every parameter + for i in "\$@"; do cmd+=(\$(printf '%q' "\$i")); done + ssh -p ${session_port} -A ${session_host} "cd \$(pwd); exec \${cmd[@]}" +} ${prefix}container_host=${session_host} ${prefix}container_port=${session_port} EOF |