Skip to content

Commit

Permalink
fix-linux打包脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
da1234cao committed Mar 25, 2023
1 parent ef45876 commit c27e4ca
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 21 deletions.
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ include_directories(${spdlog_SOURCE_DIR}/include)
message("fetch spdlog from gitee instead of github")

# toml:
include(FetchContent)
FetchContent_Declare(
tomlplusplus
GIT_REPOSITORY https://gitee.com/actcwlf/tomlplusplus.git
GIT_TAG v3.1.0
GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
GIT_TAG v3.3.0
)
FetchContent_MakeAvailable(tomlplusplus)
include_directories(${tomlplusplus_SOURCE_DIR}/include)
# set(CPACK_EXCLUDE_FROM_ALL ${CPACK_EXCLUDE_FROM_ALL} ${tomlplusplus_SOURCE_DIR})
message("fetch toml from gitee instead of github")

# json
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz)
Expand Down
6 changes: 3 additions & 3 deletions UI/domain_block_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ set_target_properties(domain_block_client PROPERTIES
WIN32_EXECUTABLE TRUE
)

install(TARGETS domain_block_client
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
# install(TARGETS domain_block_client
# BUNDLE DESTINATION .
# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(domain_block_client)
Expand Down
2 changes: 1 addition & 1 deletion UI/domain_block_client/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ config::config() {
QString orgName = QCoreApplication::organizationName();
m_default_path =
QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) +
"/" + orgName + "/" + appName + ".ini";
"/domain_block" + "/" + appName + ".ini";

// qDebug() << "Copied config file from" << m_default_path;

Expand Down
8 changes: 2 additions & 6 deletions UI/domain_block_client/rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,14 @@ void rules::send_rules() {
qDebug() << serverIp << ":" << serverPort;
socket->connectToHost(QHostAddress(serverIp), serverPort);

// 当服务端接收到完整的json后,会自动断开连接;当连接断开时自动销毁QTcpSocket对象
// 当服务端接收到完整的json后,服务端会自动断开连接;当连接断开时自动销毁QTcpSocket对象
connect(socket, &QTcpSocket::disconnected, &QTcpSocket::deleteLater);

connect(socket, &QTcpSocket::readyRead, [=]() {
QByteArray data = socket->readAll();
qDebug() << "Received data: " << data;
});

connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this,
SLOT(handleError(QAbstractSocket::SocketError)));

// 发送数据
socket->write(rulesJsonString.toUtf8());
}
Expand Down Expand Up @@ -158,8 +155,7 @@ void rules::save_info_to_file() {
QTextStream stream(&rules_file);
for (auto &info : m_rules_info) {
// 获取tuple的最后一个元素有点麻烦,这里直接使用数字
stream << std::get<0>(info) << m_separator << std::get<1>(info)
<< endl;
stream << std::get<0>(info) << m_separator << std::get<1>(info) << endl;
}
rules_file.close();
}
Expand Down
Binary file modified bin/domain_block_client
Binary file not shown.
Binary file modified bin/domain_block_service
Binary file not shown.
18 changes: 13 additions & 5 deletions package/linux/package.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

cmake_minimum_required(VERSION 3.11)

set(CPACK_PACKAGE_DESCRIPTION "domain block service")
Expand All @@ -12,7 +11,6 @@ set(CPACK_PACKAGE_VERSION_PATCH 0)

set(INSTALL_DIR /opt/domain_block)
set(SYSTEMD_DIR /etc/systemd/system/)
set(POST_INSTALL_SCRIPT ${CMAKE_SOURCE_DIR}/linux/package/post_install.sh)

# 服务程序
install(TARGETS domain_block_service RUNTIME DESTINATION ${INSTALL_DIR})
Expand All @@ -24,13 +22,23 @@ install(FILES ${CMAKE_SOURCE_DIR}/linux/domain_block_service.toml DESTINATION $
install(TARGETS domain_block_client RUNTIME DESTINATION ${INSTALL_DIR})
install(FILES ${CMAKE_SOURCE_DIR}/UI/domain_block_client/domain_block_client.ini DESTINATION ${INSTALL_DIR})


# systemctl配置文件
install(FILES ${CMAKE_SOURCE_DIR}/linux/domain_block.service DESTINATION ${SYSTEMD_DIR})

set(CPACK_DEBIAN_PACKAGE_POST_INSTALL_SCRIPT_FILE ${POST_INSTALL_SCRIPT})

set(CPACK_GENERATOR "DEB")

# 安装/卸载前后的执行脚本
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_SOURCE_DIR}/package/linux/postinst;
${CMAKE_SOURCE_DIR}/package/linux/prerm;
${CMAKE_SOURCE_DIR}/package/linux/postrm)

# 程序发布的时候没有携带qt库,需要用户自行安装
set(CPACK_DEBIAN_PACKAGE_DEPENDS "qt5-default")

# 忽略所有路径中包含"toml"的文件
set(CPACK_SOURCE_IGNORE_FILES
/.*toml.*
)

include(CPack)

2 changes: 1 addition & 1 deletion package/linux/postinst.sh → package/linux/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
systemctl daemon-reload
systemctl start domain_block

echo "postinst end.\n"
echo "postinst end."
13 changes: 13 additions & 0 deletions package/linux/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# 获取执行 sudo 命令的用户名
SUDO_USER=$(whoami)

# 删除domain_block_client在家目录里的配置和日志文件
## 当然也有可能用户没有在/home下创建家目录,那就得去/etc/passwd配置文件里面去查找了
rm -rf /home/$SUDO_USER/.config/domain_block

# 删除doma_block_service在/var/log/domain_block里产生的日志文件
rm -rf /var/log/domain_block

echo "postrm end."
7 changes: 7 additions & 0 deletions package/linux/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

# 停止服务-服务配置文件会自动被删除
systemctl stop domain_block
systemctl daemon-reload

echo "prerm end."

0 comments on commit c27e4ca

Please sign in to comment.