Skip to content

Commit

Permalink
feat: uab installation add authentication
Browse files Browse the repository at this point in the history
Linglong's backend DBus interface is unstable,
may change frequently in the near future.
We currently choose the cli interface, use the
DBus interface in the future.

Log: UAB installation add authentication.
Task: https://pms.uniontech.com/story-view-36033.html
Influence: uab-package
  • Loading branch information
rb-union committed Nov 28, 2024
1 parent a1ecff6 commit 20e8bbe
Show file tree
Hide file tree
Showing 17 changed files with 516 additions and 696 deletions.
32 changes: 17 additions & 15 deletions src/AptInstallDepend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
# SPDX-FileCopyrightText: 2022 - 2024 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: CC0-1.0

cmake_minimum_required(VERSION 3.13)

if (NOT DEFINED VERSION)
if(NOT DEFINED VERSION)
set(VERSION 5.3.9)
endif ()
endif()

project(AptInstallDepend)
set (EXE_NAME deepin-deb-installer-dependsInstall)
set(EXE_NAME deepin-deb-installer-dependsInstall)
set(LINK_LIBS
Qt5::Core
)
Expand All @@ -19,31 +19,33 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

#安全测试加固编译参数
# 安全测试加固编译参数
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -z relro -z now -z noexecstack -pie")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -z relro -z now -z noexecstack -pie")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all")

#add process directories
string(REGEX REPLACE "(.*)/(.*)" "\\1" PROJECT_INIT_PATH ${PROJECT_SOURCE_DIR})
# add process directories
string(REGEX REPLACE "(.*)/(.*)" "\\1" PROJECT_INIT_PATH ${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_INIT_PATH}/deb-installer/process)

