diff --git a/CMakeLists.txt b/CMakeLists.txt index 3537e49..e56ecb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/UI/domain_block_client/CMakeLists.txt b/UI/domain_block_client/CMakeLists.txt index 9dae07d..d2cbc9e 100644 --- a/UI/domain_block_client/CMakeLists.txt +++ b/UI/domain_block_client/CMakeLists.txt @@ -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) diff --git a/UI/domain_block_client/config.cpp b/UI/domain_block_client/config.cpp index 53e29ce..33d72da 100644 --- a/UI/domain_block_client/config.cpp +++ b/UI/domain_block_client/config.cpp @@ -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; diff --git a/UI/domain_block_client/rules.cpp b/UI/domain_block_client/rules.cpp index c8c0944..456d24f 100644 --- a/UI/domain_block_client/rules.cpp +++ b/UI/domain_block_client/rules.cpp @@ -113,7 +113,7 @@ 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, [=]() { @@ -121,9 +121,6 @@ void rules::send_rules() { qDebug() << "Received data: " << data; }); - connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, - SLOT(handleError(QAbstractSocket::SocketError))); - // 发送数据 socket->write(rulesJsonString.toUtf8()); } @@ -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(); } diff --git a/bin/domain_block_client b/bin/domain_block_client index 9bc983f..aea1dfe 100755 Binary files a/bin/domain_block_client and b/bin/domain_block_client differ diff --git a/bin/domain_block_service b/bin/domain_block_service index ef2f8d0..cf1d872 100755 Binary files a/bin/domain_block_service and b/bin/domain_block_service differ diff --git a/package/linux/package.cmake b/package/linux/package.cmake index 3d02c22..3ab7ad8 100644 --- a/package/linux/package.cmake +++ b/package/linux/package.cmake @@ -1,4 +1,3 @@ - cmake_minimum_required(VERSION 3.11) set(CPACK_PACKAGE_DESCRIPTION "domain block service") @@ -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}) @@ -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) diff --git a/package/linux/postinst.sh b/package/linux/postinst similarity index 77% rename from package/linux/postinst.sh rename to package/linux/postinst index def6ddc..2d3b20b 100755 --- a/package/linux/postinst.sh +++ b/package/linux/postinst @@ -3,4 +3,4 @@ systemctl daemon-reload systemctl start domain_block -echo "postinst end.\n" \ No newline at end of file +echo "postinst end." \ No newline at end of file diff --git a/package/linux/postrm b/package/linux/postrm new file mode 100755 index 0000000..a9b7239 --- /dev/null +++ b/package/linux/postrm @@ -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." \ No newline at end of file diff --git a/package/linux/prerm b/package/linux/prerm new file mode 100644 index 0000000..22625be --- /dev/null +++ b/package/linux/prerm @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# 停止服务-服务配置文件会自动被删除 +systemctl stop domain_block +systemctl daemon-reload + +echo "prerm end." \ No newline at end of file