Move installer running to client side for Ubuntu
This commit is contained in:
parent
2029c108e5
commit
8de7ad6b41
5 changed files with 186 additions and 35 deletions
44
client/client_scripts/linux_installer.sh
Normal file
44
client/client_scripts/linux_installer.sh
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#!/bin/bash
|
||||
|
||||
EXTRACT_DIR="$1"
|
||||
INSTALLER_PATH="$2"
|
||||
|
||||
# Create and clean extract directory
|
||||
rm -rf "$EXTRACT_DIR"
|
||||
mkdir -p "$EXTRACT_DIR"
|
||||
|
||||
# Extract ZIP archive
|
||||
unzip "$INSTALLER_PATH" -d "$EXTRACT_DIR"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo 'Failed to extract ZIP archive'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Find and extract TAR archive
|
||||
TAR_FILE=$(find "$EXTRACT_DIR" -name '*.tar' -type f)
|
||||
if [ -z "$TAR_FILE" ]; then
|
||||
echo 'TAR file not found'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
tar -xf "$TAR_FILE" -C "$EXTRACT_DIR"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo 'Failed to extract TAR archive'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f "$TAR_FILE"
|
||||
|
||||
# Find and run installer
|
||||
INSTALLER=$(find "$EXTRACT_DIR" -type f -executable)
|
||||
if [ -z "$INSTALLER" ]; then
|
||||
echo 'Installer not found'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
"$INSTALLER"
|
||||
EXIT_CODE=$?
|
||||
|
||||
# Cleanup
|
||||
rm -rf "$EXTRACT_DIR"
|
||||
exit $EXIT_CODE
|
||||
|
|
@ -54,6 +54,14 @@ QString amnezia::scriptName(ProtocolScriptType type)
|
|||
}
|
||||
}
|
||||
|
||||
QString amnezia::scriptName(ClientScriptType type)
|
||||
{
|
||||
switch (type) {
|
||||
case ClientScriptType::linux_installer: return QLatin1String("linux_installer.sh");
|
||||
default: return QString();
|
||||
}
|
||||
}
|
||||
|
||||
QString amnezia::scriptData(amnezia::SharedScriptType type)
|
||||
{
|
||||
QString fileName = QString(":/server_scripts/%1").arg(amnezia::scriptName(type));
|
||||
|
|
@ -81,3 +89,19 @@ QString amnezia::scriptData(amnezia::ProtocolScriptType type, DockerContainer co
|
|||
data.replace("\r", "");
|
||||
return data;
|
||||
}
|
||||
|
||||
QString amnezia::scriptData(ClientScriptType type)
|
||||
{
|
||||
QString fileName = QString(":/client_scripts/%1").arg(amnezia::scriptName(type));
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qDebug() << "Warning: script missing" << fileName;
|
||||
return "";
|
||||
}
|
||||
QByteArray data = file.readAll();
|
||||
if (data.isEmpty()) {
|
||||
qDebug() << "Warning: script is empty" << fileName;
|
||||
}
|
||||
data.replace("\r", "");
|
||||
return data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
#ifndef SCRIPTS_REGISTRY_H
|
||||
#define SCRIPTS_REGISTRY_H
|
||||
|
||||
#include <QLatin1String>
|
||||
#include "core/defs.h"
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/defs.h"
|
||||
#include <QLatin1String>
|
||||
|
||||
namespace amnezia {
|
||||
namespace amnezia
|
||||
{
|
||||
|
||||
enum SharedScriptType {
|
||||
// General scripts
|
||||
|
|
@ -19,6 +20,7 @@ enum SharedScriptType {
|
|||
check_server_is_busy,
|
||||
check_user_in_sudo
|
||||
};
|
||||
|
||||
enum ProtocolScriptType {
|
||||
// Protocol scripts
|
||||
dockerfile,
|
||||
|
|
@ -31,14 +33,20 @@ enum ProtocolScriptType {
|
|||
xray_template
|
||||
};
|
||||
|
||||
enum ClientScriptType {
|
||||
// Client-side scripts
|
||||
linux_installer
|
||||
};
|
||||
|
||||
QString scriptFolder(DockerContainer container);
|
||||
|
||||
QString scriptName(SharedScriptType type);
|
||||
QString scriptName(ProtocolScriptType type);
|
||||
QString scriptName(ClientScriptType type);
|
||||
|
||||
QString scriptData(SharedScriptType type);
|
||||
QString scriptData(ProtocolScriptType type, DockerContainer container);
|
||||
QString scriptData(ClientScriptType type);
|
||||
}
|
||||
|
||||
#endif // SCRIPTS_REGISTRY_H
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "amnezia_application.h"
|
||||
#include "core/errorstrings.h"
|
||||
#include "core/scripts_registry.h"
|
||||
#include "version.h"
|
||||
|
||||
namespace
|
||||
|
|
@ -121,10 +122,14 @@ void UpdateController::runInstaller()
|
|||
file.write(reply->readAll());
|
||||
file.close();
|
||||
QString t = installerPath;
|
||||
auto ipcReply = IpcClient::Interface()->installApp(t);
|
||||
ipcReply.waitForFinished();
|
||||
int result = ipcReply.returnValue();
|
||||
|
||||
#if defined(Q_OS_WINDOWS)
|
||||
runWindowsInstaller(t);
|
||||
#elif defined(Q_OS_MACOS)
|
||||
runMacInstaller(t);
|
||||
#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
||||
runLinuxInstaller(t);
|
||||
#endif
|
||||
// emit errorOccured("");
|
||||
}
|
||||
} else {
|
||||
|
|
@ -140,7 +145,69 @@ void UpdateController::runInstaller()
|
|||
qDebug() << errorString(ErrorCode::ApiConfigDownloadError);
|
||||
}
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
#if defined(Q_OS_WINDOWS)
|
||||
int UpdateController::runWindowsInstaller(const QString &installerPath)
|
||||
{
|
||||
qDebug() << "Windows installer path:" << installerPath;
|
||||
// TODO: Implement Windows installation logic
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_MACOS)
|
||||
int UpdateController::runMacInstaller(const QString &installerPath)
|
||||
{
|
||||
qDebug() << "macOS installer path:" << installerPath;
|
||||
// TODO: Implement macOS installation logic
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
||||
int UpdateController::runLinuxInstaller(const QString &installerPath)
|
||||
{
|
||||
// Create temporary directory for extraction
|
||||
QTemporaryDir extractDir;
|
||||
extractDir.setAutoRemove(false);
|
||||
if (!extractDir.isValid()) {
|
||||
qDebug() << "Failed to create temporary directory";
|
||||
return -1;
|
||||
}
|
||||
qDebug() << "Temporary directory created:" << extractDir.path();
|
||||
|
||||
// Create script file in the temporary directory
|
||||
QString scriptPath = extractDir.path() + "/installer.sh";
|
||||
QFile scriptFile(scriptPath);
|
||||
if (!scriptFile.open(QIODevice::WriteOnly)) {
|
||||
qDebug() << "Failed to create script file";
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get script content from registry
|
||||
QString scriptContent = amnezia::scriptData(amnezia::ClientScriptType::linux_installer);
|
||||
scriptFile.write(scriptContent.toUtf8());
|
||||
scriptFile.close();
|
||||
qDebug() << "Script file created:" << scriptPath;
|
||||
|
||||
// Make script executable
|
||||
QFile::setPermissions(scriptPath, QFile::permissions(scriptPath) | QFile::ExeUser);
|
||||
|
||||
// Start detached process
|
||||
qint64 pid;
|
||||
bool success = QProcess::startDetached(
|
||||
"/bin/bash", QStringList() << scriptPath << extractDir.path() << installerPath, extractDir.path(), &pid);
|
||||
|
||||
if (success) {
|
||||
qDebug() << "Installation process started with PID:" << pid;
|
||||
} else {
|
||||
qDebug() << "Failed to start installation process";
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -30,6 +30,14 @@ private:
|
|||
QString m_version;
|
||||
QString m_releaseDate;
|
||||
QString m_downloadUrl;
|
||||
|
||||
#if defined(Q_OS_WINDOWS)
|
||||
int runWindowsInstaller(const QString &installerPath);
|
||||
#elif defined(Q_OS_MACOS)
|
||||
int runMacInstaller(const QString &installerPath);
|
||||
#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
||||
int runLinuxInstaller(const QString &installerPath);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // UPDATECONTROLLER_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue