Skip to content

Commit

Permalink
Merge pull request #870 from telepresenceio/path-check
Browse files Browse the repository at this point in the history
Make PATH and dependency fixes
  • Loading branch information
Abhay Saxena committed Dec 13, 2018
2 parents df31fe7 + fb6223d commit 8f52567
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions newsfragments/869.bugfix
@@ -0,0 +1 @@
Telepresence now reports an error if your command cannot be launched.
5 changes: 4 additions & 1 deletion telepresence/outbound/local.py
Expand Up @@ -119,7 +119,10 @@ def launch_vpn(
"""
connect_sshuttle(runner, remote_info, also_proxy, ssh)
env = get_local_env(runner, env_overrides, False)
process = Popen(command, env=env)
try:
process = Popen(command, env=env)
except OSError as exc:
raise runner.fail("Failed to launch your command: {}".format(exc))
runner.add_cleanup(
"Terminate local process", terminate_local_process, runner, process
)
Expand Down
11 changes: 9 additions & 2 deletions telepresence/outbound/setup.py
Expand Up @@ -18,7 +18,14 @@
from .local import launch_inject, launch_vpn


def check_local_command(runner: Runner, command: str) -> None:
if runner.depend([command]):
raise runner.fail("{}: command not found".format(command))


def setup_inject(runner: Runner, args):
command = ["torsocks"] + (args.run or ["bash", "--norc"])
check_local_command(runner, command[1])
runner.require(["torsocks"], "Please install torsocks (v2.1 or later)")
if runner.chatty:
runner.show(
Expand All @@ -28,7 +35,6 @@ def setup_inject(runner: Runner, args):
"method limitations see "
"https://telepresence.io/reference/methods.html"
)
command = ["torsocks"] + (args.run or ["bash", "--norc"])

def launch(
runner_, _remote_info, env, socks_port, _ssh, _mount_dir, _pod_info
Expand All @@ -39,6 +45,8 @@ def launch(


def setup_vpn(runner: Runner, args):
command = args.run or ["bash", "--norc"]
check_local_command(runner, command[0])
runner.require(["sshuttle-telepresence"],
"Part of the Telepresence package. Try reinstalling.")
if runner.platform == "linux":
Expand All @@ -57,7 +65,6 @@ def setup_vpn(runner: Runner, args):
"a full list of method limitations see "
"https://telepresence.io/reference/methods.html"
)
command = args.run or ["bash", "--norc"]

def launch(
runner_, remote_info, env, _socks_port, ssh, _mount_dir, _pod_info
Expand Down
10 changes: 9 additions & 1 deletion telepresence/runner/runner.py
Expand Up @@ -202,6 +202,7 @@ def require_sudo(self) -> None:
if self.sudo_held:
return

self.require(["sudo"], "Some operations require elevated privileges")
try:
# See whether we can grab privileges without a password
self.check_call(["sudo", "-n", "echo", "-n"])
Expand All @@ -223,7 +224,14 @@ def depend(self, commands: typing.Iterable[str]) -> typing.List[str]:
"""
Find unavailable commands from a set of dependencies
"""
return [command for command in commands if which(command) is None]
missing = []
for command in commands:
path = which(command)
if path:
self.write("Found {} -> {}".format(command, path))
else:
missing.append(command)
return missing

def require(self, commands: typing.Iterable[str], message: str) -> None:
"""
Expand Down

0 comments on commit 8f52567

Please sign in to comment.