From bc07e3d496aaca6fb0086d649ea00e1c6079aafb Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Mon, 20 Sep 2021 20:48:24 +0800 Subject: [PATCH] Add snap packaging (#93) * snapcraft init * update packaging * update packaging * update packaging * update packaging * update packaging * update packaging * snap worked * fix locale warning * polish code * update metainfo * update icon * update icon * update message --- .gitignore | 1 + 3rdparty/qt-unix-signals/CMakeLists.txt | 14 ++++ 3rdparty/qt-unix-signals/LICENCE | 21 +++++ .../qt-unix-signals}/sigwatch.cpp | 0 .../qt-unix-signals}/sigwatch.h | 0 CMakeLists.txt | 2 + GPClient/CMakeLists.txt | 17 +++- GPClient/com.yuezk.qt.gpclient.metainfo.xml | 43 ++++++++++ GPClient/gpclient.h | 2 +- GPClient/main.cpp | 8 ++ GPService/CMakeLists.txt | 15 +++- GPService/gpservice.cpp | 2 +- packaging/rpm/globalprotect-openconnect.spec | 2 +- snap/snapcraft.yaml | 84 +++++++++++++++++++ 14 files changed, 203 insertions(+), 8 deletions(-) create mode 100644 3rdparty/qt-unix-signals/CMakeLists.txt create mode 100644 3rdparty/qt-unix-signals/LICENCE rename {GPService => 3rdparty/qt-unix-signals}/sigwatch.cpp (100%) rename {GPService => 3rdparty/qt-unix-signals}/sigwatch.h (100%) create mode 100644 GPClient/com.yuezk.qt.gpclient.metainfo.xml create mode 100644 snap/snapcraft.yaml diff --git a/.gitignore b/.gitignore index 6257a23..44c2114 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ gpservice *.rpm *.gz +*.snap .DS_Store build-debian build diff --git a/3rdparty/qt-unix-signals/CMakeLists.txt b/3rdparty/qt-unix-signals/CMakeLists.txt new file mode 100644 index 0000000..0745620 --- /dev/null +++ b/3rdparty/qt-unix-signals/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.1.0) + +project(QtSignals LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) + +find_package(Qt5 REQUIRED COMPONENTS Core) + +add_library(QtSignals sigwatch.cpp) +target_include_directories(QtSignals INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(QtSignals Qt5::Core) \ No newline at end of file diff --git a/3rdparty/qt-unix-signals/LICENCE b/3rdparty/qt-unix-signals/LICENCE new file mode 100644 index 0000000..7cee458 --- /dev/null +++ b/3rdparty/qt-unix-signals/LICENCE @@ -0,0 +1,21 @@ +Unix signal watcher for Qt. + +Copyright (C) 2014 Simon Knopp + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/GPService/sigwatch.cpp b/3rdparty/qt-unix-signals/sigwatch.cpp similarity index 100% rename from GPService/sigwatch.cpp rename to 3rdparty/qt-unix-signals/sigwatch.cpp diff --git a/GPService/sigwatch.h b/3rdparty/qt-unix-signals/sigwatch.h similarity index 100% rename from GPService/sigwatch.h rename to 3rdparty/qt-unix-signals/sigwatch.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b4f6095..fce7253 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,5 +22,7 @@ find_package(Qt5 REQUIRED COMPONENTS DBus ) +add_subdirectory(3rdparty/qt-unix-signals) add_subdirectory(GPService) add_subdirectory(GPClient) +add_dependencies(gpclient gpservice) diff --git a/GPClient/CMakeLists.txt b/GPClient/CMakeLists.txt index e149e82..e429632 100644 --- a/GPClient/CMakeLists.txt +++ b/GPClient/CMakeLists.txt @@ -4,7 +4,11 @@ project(GPClient) set(gpclient_GENERATED_SOURCES) -qt5_add_dbus_interface(gpclient_GENERATED_SOURCES ${CMAKE_BINARY_DIR}/com.yuezk.qt.GPService.xml gpserviceinterface) +qt5_add_dbus_interface( + gpclient_GENERATED_SOURCES + ${CMAKE_BINARY_DIR}/com.yuezk.qt.GPService.xml + gpserviceinterface +) add_executable(gpclient cdpcommand.cpp @@ -34,7 +38,13 @@ add_3rdparty( SingleApplication GIT_REPOSITORY https://github.com/itay-grudev/SingleApplication.git GIT_TAG v3.3.0 - CMAKE_ARGS -DQAPPLICATION_CLASS=QApplication + CMAKE_ARGS + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_FIND_ROOT_PATH=${CMAKE_FIND_ROOT_PATH} + -DCMAKE_PREFIX_PATH=$ENV{CMAKE_PREFIX_PATH} + -DCMAKE_INCLUDE_PATH=$ENV{CMAKE_INCLUDE_PATH} + -DCMAKE_LIBRARY_PATH=$ENV{CMAKE_LIBRARY_PATH} + -DQAPPLICATION_CLASS=QApplication ) add_3rdparty( @@ -69,10 +79,13 @@ target_link_libraries(gpclient Qt5::WebEngine Qt5::WebEngineWidgets Qt5::DBus + QtSignals ) target_compile_definitions(gpclient PUBLIC QAPPLICATION_CLASS=QApplication) install(TARGETS gpclient DESTINATION "/usr/bin") +install(FILES com.yuezk.qt.gpclient.metainfo.xml DESTINATION "/usr/share/metainfo") install(FILES com.yuezk.qt.gpclient.desktop DESTINATION "/usr/share/applications") +install(FILES com.yuezk.qt.GPClient.svg DESTINATION "/usr/share/icons/hicolor/scalable/apps") install(FILES com.yuezk.qt.GPClient.svg DESTINATION "/usr/share/pixmaps") diff --git a/GPClient/com.yuezk.qt.gpclient.metainfo.xml b/GPClient/com.yuezk.qt.gpclient.metainfo.xml new file mode 100644 index 0000000..c39df8e --- /dev/null +++ b/GPClient/com.yuezk.qt.gpclient.metainfo.xml @@ -0,0 +1,43 @@ + + + com.yuezk.qt.gpclient + + globalprotect-openconnect + A GlobalProtect VPN client powered by OpenConnect + + CC0-1.0 + AGPL-3.0-or-later + + +

A GlobalProtect VPN client (GUI) for Linux based on OpenConnect and built with Qt5, supports the SAML auth mode.

+
+ + + Network + + + k3vinyue_AT_gmail.com + Kevin Yue + + https://github.com/yuezk/GlobalProtect-openconnect + https://github.com/yuezk/GlobalProtect-openconnect/issues + https://github.com/yuezk/GlobalProtect-openconnect/issues + + + globalprotect + openconnect + vpn + saml + + + com.yuezk.qt.gpclient.desktop + + + https://user-images.githubusercontent.com/3297602/133869036-5c02b0d9-c2d9-4f87-8c81-e44f68cfd6ac.png + + + + /usr/bin/gpclient + com.yuezk.qt.GPService + +
\ No newline at end of file diff --git a/GPClient/gpclient.h b/GPClient/gpclient.h index 690c026..ae2eaf7 100644 --- a/GPClient/gpclient.h +++ b/GPClient/gpclient.h @@ -23,6 +23,7 @@ public: ~GPClient(); void activate(); + void quit(); private slots: void onSettingsButtonClicked(); @@ -97,6 +98,5 @@ private: void setCurrentGateway(const GPGateway gateway); void clearSettings(); - void quit(); }; #endif // GPCLIENT_H diff --git a/GPClient/main.cpp b/GPClient/main.cpp index 68c1a1f..5344847 100644 --- a/GPClient/main.cpp +++ b/GPClient/main.cpp @@ -8,6 +8,7 @@ #include "singleapplication.h" #include "gpclient.h" #include "enhancedwebview.h" +#include "sigwatch.h" #include "version.h" int main(int argc, char *argv[]) @@ -37,5 +38,12 @@ int main(int argc, char *argv[]) QObject::connect(&app, &SingleApplication::instanceStarted, &w, &GPClient::activate); + UnixSignalWatcher sigwatch; + sigwatch.watchForSignal(SIGINT); + sigwatch.watchForSignal(SIGTERM); + sigwatch.watchForSignal(SIGQUIT); + sigwatch.watchForSignal(SIGHUP); + QObject::connect(&sigwatch, &UnixSignalWatcher::unixSignal, &w, &GPClient::quit); + return app.exec(); } diff --git a/GPService/CMakeLists.txt b/GPService/CMakeLists.txt index c7205c3..8786f8e 100644 --- a/GPService/CMakeLists.txt +++ b/GPService/CMakeLists.txt @@ -5,7 +5,10 @@ project(GPService) set(gpservice_GENERATED_SOURCES) # generate the dbus xml definition -qt5_generate_dbus_interface(gpservice.h ${CMAKE_BINARY_DIR}/com.yuezk.qt.GPService.xml) +qt5_generate_dbus_interface( + gpservice.h + ${CMAKE_BINARY_DIR}/com.yuezk.qt.GPService.xml +) # generate dbus adaptor qt5_add_dbus_adaptor( @@ -18,7 +21,6 @@ qt5_add_dbus_adaptor( add_executable(gpservice gpservice.cpp main.cpp - sigwatch.cpp ${gpservice_GENERATED_SOURCES} ) @@ -26,7 +28,13 @@ add_3rdparty( SingleApplication GIT_REPOSITORY https://github.com/itay-grudev/SingleApplication.git GIT_TAG v3.3.0 - CMAKE_ARGS -DQAPPLICATION_CLASS=QCoreApplication + CMAKE_ARGS + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_FIND_ROOT_PATH=${CMAKE_FIND_ROOT_PATH} + -DCMAKE_PREFIX_PATH=$ENV{CMAKE_PREFIX_PATH} + -DCMAKE_INCLUDE_PATH=$ENV{CMAKE_INCLUDE_PATH} + -DCMAKE_LIBRARY_PATH=$ENV{CMAKE_LIBRARY_PATH} + -DQAPPLICATION_CLASS=QCoreApplication ) ExternalProject_Get_Property(SingleApplication-${PROJECT_NAME} SOURCE_DIR BINARY_DIR) @@ -47,6 +55,7 @@ target_link_libraries(gpservice Qt5::Core Qt5::Network Qt5::DBus + QtSignals ) target_compile_definitions(gpservice PUBLIC QAPPLICATION_CLASS=QCoreApplication) diff --git a/GPService/gpservice.cpp b/GPService/gpservice.cpp index 7d0034b..6fd2e24 100644 --- a/GPService/gpservice.cpp +++ b/GPService/gpservice.cpp @@ -139,7 +139,7 @@ bool GPService::isValidVersion(QString &bin) { QString majorVersion = match.captured(1); if (majorVersion.toInt() < 8) { - emit error("The OpenConnect version must greater than v8.0.0, but got " + fullVersion); + emit error("The OpenConnect version must greater than v8.0.0, got " + fullVersion); return false; } } else { diff --git a/packaging/rpm/globalprotect-openconnect.spec b/packaging/rpm/globalprotect-openconnect.spec index 26f795f..56e5e7e 100644 --- a/packaging/rpm/globalprotect-openconnect.spec +++ b/packaging/rpm/globalprotect-openconnect.spec @@ -1,7 +1,7 @@ Name: globalprotect-openconnect Version: 1.3.0+SNAPSHOT20210829120923 Release: 1 -Summary: A GlobalProtect VPN client +Summary: A GlobalProtect VPN client powered by OpenConnect License: GPLv3 URL: https://github.com/yuezk/GlobalProtect-openconnect diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 0000000..6355cf0 --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,84 @@ +name: globalprotect-openconnect +base: core18 +version: 'test' +grade: devel +confinement: devmode # use 'strict' once you have the right plugs and slots +compression: lzo + +contact: k3vinyue@gmail.com +donation: https://www.buymeacoffee.com/yuezk +issues: https://github.com/yuezk/GlobalProtect-openconnect/issues +source-code: https://github.com/yuezk/GlobalProtect-openconnect +website: https://github.com/yuezk/GlobalProtect-openconnect +license: GPL-3.0 + +adopt-info: application + +package-repositories: + - type: apt + ppa: dwmw2/openconnect + +layout: + /usr/local/sbin: + bind: $SNAP/usr/sbin + /usr/share/vpnc-scripts: + bind: $SNAP/usr/share/vpnc-scripts + /usr/share/locale: + bind: $SNAP/usr/share/locale + +slots: + gpservice-slot: + interface: dbus + bus: system + name: com.yuezk.qt.GPService + +plugs: + gpservice-plug: + interface: dbus + bus: system + name: com.yuezk.qt.GPService + +apps: + gpservice: + daemon: simple + command: usr/bin/gpservice + command-chain: + - snap/command-chain/desktop-launch + environment: + LC_ALL: en_US.UTF-8 + LANG: en_US.UTF-8 + plugs: + - network + slots: + - gpservice-slot + + gpclient: + common-id: com.yuezk.qt.gpclient + command: usr/bin/gpclient + desktop: usr/share/applications/com.yuezk.qt.gpclient.desktop + extensions: + - kde-neon + plugs: + - desktop + - desktop-legacy + - wayland + - unity7 + - x11 + - network + - gpservice-plug + +parts: + application: + parse-info: + - usr/share/metainfo/com.yuezk.qt.gpclient.metainfo.xml + plugin: cmake + source: . + build-packages: + - libglu1-mesa-dev + build-snaps: + - kde-frameworks-5-core18-sdk + stage-packages: + - openconnect + - libatm1 + configflags: + - -DCMAKE_BUILD_TYPE=Release \ No newline at end of file