DeviceShell: Don't store a shell script on remote side

Execute a script directly on remote side instead.
Storing it always into /tmp/shell.sh may potentially break
when 2 or more shells are being started for one device at
the same time.

Change-Id: I2b8c94ef531fa4916383355a312421a3a18bfcad
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-06-07 14:23:18 +02:00
parent b82f321c9a
commit ec63e694d8

View File

@@ -349,15 +349,12 @@ bool DeviceShell::start()
bool DeviceShell::installShellScript()
{
const QString installCmd
= QString("echo %1 | base64 -d > /tmp/shell.sh 2>/dev/null && "
"chmod +x /tmp/shell.sh && "
"/tmp/shell.sh || echo ERROR_INSTALL_SCRIPT >&2\n")
.arg(QString::fromLatin1(
QByteArray(r_execScript.begin(), r_execScript.size()).toBase64()));
const QByteArray runScriptCmd = "scriptData=$(echo "
+ QByteArray(r_execScript.begin(), r_execScript.size()).toBase64()
+ " | base64 -d) && /bin/sh -c \"$scriptData\" || echo ERROR_INSTALL_SCRIPT >&2\n";
qCDebug(deviceShellLog) << "Install shell script command:" << installCmd;
m_shellProcess->write(installCmd);
qCDebug(deviceShellLog) << "Install shell script command:" << runScriptCmd;
m_shellProcess->writeRaw(runScriptCmd);
while (m_shellScriptState == State::Unknown) {
if (!m_shellProcess->waitForReadyRead()) {