Skip to content

Commit

Permalink
Rename et --prefix option to --terminal-path.
Browse files Browse the repository at this point in the history
The prefix option to the terminal client is misleading as it isn't a
prefix (or search path) and is treated as an absolute path to the
etterminal executable.  This renames it as such and removes the
superfluous positional arg in the command string building for the ssh
command (i.e. /usr/local/bin/etterminal etterminal -v 0)
  • Loading branch information
jshort committed Oct 11, 2022
1 parent a62cda4 commit 69ee277
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
18 changes: 11 additions & 7 deletions src/terminal/SshSetupHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
#include "SubprocessToString.hpp"

namespace et {
const string SshSetupHandler::ETTERMINAL_BIN = "etterminal";

string genCommand(const string& passkey, const string& id,
const string& clientTerm, const string& user, bool kill,
const string& command_prefix, const string& options) {
string SSH_SCRIPT_PREFIX;
const string& etterminal_path, const string& options) {
string ssh_script_prefix;
string etterminal_bin =
etterminal_path.empty() ? SshSetupHandler::ETTERMINAL_BIN : etterminal_path;

string COMMAND = "echo '" + id + "/" + passkey + "_" + clientTerm + "\n' | " +
command_prefix + " etterminal " + options;
string command = "echo '" + id + "/" + passkey + "_" + clientTerm + "' | " +
etterminal_bin + " " + options;

// Kill old ET sessions of the user
if (kill) {
SSH_SCRIPT_PREFIX =
"pkill etterminal -u " + user + "; sleep 0.5; " + SSH_SCRIPT_PREFIX;
ssh_script_prefix =
"pkill etterminal -u " + user + "; sleep 0.5; " + ssh_script_prefix;
}

return SSH_SCRIPT_PREFIX + COMMAND;
return ssh_script_prefix + command;
}

string SshSetupHandler::SetupSsh(const string& user, const string& host,
Expand Down
3 changes: 2 additions & 1 deletion src/terminal/SshSetupHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ class SshSetupHandler {
static string SetupSsh(const string &user, const string &host,
const string &host_alias, int port,
const string &jumphost, int jport, bool kill,
int vlevel, const string &cmd_prefix,
int vlevel, const string &etterminal_path,
const string &serverFifo,
const std::vector<std::string>& ssh_options);
static const string ETTERMINAL_BIN;
};
} // namespace et
#endif // __ET_SSH_SETUP_HANDLER__
19 changes: 10 additions & 9 deletions src/terminal/TerminalClientMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ int main(int argc, char** argv) {
cxxopts::value<int>()->default_value("2022")) //
("c,command", "Run command on connect",
cxxopts::value<std::string>()) //
("prefix", "Add prefix when launching etterminal on server side",
("terminal-path", "Path to etterminal on server side. "
"Use if etterminal is not on the system path.",
cxxopts::value<std::string>()) //
("t,tunnel",
"Tunnel: Array of source:destination ports or "
Expand All @@ -69,8 +70,8 @@ int main(int argc, char** argv) {
("x,kill-other-sessions",
"kill all old sessions belonging to the user") //
("macserver",
"Set when connecting to an OS/X server. Sets "
"--prefix=/usr/local/bin/etterminal") //
"Set when connecting to an macOS server. Sets "
"--terminal-path=/usr/local/bin/etterminal") //
("v,verbose", "Enable verbose logging",
cxxopts::value<int>()->default_value("0")) //
("k,keepalive", "Client keepalive duration in seconds",
Expand Down Expand Up @@ -265,17 +266,17 @@ int main(int argc, char** argv) {
if (result.count("ssh-option")) {
ssh_options = result["ssh-option"].as<std::vector<string>>();
}
string prefix = "";
string etterminal_path = "";
if (result.count("macserver") > 0) {
prefix = "/usr/local/bin/etterminal";
etterminal_path = "/usr/local/bin/etterminal";
}
if (result.count("prefix")) {
prefix = result["prefix"].as<string>();
if (result.count("etterminal_path")) {
etterminal_path = result["terminal-path"].as<string>();
}
string idpasskeypair = SshSetupHandler::SetupSsh(
username, destinationHost, host_alias, destinationPort, jumphost, jport,
result.count("x") > 0, result["verbose"].as<int>(), prefix, serverFifo,
ssh_options);
result.count("x") > 0, result["verbose"].as<int>(), etterminal_path,
serverFifo, ssh_options);

string id = "", passkey = "";
// Trim whitespace
Expand Down

0 comments on commit 69ee277

Please sign in to comment.