Skip to content

Commit

Permalink
Implement tools in cli path. fix mooltipass#345
Browse files Browse the repository at this point in the history
  • Loading branch information
Raoul Hecky committed Jul 5, 2021
1 parent 98ff210 commit 045f9a4
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 8 deletions.
7 changes: 4 additions & 3 deletions scripts/ci/osx/after_success.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ cat build/$APP.app/Contents/Info.plist
cp build/moolticuted build/$APP.app/Contents/MacOS/

#Get 3rd party tools
wget_retry https://calaos.fr/mooltipass/tools/macos/mc-agent -O build/$APP.app/Contents/MacOS/mc-agent
wget_retry https://calaos.fr/mooltipass/tools/macos/mc-cli -O build/$APP.app/Contents/MacOS/mc-cli
chmod +x build/$APP.app/Contents/MacOS/mc-agent build/$APP.app/Contents/MacOS/mc-cli
mkdir -p build/$APP.app/Contents/MacOS/cli
wget_retry https://calaos.fr/mooltipass/tools/macos/mc-agent -O build/$APP.app/Contents/MacOS/cli/mc-agent
wget_retry https://calaos.fr/mooltipass/tools/macos/mc-cli -O build/$APP.app/Contents/MacOS/cli/mc-cli
chmod +x build/$APP.app/Contents/MacOS/cli/mc-agent build/$APP.app/Contents/MacOS/cli/mc-cli

# use macdeployqt to deploy the application
echo "Calling macdeployqt"
Expand Down
2 changes: 1 addition & 1 deletion src/AppGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void AppGui::startSSHAgent()
if (s.value("settings/auto_start_ssh").toBool())
{
sshAgentProcess = new QProcess(this);
QString program = QCoreApplication::applicationDirPath () + "/mc-agent";
QString program = QCoreApplication::applicationDirPath () + "/cli/mc-agent";
QStringList arguments;
#ifndef Q_OS_WIN
arguments << "--no-fork";
Expand Down
6 changes: 3 additions & 3 deletions src/SSHManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void SSHManagement::onServiceExists(const QString service, bool exists)
if (exists)
{
sshProcess = new QProcess(this);
const auto program = QCoreApplication::applicationDirPath () + "/mc-agent";
const auto program = QCoreApplication::applicationDirPath () + "/cli/mc-agent";
auto actualProg = program;
#ifdef Q_OS_WIN
actualProg += ".exe";
Expand Down Expand Up @@ -386,7 +386,7 @@ void SSHManagement::on_pushButtonImport_clicked()
currentAction = Action::ImportKey;

sshProcess = new QProcess(this);
QString program = QCoreApplication::applicationDirPath () + "/mc-agent";
QString program = QCoreApplication::applicationDirPath () + "/cli/mc-agent";
QStringList arguments;
arguments << "--output_progress"
<< "cli"
Expand Down Expand Up @@ -432,7 +432,7 @@ void SSHManagement::on_pushButtonDelete_clicked()
currentAction = Action::DeleteKey;

sshProcess = new QProcess(this);
QString program = QCoreApplication::applicationDirPath () + "/mc-agent";
QString program = QCoreApplication::applicationDirPath () + "/cli/mc-agent";
QStringList arguments;
arguments << "--output_progress"
<< "cli"
Expand Down
85 changes: 84 additions & 1 deletion win/installer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ Filename: "{app}\moolticute.exe"; WorkingDir: "{app}"; Description: "Start Moolt

[Registry]
Root: "HKCU"; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "Moolticute"; ValueData: "{app}\moolticute.exe --autolaunched"; Flags: uninsdeletevalue
Root: "HKCU"; Subkey: "Environment"; ValueType: expandsz; ValueName: "PATH"; ValueData: "{olddata};{app}\cli"

[Code]
function IsAppRunning(const FileName : string): Boolean;
Expand Down Expand Up @@ -186,3 +185,87 @@ begin
ShellExec('', ExpandConstant('{sys}\taskkill.exe'),'/f /im SnoreToast.exe', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
END
end;
const EnvironmentKey = 'Environment';
procedure EnvAddPath(instlPath: string);
var
Paths: string;
begin
{ Retrieve current path (use empty string if entry not exists) }
if not RegQueryStringValue(HKEY_CURRENT_USER, EnvironmentKey, 'Path', Paths) then
Paths := '';
if Paths = '' then
Paths := instlPath + ';'
else
begin
{ Skip if string already found in path }
if Pos(';' + Uppercase(instlPath) + ';', ';' + Uppercase(Paths) + ';') > 0 then exit;
if Pos(';' + Uppercase(instlPath) + '\;', ';' + Uppercase(Paths) + ';') > 0 then exit;
{ Append App Install Path to the end of the path variable }
Log(Format('Right(Paths, 1): [%s]', [Paths[length(Paths)]]));
if Paths[length(Paths)] = ';' then
Paths := Paths + instlPath + ';' { don't double up ';' in env(PATH) }
else
Paths := Paths + ';' + instlPath + ';' ;
end;
{ Overwrite (or create if missing) path environment variable }
if RegWriteStringValue(HKEY_CURRENT_USER, EnvironmentKey, 'Path', Paths)
then Log(Format('The [%s] added to PATH: [%s]', [instlPath, Paths]))
else Log(Format('Error while adding the [%s] to PATH: [%s]', [instlPath, Paths]));
end;
procedure EnvRemovePath(instlPath: string);
var
Paths: string;
P, Offset, DelimLen: Integer;
begin
{ Skip if registry entry not exists }
if not RegQueryStringValue(HKEY_CURRENT_USER, EnvironmentKey, 'Path', Paths) then
exit;
P := 1;
{ Remove all occurences of instlPath to fix issue created by old installer }
while P > 0 do
begin
{ Skip if string not found in path }
DelimLen := 1; { Length(';') }
P := Pos(';' + Uppercase(instlPath) + ';', ';' + Uppercase(Paths) + ';');
if P = 0 then
begin
{ perhaps instlPath lives in Paths, but terminated by '\;' }
DelimLen := 2; { Length('\;') }
P := Pos(';' + Uppercase(instlPath) + '\;', ';' + Uppercase(Paths) + ';');
if P = 0 then exit;
end;
{ Decide where to start string subset in Delete() operation. }
if P = 1 then
Offset := 0
else
Offset := 1;
{ Update path variable }
Delete(Paths, P - Offset, Length(instlPath) + DelimLen);
{ Overwrite path environment variable }
if RegWriteStringValue(HKEY_CURRENT_USER, EnvironmentKey, 'Path', Paths)
then Log(Format('The [%s] removed from PATH: [%s]', [instlPath, Paths]))
else Log(Format('Error while removing the [%s] from PATH: [%s]', [instlPath, Paths]));
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if (CurStep = ssPostInstall)
then EnvAddPath(ExpandConstant('{app}') +'\cli');
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usPostUninstall
then EnvRemovePath(ExpandConstant('{app}') +'\cli');
end;
Binary file removed win/psvince.dll
Binary file not shown.

0 comments on commit 045f9a4

Please sign in to comment.