file(GLOB_RECURSE AUTH_CPP_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h ${CMAKE_CURRENT_LIST_DIR}/*.cpp ${PROJECT_INIT_PATH}/deb-installer/process/*.cpp)
add_executable (${EXE_NAME}
file(GLOB_RECURSE AUTH_CPP_FILES
${CMAKE_CURRENT_LIST_DIR}/*.h
${CMAKE_CURRENT_LIST_DIR}/*.cpp
${PROJECT_INIT_PATH}/deb-installer/process/*.cpp)
add_executable(${EXE_NAME}
${AUTH_CPP_FILES}
)

# Find the library
find_package(PkgConfig REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5 REQUIRED Core Gui Widgets)
set(CMAKE_INSTALL_PREFIX /usr)

# Install files
install(TARGETS ${EXE_NAME} DESTINATION bin)
target_link_libraries(${EXE_NAME} ${LINK_LIBS} )
target_link_libraries(${EXE_NAME} ${LINK_LIBS})
target_link_libraries(${EXE_NAME}
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::Gui)
)
54 changes: 50 additions & 4 deletions src/AptInstallDepend/installDebThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ static const QString kParamInstallWine = "install_wine";
static const QString kParamInstallConfig = "install_config";
static const QString kParamInstallComaptible = "install_compatible";
static const QString kParamInstallImmutable = "install_immutable";
static const QString kParamInstallUab = "uab";

static const QString kInstall = "install";
static const QString kRemove = "remove";
Expand Down Expand Up @@ -38,6 +39,9 @@ InstallDebThread::InstallDebThread()

connect(m_proc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onFinished(int, QProcess::ExitStatus)));
connect(m_proc, SIGNAL(readyReadStandardOutput()), this, SLOT(onReadoutput()));
connect(m_proc, &KProcess::readyReadStandardError, this, [this](){
qWarning() << m_proc->readAllStandardError();
});
}

InstallDebThread::~InstallDebThread()
Expand All @@ -52,11 +56,12 @@ void InstallDebThread::setParam(const QStringList &arguments)
return;
}

// normal command;
// normal command
static QMap<QString, Command> kParamMap{{kParamInstallWine, InstallWine},
{kParamInstallConfig, InstallConfig},
{kParamInstallComaptible, Compatible},
{kParamInstallImmutable, Immutable},
{kParamInstallUab, LinglongUab},
{kInstall, Install},
{kRemove, Remove}};

Expand Down Expand Up @@ -149,6 +154,8 @@ void InstallDebThread::run()
} else if (m_cmds.testFlag(InstallConfig)) {
// InstallConfig must last, Compatible and Immutable maybe set InstallConfig too.
installConfig();
} else if (m_cmds.testFlag(LinglongUab)) {
uabProcessCli();
}
}

Expand All @@ -167,9 +174,7 @@ void InstallDebThread::installWine()
// On immutable system: --fix-missing not support, apt command will transport to deepin-immutable-ctl
system("echo 'libpam-runtime libpam-runtime/override boolean false' | debconf-set-selections");
system("echo 'libc6 libraries/restart-without-asking boolean true' | sudo debconf-set-selections\n");
m_proc->setProgram("sudo",
QStringList() << "apt-get"
<< "install" << m_listParam << "-y");
m_proc->setProgram("apt-get", QStringList() << "install" << m_listParam << "-y");
m_proc->start();
m_proc->waitForFinished(-1);
m_proc->close();
Expand Down Expand Up @@ -322,6 +327,47 @@ void InstallDebThread::immutableProcess()
}
}

/**
@brief Install / unisntall uab package in Linglong.
@todo Linglong's backend DBus interface is unstable, may change frequently in the near future.
We currently choose the cli interface, use the DBus interface in the future.
*/
void InstallDebThread::uabProcessCli()
{
if (m_listParam.isEmpty()) {
return;
}
// The Linglong params
static const QString kUabBin = "ll-cli";
static const QString kUabInstall = "install";
static const QString kUabUninstall = "uninstall";
static const QString kUabJson = "--json";
static const QString kUabForce = "--force"; // Force install the application
static const QString kUabPass = "-y"; // Automatically answer yes to all questions

QStringList params;

if (m_cmds.testFlag(Install)) {
// e.g.: ll-cli install --json --force -y [uab file]
params << kUabInstall << kUabJson << kUabForce << kUabPass << m_listParam.first();

} else if (m_cmds.testFlag(Remove)) {
// e.g.: ll-cli uninstall --json [id/version]
params << kUabUninstall << kUabJson << m_listParam.first();

} else {
return;
}

m_proc->setProgram(kUabBin, params);
qInfo() << "Exec:" << qPrintable(m_proc->program().join(' '));

m_proc->start();
m_proc->waitForFinished(-1);
m_proc->close();
}

/**
* @brief PackagesManager::SymbolicLink 创建软连接
* @param previousName 原始路径
Expand Down
8 changes: 5 additions & 3 deletions src/AptInstallDepend/installDebThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ class InstallDebThread : public QThread
InstallWine = 1 << 3,
InstallConfig = 1 << 4, // DebConf install

Compatible = 1 << 5, // compatible mode
Immutable = 1 << 6, // immutable system
Compatible = 1 << 5, // compatible mode
Immutable = 1 << 6, // immutable system
LinglongUab = 1 << 7, // linglong app(lingyaps)
};
Q_DECLARE_FLAGS(Commands, Command)
Q_FLAG(Commands);
Q_FLAG(Commands)

InstallDebThread();
virtual ~InstallDebThread();
Expand All @@ -53,6 +54,7 @@ public slots:
void installConfig();
void compatibleProcess();
void immutableProcess();
void uabProcessCli();

// 使用软连接方式解决文件路径中存在空格的问题。
QString SymbolicLink(const QString &previousName, const QString &packageName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Konsole {
class Pty;
}; // namespace Konsole
} // namespace Konsole

namespace Compatible {

Expand Down
2 changes: 1 addition & 1 deletion src/deb-installer/immutable/immutable_process_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Konsole {
class Pty;
}; // namespace Konsole
} // namespace Konsole

namespace Immutable {

Expand Down
Loading

0 comments on commit 20e8bbe

Please sign in to comment.