implement Linux updating
This commit is contained in:
parent
efdd47a63d
commit
99f610edf9
2 changed files with 70 additions and 22 deletions
|
|
@ -62,7 +62,7 @@ void UpdateController::checkForUpdates()
|
||||||
|
|
||||||
for (auto asset : assets) {
|
for (auto asset : assets) {
|
||||||
QJsonObject assetObject = asset.toObject();
|
QJsonObject assetObject = asset.toObject();
|
||||||
if (assetObject.value("name").toString().contains(".tar.gz")) {
|
if (assetObject.value("name").toString().contains(".tar.zip")) {
|
||||||
m_downloadUrl = assetObject.value("browser_download_url").toString();
|
m_downloadUrl = assetObject.value("browser_download_url").toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -108,27 +108,12 @@ void UpdateController::runInstaller()
|
||||||
if (file.open(QIODevice::WriteOnly)) {
|
if (file.open(QIODevice::WriteOnly)) {
|
||||||
file.write(reply->readAll());
|
file.write(reply->readAll());
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
QFutureWatcher<int> watcher;
|
|
||||||
QFuture<int> future = QtConcurrent::run([this]() {
|
|
||||||
QString t = installerPath;
|
QString t = installerPath;
|
||||||
QRemoteObjectPendingReply<int> ipcReply = IpcClient::Interface()->installApp(t);
|
auto ipcReply = IpcClient::Interface()->installApp(t);
|
||||||
// QRemoteObjectPendingReply<int> ipcReply = IpcClient::Interface()->mountDmg(t, true);
|
|
||||||
// ipcReply.waitForFinished();
|
|
||||||
// QProcess::execute("/Volumes/AmneziaVPN/AmneziaVPN.app/Contents/MacOS/AmneziaVPN");
|
|
||||||
// ipcReply = IpcClient::Interface()->mountDmg(t, false);
|
|
||||||
ipcReply.waitForFinished();
|
ipcReply.waitForFinished();
|
||||||
return ipcReply.returnValue();
|
int result = ipcReply.returnValue();
|
||||||
});
|
|
||||||
|
|
||||||
QEventLoop wait;
|
// emit errorOccured("");
|
||||||
connect(&watcher, &QFutureWatcher<ErrorCode>::finished, &wait, &QEventLoop::quit);
|
|
||||||
watcher.setFuture(future);
|
|
||||||
wait.exec();
|
|
||||||
|
|
||||||
qDebug() << future.result();
|
|
||||||
|
|
||||||
// emit errorOccured("");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (reply->error() == QNetworkReply::NetworkError::OperationCanceledError
|
if (reply->error() == QNetworkReply::NetworkError::OperationCanceledError
|
||||||
|
|
|
||||||
|
|
@ -381,7 +381,70 @@ int IpcServer::mountDmg(const QString &path, bool mount)
|
||||||
int IpcServer::installApp(const QString &path)
|
int IpcServer::installApp(const QString &path)
|
||||||
{
|
{
|
||||||
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
||||||
return QProcess::execute(QString("sudo dpkg -i %1").arg(path));
|
QProcess process;
|
||||||
|
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
|
||||||
|
QString extractDir = tempDir + "/amnezia_update";
|
||||||
|
|
||||||
|
qDebug() << "Installing app from:" << path;
|
||||||
|
qDebug() << "Using temp directory:" << extractDir;
|
||||||
|
|
||||||
|
// Create extraction directory if it doesn't exist
|
||||||
|
QDir dir(extractDir);
|
||||||
|
if (!dir.exists()) {
|
||||||
|
dir.mkpath(".");
|
||||||
|
qDebug() << "Created extraction directory";
|
||||||
|
}
|
||||||
|
|
||||||
|
// First, extract the zip archive
|
||||||
|
qDebug() << "Extracting ZIP archive...";
|
||||||
|
process.start("unzip", QStringList() << path << "-d" << extractDir);
|
||||||
|
process.waitForFinished();
|
||||||
|
if (process.exitCode() != 0) {
|
||||||
|
qDebug() << "ZIP extraction error:" << process.readAllStandardError();
|
||||||
|
return process.exitCode();
|
||||||
|
}
|
||||||
|
qDebug() << "ZIP archive extracted successfully";
|
||||||
|
|
||||||
|
// Look for tar file in extracted files
|
||||||
|
qDebug() << "Looking for TAR file...";
|
||||||
|
QDirIterator tarIt(extractDir, QStringList() << "*.tar", QDir::Files);
|
||||||
|
if (!tarIt.hasNext()) {
|
||||||
|
qDebug() << "TAR file not found in the extracted archive";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract found tar archive
|
||||||
|
QString tarPath = tarIt.next();
|
||||||
|
qDebug() << "Found TAR file:" << tarPath;
|
||||||
|
qDebug() << "Extracting TAR archive...";
|
||||||
|
|
||||||
|
process.start("tar", QStringList() << "-xf" << tarPath << "-C" << extractDir);
|
||||||
|
process.waitForFinished();
|
||||||
|
if (process.exitCode() != 0) {
|
||||||
|
qDebug() << "TAR extraction error:" << process.readAllStandardError();
|
||||||
|
return process.exitCode();
|
||||||
|
}
|
||||||
|
qDebug() << "TAR archive extracted successfully";
|
||||||
|
|
||||||
|
// Remove tar file as it's no longer needed
|
||||||
|
QFile::remove(tarPath);
|
||||||
|
qDebug() << "Removed temporary TAR file";
|
||||||
|
|
||||||
|
// Find executable file and run it
|
||||||
|
qDebug() << "Looking for executable file...";
|
||||||
|
QDirIterator it(extractDir, QDir::Files | QDir::Executable, QDirIterator::Subdirectories);
|
||||||
|
if (it.hasNext()) {
|
||||||
|
QString execPath = it.next();
|
||||||
|
qDebug() << "Found executable:" << execPath;
|
||||||
|
qDebug() << "Launching installer...";
|
||||||
|
process.start("sudo", QStringList() << execPath);
|
||||||
|
process.waitForFinished();
|
||||||
|
qDebug() << "Installer finished with exit code:" << process.exitCode();
|
||||||
|
return process.exitCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "No executable file found";
|
||||||
|
return -1; // Executable not found
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue