diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 14e13b0..2d720e6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,29 +2,34 @@ name: Build on: push: - branches: [ master ] + branches: + - master + - dev + paths-ignore: + - LICENSE + - "*.md" + - .vscode pull_request: - branches: [ master ] + branches: + - master + - dev + paths-ignore: + - LICENSE + - "*.md" + - .vscode workflow_dispatch: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 steps: - - name: Install Qt - uses: jurplel/install-qt-action@v2 - with: - version: 5.12.11 - modules: 'qtwebengine qtwebsockets' - # Checkout repository and submodules - uses: actions/checkout@v2 with: submodules: recursive - - name: Build + - name: Build & Install run: | - qmake CONFIG+=release - make + ./scripts/install-ubuntu.sh \ No newline at end of file diff --git a/.gitignore b/.gitignore index 42def65..44c2114 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,9 @@ gpservice *.snap .DS_Store build-debian -packaging/snap/local +build + +.cmake # Auto generated DBus files *_adaptor.cpp diff --git a/.gitmodules b/.gitmodules index a95cc4c..45a9506 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,7 @@ [submodule "singleapplication"] - path = singleapplication + path = 3rdparty/SingleApplication url = https://github.com/itay-grudev/SingleApplication.git [submodule "plog"] - path = plog + path = 3rdparty/plog url = https://github.com/SergiusTheBest/plog.git diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..fab9481 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,23 @@ +{ + "files.associations": { + "qregularexpression": "cpp", + "qfileinfo": "cpp", + "qregularexpressionmatch": "cpp", + "qdatetime": "cpp", + "qprocess": "cpp", + "qobject": "cpp", + "qstandardpaths": "cpp", + "qmainwindow": "cpp", + "qsystemtrayicon": "cpp", + "qpushbutton": "cpp", + "qmenu": "cpp", + "qjsondocument": "cpp", + "qnetworkaccessmanager": "cpp", + "qwebengineview": "cpp", + "qprocessenvironment": "cpp", + "qnetworkreply": "cpp", + "qicon": "cpp", + "qsslsocket": "cpp", + "qapplication": "cpp" + } +} \ No newline at end of file diff --git a/3rdparty/SingleApplication b/3rdparty/SingleApplication new file mode 160000 index 0000000..bdbb09b --- /dev/null +++ b/3rdparty/SingleApplication @@ -0,0 +1 @@ +Subproject commit bdbb09b5f21ebea4cd7dfb43b29114a94e04a3a1 diff --git a/3rdparty/plog b/3rdparty/plog new file mode 160000 index 0000000..f4c22b0 --- /dev/null +++ b/3rdparty/plog @@ -0,0 +1 @@ +Subproject commit f4c22b03d5d3aa753cca8e716636ac4eb29b0917 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b4f6095 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.10.0) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +file(READ "VERSION" ver) +project(GlobalProtect-openconnect VERSION ${ver} LANGUAGES CXX) + +configure_file(version.h.in version.h) + +find_package(Qt5 REQUIRED COMPONENTS + Core + Widgets + Network + WebSockets + WebEngine + WebEngineWidgets + DBus +) + +add_subdirectory(GPService) +add_subdirectory(GPClient) diff --git a/GPClient/CMakeLists.txt b/GPClient/CMakeLists.txt new file mode 100644 index 0000000..e149e82 --- /dev/null +++ b/GPClient/CMakeLists.txt @@ -0,0 +1,78 @@ +include("${CMAKE_SOURCE_DIR}/cmake/Add3rdParty.cmake") + +project(GPClient) + +set(gpclient_GENERATED_SOURCES) + +qt5_add_dbus_interface(gpclient_GENERATED_SOURCES ${CMAKE_BINARY_DIR}/com.yuezk.qt.GPService.xml gpserviceinterface) + +add_executable(gpclient + cdpcommand.cpp + cdpcommandmanager.cpp + enhancedwebview.cpp + gatewayauthenticator.cpp + gatewayauthenticatorparams.cpp + gpgateway.cpp + gphelper.cpp + loginparams.cpp + main.cpp + normalloginwindow.cpp + portalauthenticator.cpp + portalconfigresponse.cpp + preloginresponse.cpp + samlloginwindow.cpp + gpclient.cpp + settingsdialog.cpp + gpclient.ui + normalloginwindow.ui + settingsdialog.ui + resources.qrc + ${gpclient_GENERATED_SOURCES} +) + +add_3rdparty( + SingleApplication + GIT_REPOSITORY https://github.com/itay-grudev/SingleApplication.git + GIT_TAG v3.3.0 + CMAKE_ARGS -DQAPPLICATION_CLASS=QApplication +) + +add_3rdparty( + plog + GIT_REPOSITORY https://github.com/SergiusTheBest/plog.git + GIT_TAG 1.1.5 + CMAKE_ARGS -DPLOG_BUILD_SAMPLES=OFF +) + +ExternalProject_Get_Property(SingleApplication-${PROJECT_NAME} SOURCE_DIR BINARY_DIR) +set(SingleApplication_INCLUDE_DIR ${SOURCE_DIR}) +set(SingleApplication_LIBRARY ${BINARY_DIR}/libSingleApplication.a) + +ExternalProject_Get_Property(plog-${PROJECT_NAME} SOURCE_DIR) +set(plog_INCLUDE_DIR "${SOURCE_DIR}/include") + +add_dependencies(gpclient SingleApplication-${PROJECT_NAME} plog-${PROJECT_NAME}) + +target_include_directories(gpclient PRIVATE + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${SingleApplication_INCLUDE_DIR} + ${plog_INCLUDE_DIR} +) + +target_link_libraries(gpclient + ${SingleApplication_LIBRARY} + Qt5::Widgets + Qt5::Network + Qt5::WebSockets + Qt5::WebEngine + Qt5::WebEngineWidgets + Qt5::DBus +) + +target_compile_definitions(gpclient PUBLIC QAPPLICATION_CLASS=QApplication) + +install(TARGETS gpclient DESTINATION "/usr/bin") +install(FILES com.yuezk.qt.gpclient.desktop DESTINATION "/usr/share/applications") +install(FILES com.yuezk.qt.GPClient.svg DESTINATION "/usr/share/pixmaps") diff --git a/GPClient/GPClient.pro b/GPClient/GPClient.pro deleted file mode 100644 index ec6f90b..0000000 --- a/GPClient/GPClient.pro +++ /dev/null @@ -1,83 +0,0 @@ -TARGET = gpclient - -QT += core gui network websockets dbus webenginewidgets - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -CONFIG += c++11 - -include(../singleapplication/singleapplication.pri) -DEFINES += QAPPLICATION_CLASS=QApplication - -# The following define makes your compiler emit warnings if you use -# any Qt feature that has been marked deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -INCLUDEPATH += ../plog/include - -# You can also make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += \ - cdpcommand.cpp \ - cdpcommandmanager.cpp \ - enhancedwebview.cpp \ - gatewayauthenticator.cpp \ - gatewayauthenticatorparams.cpp \ - gpgateway.cpp \ - gphelper.cpp \ - loginparams.cpp \ - main.cpp \ - normalloginwindow.cpp \ - portalauthenticator.cpp \ - portalconfigresponse.cpp \ - preloginresponse.cpp \ - samlloginwindow.cpp \ - gpclient.cpp \ - settingsdialog.cpp - -HEADERS += \ - cdpcommand.h \ - cdpcommandmanager.h \ - enhancedwebview.h \ - gatewayauthenticator.h \ - gatewayauthenticatorparams.h \ - gpgateway.h \ - gphelper.h \ - loginparams.h \ - normalloginwindow.h \ - portalauthenticator.h \ - portalconfigresponse.h \ - preloginresponse.h \ - samlloginwindow.h \ - gpclient.h \ - settingsdialog.h - -FORMS += \ - gpclient.ui \ - normalloginwindow.ui \ - settingsdialog.ui - -DBUS_INTERFACES += ../GPService/gpservice.xml - -# Default rules for deployment. -target.path = /usr/bin -INSTALLS += target - -DISTFILES += \ - com.yuezk.qt.GPClient.svg \ - com.yuezk.qt.gpclient.desktop - -desktop_entry.path = /usr/share/applications/ -desktop_entry.files = com.yuezk.qt.gpclient.desktop - -desktop_icon.path = /usr/share/pixmaps/ -desktop_icon.files = com.yuezk.qt.GPClient.svg - -INSTALLS += desktop_entry desktop_icon - -RESOURCES += \ - resources.qrc diff --git a/GPClient/cdpcommand.cpp b/GPClient/cdpcommand.cpp index 10d3f48..0722aac 100644 --- a/GPClient/cdpcommand.cpp +++ b/GPClient/cdpcommand.cpp @@ -1,8 +1,8 @@ -#include "cdpcommand.h" +#include +#include +#include -#include -#include -#include +#include "cdpcommand.h" CDPCommand::CDPCommand(QObject *parent) : QObject(parent) { diff --git a/GPClient/cdpcommand.h b/GPClient/cdpcommand.h index 75cbdbe..8f37b7b 100644 --- a/GPClient/cdpcommand.h +++ b/GPClient/cdpcommand.h @@ -1,7 +1,7 @@ #ifndef CDPCOMMAND_H #define CDPCOMMAND_H -#include +#include class CDPCommand : public QObject { diff --git a/GPClient/cdpcommandmanager.cpp b/GPClient/cdpcommandmanager.cpp index 9969dbd..e4e20f5 100644 --- a/GPClient/cdpcommandmanager.cpp +++ b/GPClient/cdpcommandmanager.cpp @@ -1,7 +1,8 @@ -#include "cdpcommandmanager.h" -#include +#include #include +#include "cdpcommandmanager.h" + CDPCommandManager::CDPCommandManager(QObject *parent) : QObject(parent) , networkManager(new QNetworkAccessManager) diff --git a/GPClient/cdpcommandmanager.h b/GPClient/cdpcommandmanager.h index 9aefedf..ef1238f 100644 --- a/GPClient/cdpcommandmanager.h +++ b/GPClient/cdpcommandmanager.h @@ -1,11 +1,12 @@ #ifndef CDPCOMMANDMANAGER_H #define CDPCOMMANDMANAGER_H +#include +#include +#include +#include + #include "cdpcommand.h" -#include -#include -#include -#include class CDPCommandManager : public QObject { diff --git a/GPClient/enhancedwebview.cpp b/GPClient/enhancedwebview.cpp index 292c6ff..8ac3ac1 100644 --- a/GPClient/enhancedwebview.cpp +++ b/GPClient/enhancedwebview.cpp @@ -1,9 +1,9 @@ +#include +#include + #include "enhancedwebview.h" #include "cdpcommandmanager.h" -#include -#include - EnhancedWebView::EnhancedWebView(QWidget *parent) : QWebEngineView(parent) , cdp(new CDPCommandManager) diff --git a/GPClient/enhancedwebview.h b/GPClient/enhancedwebview.h index 191364d..163768e 100644 --- a/GPClient/enhancedwebview.h +++ b/GPClient/enhancedwebview.h @@ -1,9 +1,10 @@ #ifndef ENHANCEDWEBVIEW_H #define ENHANCEDWEBVIEW_H -#include "cdpcommandmanager.h" #include +#include "cdpcommandmanager.h" + #define ENV_CDP_PORT "QTWEBENGINE_REMOTE_DEBUGGING" class EnhancedWebView : public QWebEngineView diff --git a/GPClient/gatewayauthenticator.cpp b/GPClient/gatewayauthenticator.cpp index 894a4ea..60e98de 100644 --- a/GPClient/gatewayauthenticator.cpp +++ b/GPClient/gatewayauthenticator.cpp @@ -1,11 +1,11 @@ +#include +#include + #include "gatewayauthenticator.h" #include "gphelper.h" #include "loginparams.h" #include "preloginresponse.h" -#include -#include - using namespace gpclient::helper; GatewayAuthenticator::GatewayAuthenticator(const QString& gateway, const GatewayAuthenticatorParams params) diff --git a/GPClient/gatewayauthenticator.h b/GPClient/gatewayauthenticator.h index 97f091c..c150a88 100644 --- a/GPClient/gatewayauthenticator.h +++ b/GPClient/gatewayauthenticator.h @@ -1,10 +1,11 @@ #ifndef GATEWAYAUTHENTICATOR_H #define GATEWAYAUTHENTICATOR_H +#include + #include "normalloginwindow.h" #include "loginparams.h" #include "gatewayauthenticatorparams.h" -#include class GatewayAuthenticator : public QObject { diff --git a/GPClient/gatewayauthenticatorparams.h b/GPClient/gatewayauthenticatorparams.h index cb25eae..72d9176 100644 --- a/GPClient/gatewayauthenticatorparams.h +++ b/GPClient/gatewayauthenticatorparams.h @@ -1,7 +1,8 @@ #ifndef GATEWAYAUTHENTICATORPARAMS_H #define GATEWAYAUTHENTICATORPARAMS_H -#include +#include + #include "portalconfigresponse.h" class GatewayAuthenticatorParams diff --git a/GPClient/gpclient.cpp b/GPClient/gpclient.cpp index 966f4bf..76cfd58 100644 --- a/GPClient/gpclient.cpp +++ b/GPClient/gpclient.cpp @@ -1,3 +1,6 @@ +#include +#include + #include "gpclient.h" #include "gphelper.h" #include "ui_gpclient.h" @@ -6,9 +9,6 @@ #include "settingsdialog.h" #include "gatewayauthenticatorparams.h" -#include -#include - using namespace gpclient::helper; GPClient::GPClient(QWidget *parent) diff --git a/GPClient/gpclient.h b/GPClient/gpclient.h index 45ca86d..690c026 100644 --- a/GPClient/gpclient.h +++ b/GPClient/gpclient.h @@ -1,15 +1,15 @@ #ifndef GPCLIENT_H #define GPCLIENT_H -#include "gpservice_interface.h" +#include +#include +#include +#include + +#include "gpserviceinterface.h" #include "portalconfigresponse.h" #include "settingsdialog.h" -#include -#include -#include -#include - QT_BEGIN_NAMESPACE namespace Ui { class GPClient; } QT_END_NAMESPACE diff --git a/GPClient/gpgateway.cpp b/GPClient/gpgateway.cpp index 5725925..7b587ed 100644 --- a/GPClient/gpgateway.cpp +++ b/GPClient/gpgateway.cpp @@ -1,8 +1,8 @@ -#include "gpgateway.h" +#include +#include +#include -#include -#include -#include +#include "gpgateway.h" GPGateway::GPGateway() { diff --git a/GPClient/gpgateway.h b/GPClient/gpgateway.h index 0bfb449..d879259 100644 --- a/GPClient/gpgateway.h +++ b/GPClient/gpgateway.h @@ -1,9 +1,9 @@ #ifndef GPGATEWAY_H #define GPGATEWAY_H -#include -#include -#include +#include +#include +#include class GPGateway { diff --git a/GPClient/gphelper.cpp b/GPClient/gphelper.cpp index 4b6b5bd..242992b 100644 --- a/GPClient/gphelper.cpp +++ b/GPClient/gphelper.cpp @@ -1,14 +1,15 @@ -#include "gphelper.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include "gphelper.h" + QNetworkAccessManager* gpclient::helper::networkManager = new QNetworkAccessManager; QNetworkReply* gpclient::helper::createRequest(QString url, QByteArray params) diff --git a/GPClient/gphelper.h b/GPClient/gphelper.h index 66aa63a..fb74899 100644 --- a/GPClient/gphelper.h +++ b/GPClient/gphelper.h @@ -1,16 +1,16 @@ #ifndef GPHELPER_H #define GPHELPER_H +#include +#include +#include +#include +#include +#include + #include "samlloginwindow.h" #include "gpgateway.h" -#include -#include -#include -#include -#include -#include - const QString UA = "PAN GlobalProtect"; diff --git a/GPClient/loginparams.cpp b/GPClient/loginparams.cpp index 54850c9..5b59fe3 100644 --- a/GPClient/loginparams.cpp +++ b/GPClient/loginparams.cpp @@ -1,6 +1,6 @@ -#include "loginparams.h" +#include -#include +#include "loginparams.h" LoginParams::LoginParams(const QString clientos) { diff --git a/GPClient/loginparams.h b/GPClient/loginparams.h index f83bca0..87d3d10 100644 --- a/GPClient/loginparams.h +++ b/GPClient/loginparams.h @@ -1,7 +1,7 @@ #ifndef LOGINPARAMS_H #define LOGINPARAMS_H -#include +#include class LoginParams { diff --git a/GPClient/main.cpp b/GPClient/main.cpp index 97f20f2..2902a0e 100644 --- a/GPClient/main.cpp +++ b/GPClient/main.cpp @@ -1,13 +1,14 @@ -#include "singleapplication.h" -#include "gpclient.h" -#include "enhancedwebview.h" - -#include -#include +#include +#include +#include +#include #include #include -static const QString version = "v1.3.3"; +#include "singleapplication.h" +#include "gpclient.h" +#include "enhancedwebview.h" +#include "version.h" int main(int argc, char *argv[]) { @@ -20,7 +21,7 @@ int main(int argc, char *argv[]) static plog::ColorConsoleAppender consoleAppender; plog::init(plog::debug, logFile.toUtf8()).addAppender(&consoleAppender); - PLOGI << "GlobalProtect started, version: " << version; + PLOGI << "GlobalProtect started, version: " << VERSION; PLOGI << "PATH: " << qgetenv("PATH"); QString port = QString::fromLocal8Bit(qgetenv(ENV_CDP_PORT)); diff --git a/GPClient/normalloginwindow.cpp b/GPClient/normalloginwindow.cpp index a712bee..1626a09 100644 --- a/GPClient/normalloginwindow.cpp +++ b/GPClient/normalloginwindow.cpp @@ -1,8 +1,8 @@ +#include + #include "normalloginwindow.h" #include "ui_normalloginwindow.h" -#include - NormalLoginWindow::NormalLoginWindow(QWidget *parent) : QDialog(parent), ui(new Ui::NormalLoginWindow) diff --git a/GPClient/normalloginwindow.h b/GPClient/normalloginwindow.h index d697aba..a2327bb 100644 --- a/GPClient/normalloginwindow.h +++ b/GPClient/normalloginwindow.h @@ -1,7 +1,7 @@ #ifndef PORTALAUTHWINDOW_H #define PORTALAUTHWINDOW_H -#include +#include namespace Ui { class NormalLoginWindow; diff --git a/GPClient/portalauthenticator.cpp b/GPClient/portalauthenticator.cpp index 7570a23..e0900ea 100644 --- a/GPClient/portalauthenticator.cpp +++ b/GPClient/portalauthenticator.cpp @@ -1,3 +1,6 @@ +#include +#include + #include "portalauthenticator.h" #include "gphelper.h" #include "normalloginwindow.h" @@ -7,9 +10,6 @@ #include "portalconfigresponse.h" #include "gpgateway.h" -#include -#include - using namespace gpclient::helper; PortalAuthenticator::PortalAuthenticator(const QString& portal, const QString& clientos) : QObject() diff --git a/GPClient/portalauthenticator.h b/GPClient/portalauthenticator.h index 0042bbd..4a39fc3 100644 --- a/GPClient/portalauthenticator.h +++ b/GPClient/portalauthenticator.h @@ -1,12 +1,13 @@ #ifndef PORTALAUTHENTICATOR_H #define PORTALAUTHENTICATOR_H +#include + #include "portalconfigresponse.h" #include "normalloginwindow.h" #include "samlloginwindow.h" #include "preloginresponse.h" -#include class PortalAuthenticator : public QObject { diff --git a/GPClient/portalconfigresponse.cpp b/GPClient/portalconfigresponse.cpp index 790056d..c5c578f 100644 --- a/GPClient/portalconfigresponse.cpp +++ b/GPClient/portalconfigresponse.cpp @@ -1,8 +1,8 @@ -#include "portalconfigresponse.h" - -#include +#include #include +#include "portalconfigresponse.h" + QString PortalConfigResponse::xmlUserAuthCookie = "portal-userauthcookie"; QString PortalConfigResponse::xmlPrelogonUserAuthCookie = "portal-prelogonuserauthcookie"; QString PortalConfigResponse::xmlGateways = "gateways"; diff --git a/GPClient/portalconfigresponse.h b/GPClient/portalconfigresponse.h index c79dae0..b6fe0d9 100644 --- a/GPClient/portalconfigresponse.h +++ b/GPClient/portalconfigresponse.h @@ -1,11 +1,11 @@ #ifndef PORTALCONFIGRESPONSE_H #define PORTALCONFIGRESPONSE_H -#include "gpgateway.h" +#include +#include +#include -#include -#include -#include +#include "gpgateway.h" class PortalConfigResponse { diff --git a/GPClient/preloginresponse.cpp b/GPClient/preloginresponse.cpp index d148b60..6fd6f40 100644 --- a/GPClient/preloginresponse.cpp +++ b/GPClient/preloginresponse.cpp @@ -1,9 +1,9 @@ -#include "preloginresponse.h" - -#include -#include +#include +#include #include +#include "preloginresponse.h" + QString PreloginResponse::xmlAuthMessage = "authentication-message"; QString PreloginResponse::xmlLabelUsername = "username-label"; QString PreloginResponse::xmlLabelPassword = "password-label"; diff --git a/GPClient/preloginresponse.h b/GPClient/preloginresponse.h index 1b8b09c..772a037 100644 --- a/GPClient/preloginresponse.h +++ b/GPClient/preloginresponse.h @@ -1,8 +1,8 @@ #ifndef PRELOGINRESPONSE_H #define PRELOGINRESPONSE_H -#include -#include +#include +#include class PreloginResponse { diff --git a/GPClient/samlloginwindow.cpp b/GPClient/samlloginwindow.cpp index 2729ca1..70d58b4 100644 --- a/GPClient/samlloginwindow.cpp +++ b/GPClient/samlloginwindow.cpp @@ -1,9 +1,9 @@ -#include "samlloginwindow.h" - -#include +#include +#include +#include #include -#include -#include + +#include "samlloginwindow.h" SAMLLoginWindow::SAMLLoginWindow(QWidget *parent) : QDialog(parent) diff --git a/GPClient/samlloginwindow.h b/GPClient/samlloginwindow.h index 09d8a2e..2d6bc79 100644 --- a/GPClient/samlloginwindow.h +++ b/GPClient/samlloginwindow.h @@ -1,11 +1,11 @@ #ifndef SAMLLOGINWINDOW_H #define SAMLLOGINWINDOW_H -#include "enhancedwebview.h" +#include +#include +#include -#include -#include -#include +#include "enhancedwebview.h" class SAMLLoginWindow : public QDialog { diff --git a/GPClient/settingsdialog.h b/GPClient/settingsdialog.h index 234db96..9e29e48 100644 --- a/GPClient/settingsdialog.h +++ b/GPClient/settingsdialog.h @@ -1,7 +1,7 @@ #ifndef SETTINGSDIALOG_H #define SETTINGSDIALOG_H -#include +#include namespace Ui { class SettingsDialog; diff --git a/GPService/CMakeLists.txt b/GPService/CMakeLists.txt new file mode 100644 index 0000000..c7205c3 --- /dev/null +++ b/GPService/CMakeLists.txt @@ -0,0 +1,57 @@ +include("${CMAKE_SOURCE_DIR}/cmake/Add3rdParty.cmake") + +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) + +# generate dbus adaptor +qt5_add_dbus_adaptor( + gpservice_GENERATED_SOURCES + ${CMAKE_BINARY_DIR}/com.yuezk.qt.GPService.xml + gpservice.h + GPService +) + +add_executable(gpservice + gpservice.cpp + main.cpp + sigwatch.cpp + ${gpservice_GENERATED_SOURCES} +) + +add_3rdparty( + SingleApplication + GIT_REPOSITORY https://github.com/itay-grudev/SingleApplication.git + GIT_TAG v3.3.0 + CMAKE_ARGS -DQAPPLICATION_CLASS=QCoreApplication +) + +ExternalProject_Get_Property(SingleApplication-${PROJECT_NAME} SOURCE_DIR BINARY_DIR) + +set(SingleApplication_INCLUDE_DIR ${SOURCE_DIR}) +set(SingleApplication_LIBRARY ${BINARY_DIR}/libSingleApplication.a) + +add_dependencies(gpservice SingleApplication-${PROJECT_NAME}) + +target_include_directories(gpservice PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${SingleApplication_INCLUDE_DIR} +) + +target_link_libraries(gpservice + ${SingleApplication_LIBRARY} + Qt5::Core + Qt5::Network + Qt5::DBus +) + +target_compile_definitions(gpservice PUBLIC QAPPLICATION_CLASS=QCoreApplication) + +install(TARGETS gpservice DESTINATION "/usr/bin") +install(FILES "dbus/com.yuezk.qt.GPService.conf" DESTINATION "/usr/share/dbus-1/system.d" ) +install(FILES "dbus/com.yuezk.qt.GPService.service" DESTINATION "/usr/share/dbus-1/system-services") +install(FILES "systemd/gpservice.service" DESTINATION "/etc/systemd/system") diff --git a/GPService/GPService.pro b/GPService/GPService.pro deleted file mode 100644 index e37b7bf..0000000 --- a/GPService/GPService.pro +++ /dev/null @@ -1,52 +0,0 @@ -TARGET = gpservice - -#QT += dbus -QT -= gui - -CONFIG += c++11 console -CONFIG -= app_bundle - -include(../singleapplication/singleapplication.pri) -DEFINES += QAPPLICATION_CLASS=QCoreApplication - -# The following define makes your compiler emit warnings if you use -# any Qt feature that has been marked deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -HEADERS += \ -# gpservice.h \ - sigwatch.h - -SOURCES += \ -# gpservice.cpp \ - main.cpp \ - sigwatch.cpp - -#DBUS_ADAPTORS += gpservice.xml - -# Default rules for deployment. -target.path = /usr/bin -INSTALLS += target - -#DISTFILES += \ -# dbus/com.yuezk.qt.GPService.conf \ -# dbus/com.yuezk.qt.GPService.service \ -# systemd/gpservice.service - -#dbus_config.path = /usr/share/dbus-1/system.d/ -#dbus_config.files = dbus/com.yuezk.qt.GPService.conf - -#dbus_service.path = /usr/share/dbus-1/system-services/ -#dbus_service.files = dbus/com.yuezk.qt.GPService.service - -#systemd_service.path = /etc/systemd/system/ -#systemd_service.files = systemd/gpservice.service - -#INSTALLS += dbus_config dbus_service systemd_service diff --git a/GPService/gpservice.cpp b/GPService/gpservice.cpp index 7f61660..644847f 100644 --- a/GPService/gpservice.cpp +++ b/GPService/gpservice.cpp @@ -1,11 +1,13 @@ -#include "gpservice.h" -#include "gpservice_adaptor.h" +#include +#include +#include +#include +#include +#include +#include -#include -#include -#include -#include -#include +#include "gpservice.h" +#include "gpserviceadaptor.h" GPService::GPService(QObject *parent) : QObject(parent) @@ -107,13 +109,17 @@ void GPService::connect(QString server, QString username, QString passwd, QStrin return; } + if (!isValidVersion(bin)) { + return; + } + QStringList args; args << QCoreApplication::arguments().mid(1) - << "--protocol=gp" - << splitCommand(extraArgs) - << "-u" << username - << "-C" << passwd - << server; + << "--protocol=gp" + << splitCommand(extraArgs) + << "-u" << username + << "-C" << passwd + << server; log("Start process with arugments: " + args.join(" ")); @@ -122,6 +128,32 @@ void GPService::connect(QString server, QString username, QString passwd, QStrin openconnect->start(bin, args); } +bool GPService::isValidVersion(QString &bin) { + QProcess p; + p.start(bin, QStringList("--version")); + p.waitForFinished(); + QString output = p.readAllStandardError() + p.readAllStandardOutput(); + + QRegularExpression re("v(\\d+).*?(\\s|\\n)"); + QRegularExpressionMatch match = re.match(output); + + if (match.hasMatch()) { + log("Output of `openconnect --version`: " + output); + + QString fullVersion = match.captured(0); + QString majorVersion = match.captured(1); + + if (majorVersion.toInt() < 8) { + emit error("The OpenConnect version must greater than v8.0.0, but got " + fullVersion); + return false; + } + } else { + log("Failed to parse the OpenConnect version from " + output); + } + + return true; +} + void GPService::disconnect() { if (openconnect->state() != QProcess::NotRunning) { diff --git a/GPService/gpservice.h b/GPService/gpservice.h index 7f547a3..a3b4856 100644 --- a/GPService/gpservice.h +++ b/GPService/gpservice.h @@ -1,8 +1,8 @@ #ifndef GLOBALPROTECTSERVICE_H #define GLOBALPROTECTSERVICE_H -#include -#include +#include +#include static const QString binaryPaths[] { "/usr/local/bin/openconnect", @@ -21,6 +21,8 @@ public: explicit GPService(QObject *parent = nullptr); ~GPService(); + void quit(); + enum VpnStatus { VpnNotConnected, VpnConnecting, @@ -38,7 +40,6 @@ public slots: void connect(QString server, QString username, QString passwd, QString extraArgs); void disconnect(); int status(); - void quit(); private slots: void onProcessStarted(); @@ -53,6 +54,7 @@ private: int vpnStatus = GPService::VpnNotConnected; void log(QString msg); + bool isValidVersion(QString &bin); static QString findBinary(); static QStringList splitCommand(QString command); }; diff --git a/GPService/gpservice.xml b/GPService/gpservice.xml deleted file mode 100644 index 9a9b8e8..0000000 --- a/GPService/gpservice.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/GPService/main.cpp b/GPService/main.cpp index a57809c..79c41be 100644 --- a/GPService/main.cpp +++ b/GPService/main.cpp @@ -1,23 +1,23 @@ -//#include "gpservice.h" +#include +#include +#include + +#include "gpservice.h" #include "singleapplication.h" #include "sigwatch.h" -#include "iostream" - -//#include -#include - int main(int argc, char *argv[]) { SingleApplication app(argc, argv); -// if (!QDBusConnection::systemBus().isConnected()) { -// qWarning("Cannot connect to the D-Bus session bus.\n" -// "Please check your system settings and try again.\n"); -// return 1; -// } + if (!QDBusConnection::systemBus().isConnected()) + { + qWarning("Cannot connect to the D-Bus session bus.\n" + "Please check your system settings and try again.\n"); + return 1; + } -// GPService service; + GPService service; QString env = "ENV: " + QProcessEnvironment::systemEnvironment().toStringList().join("\n"); std::cout << env.toStdString(); @@ -27,7 +27,7 @@ int main(int argc, char *argv[]) sigwatch.watchForSignal(SIGTERM); sigwatch.watchForSignal(SIGQUIT); sigwatch.watchForSignal(SIGHUP); -// QObject::connect(&sigwatch, &UnixSignalWatcher::unixSignal, &service, &GPService::quit); + QObject::connect(&sigwatch, &UnixSignalWatcher::unixSignal, &service, &GPService::quit); return app.exec(); } diff --git a/GlobalProtect-openconnect.pro b/GlobalProtect-openconnect.pro deleted file mode 100644 index 00483f6..0000000 --- a/GlobalProtect-openconnect.pro +++ /dev/null @@ -1,5 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS += \ - GPClient \ - GPService diff --git a/PKGBUILD.template b/PKGBUILD.template index f34be1e..4456ab7 100644 --- a/PKGBUILD.template +++ b/PKGBUILD.template @@ -9,31 +9,25 @@ arch=(x86_64 aarch64) url="https://github.com/yuezk/${_gitname}" license=('GPL3') depends=('openconnect>=8.0.0' qt5-base qt5-webengine qt5-websockets) -makedepends=() +makedepends=(g++ make) source=( "${_gitname}-${pkgver}.tar.gz::${url}/archive/v${pkgver}.tar.gz" - "https://github.com/itay-grudev/SingleApplication/archive/v3.0.19.tar.gz" - "https://github.com/SergiusTheBest/plog/archive/1.1.5.tar.gz" ) sha256sums=( '{SOURCE_SHA}' - '9405fd259288b2a862e91e5135bccee936f0438e1b32c13603277132309d15e0' - '6c80b4701183d2415bec927e1f5ca9b1761b3b5c65d3e09fb29c743e016d5609' ); prepare() { - mv "$srcdir/SingleApplication-3.0.19" -T "$srcdir/${_gitname}-${pkgver}/singleapplication" - mv "$srcdir/plog-1.1.5" -T "$srcdir/${_gitname}-${pkgver}/plog" } build() { cd "$srcdir/${_gitname}-${pkgver}" - qmake CONFIG+=release "${srcdir}/${_gitname}-${pkgver}/GlobalProtect-openconnect.pro" - make + ./cmakew -B build + MAKEFLAGS=-j$(nproc) ./cmakew --build build } package() { cd "$srcdir/${_gitname}-${pkgver}" - make INSTALL_ROOT="$pkgdir/" install + make DESTDIR="$pkgdir/" install -C build } diff --git a/README.md b/README.md index 6048d11..45286ce 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A GlobalProtect VPN client (GUI) for Linux based on Openconnect and built with Qt5, supports SAML auth mode, inspired by [gp-saml-gui](https://github.com/dlenski/gp-saml-gui).

- +

## Features @@ -43,63 +43,63 @@ Install the [AppIndicator and KStatusNotifierItem Support](https://extensions.gn - Openconnect v8.x - Qt5, qt5-webengine, qt5-websockets -### Ubuntu -1. Install openconnect v8.x +## Build & Install - ```sh - sudo apt install openconnect - openconnect --version - ``` - - For Ubuntu 18.04 you might need to [build the latest openconnect from source code](https://gist.github.com/yuezk/ab9a4b87a9fa0182bdb2df41fab5f613). - -2. Install the Qt dependencies - - For Ubuntu 20, this should work. - - ```sh - sudo apt install qtbase5-dev libqt5websockets5-dev qtwebengine5-dev qttools5-dev debhelper - ``` - - For Ubuntu 21, you need to install the base pieces separately as QT5 is the default. - - ```sh - sudo apt install qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools libqt5websockets5-dev qtwebengine5-dev qttools5-dev debhelper - ``` - -### OpenSUSE -Install the Qt dependencies - -```sh -sudo zypper install libqt5-qtbase-devel libqt5-qtwebsockets-devel libqt5-qtwebengine-devel -``` - -### Fedora -Install the Qt dependencies: - -```sh -sudo dnf install qt5-qtbase-devel qt5-qtwebengine-devel qt5-qtwebsockets-devel -``` - -## Install - -### Install from AUR (Arch/Manjaro) - -Install [globalprotect-openconnect](https://aur.archlinux.org/packages/globalprotect-openconnect/). - -### Build from source code +Clone this repo with: ```sh git clone https://github.com/yuezk/GlobalProtect-openconnect.git cd GlobalProtect-openconnect -git submodule update --init - -# qmake or qmake-qt5 -qmake CONFIG+=release -make -sudo make install ``` -Open `GlobalProtect VPN` in the application dashboard. + +### Arch/Manjaro + +Install from the [globalprotect-openconnect](https://aur.archlinux.org/packages/globalprotect-openconnect/) AUR. + +### Ubuntu/Mint + +For **Ubuntu 18.04**, add this [dwmw2/openconnect](https://launchpad.net/~dwmw2/+archive/ubuntu/openconnect) PPA first to install the latest openconnect. + +```sh +sudo add-apt-repository ppa:dwmw2/openconnect +sudo apt update +``` +...then build and install with: + +```sh +./scripts/install-ubuntu.sh +``` +### openSUSE + +Build and install with: + +```sh +./scripts/install-opensuse.sh +``` + +### Fedora + +Build and install with: + +```sh +./scripts/install-fedora.sh +``` + +### Other Linux + +Install the Qt5 dependencies and OpenConnect: + +- QtCore +- QtWebEngine +- QtWebSockets +- QtDBus +- openconnect v8.x + +...then build and install with: + +```sh +./scripts/install.sh +``` ### Debian package diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..785cda8 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.3.3 \ No newline at end of file diff --git a/cmake/Add3rdParty.cmake b/cmake/Add3rdParty.cmake new file mode 100644 index 0000000..3809a14 --- /dev/null +++ b/cmake/Add3rdParty.cmake @@ -0,0 +1,27 @@ +include(ExternalProject) + +function(add_3rdparty NAME) + set(oneValueArgs GIT_REPOSITORY GIT_TAG) + cmake_parse_arguments(add_3rdparty_args "" "${oneValueArgs}" "" ${ARGN}) + + if(EXISTS "${CMAKE_SOURCE_DIR}/3rdparty/${NAME}/CMakeLists.txt") + message(STATUS "Found third party locally for ${NAME}") + + ExternalProject_Add( + ${NAME}-${PROJECT_NAME} + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/${NAME} + SOURCE_DIR "${CMAKE_SOURCE_DIR}/3rdparty/${NAME}" + INSTALL_COMMAND "" + "${add_3rdparty_args_UNPARSED_ARGUMENTS}" + ) + return() + endif() + + message(STATUS "Using ExternalProject to download ${NAME}") + ExternalProject_Add( + ${NAME}-${PROJECT_NAME} + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/${NAME} + INSTALL_COMMAND "" + "${ARGN}" + ) +endfunction() diff --git a/cmakew b/cmakew new file mode 100755 index 0000000..1d73db0 --- /dev/null +++ b/cmakew @@ -0,0 +1,102 @@ +#!/bin/bash + +cmake_version="3.21.2" + +arr_cmake_v=(${cmake_version//./ }) +cmake_version_major=(${arr_cmake_v[0]}) +cmake_version_minor=(${arr_cmake_v[1]}) +cmake_version_patch=(${arr_cmake_v[2]}) + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false + +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +cmake_base="./.cmake" +cmake_bin="${cmake_base}/cmake-$cmake_version/bin/cmake" + +# download cmake if neccessary +if [ ! -f "$cmake_bin" ]; then + download_link="" + + if [ "$darwin" = true ]; then + download_link="https://cmake.org/files/v$cmake_version_major.$cmake_version_minor/cmake-$cmake_version-Darwin-x86_64.tar.gz" + else + download_link="https://github.com/Kitware/CMake/releases/download/v${cmake_version}/cmake-${cmake_version}-linux-x86_64.tar.gz" + fi + + wget -nv --show-progress "$download_link" -O "/tmp/cmake-$cmake_version.tar.gz" + mkdir -p "${cmake_base}/cmake-$cmake_version" + tar -xzf "/tmp/cmake-$cmake_version.tar.gz" -C "${cmake_base}/cmake-$cmake_version" --strip-components=1 + rm "/tmp/cmake-$cmake_version.tar.gz" +fi + +# We build the pattern for arguments to be converted via cygpath +if [ "$cygwin" = true ]; then + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + + OURCYGPATTERN="(^($ROOTDIRS))" + + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + + i=$((i+1)) + done + + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# run cmake +exec "$cmake_bin" "$@" \ No newline at end of file diff --git a/plog b/plog deleted file mode 160000 index fda4a26..0000000 --- a/plog +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fda4a26c26b2d1b2beb68d7b92b56950ec2b8ad2 diff --git a/screenshot.png b/screenshot.png deleted file mode 100644 index 868eb9b..0000000 Binary files a/screenshot.png and /dev/null differ diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh new file mode 100755 index 0000000..7130bb1 --- /dev/null +++ b/scripts/bump-version.sh @@ -0,0 +1,452 @@ +#!/bin/bash +# +# █▄▄ █░█ █▀▄▀█ █▀█ ▄▄ █░█ █▀▀ █▀█ █▀ █ █▀█ █▄░█ +# █▄█ █▄█ █░▀░█ █▀▀ ░░ ▀▄▀ ██▄ █▀▄ ▄█ █ █▄█ █░▀█ +# +# Description: +# - This script automates bumping the git software project's version using automation. + +# - It does several things that are typically required for releasing a Git repository, like git tagging, +# automatic updating of CHANGELOG.md, and incrementing the version number in various JSON files. + +# - Increments / suggests the current software project's version number +# - Adds a Git tag, named after the chosen version number +# - Updates CHANGELOG.md +# - Updates VERSION file +# - Commits files to a new branch +# - Pushes to remote (optionally) +# - Updates "version" : "x.x.x" tag in JSON files if [-v file1 -v file2...] argument is supplied. +# +# Usage: +# ./bump-version.sh [-v ] [-m ] [-j ] [-j ].. [-n] [-p] [-b] [-h] +# +# Options: +# -v Specify a manual version number +# -m Custom release message. +# -f Update version number inside JSON files. +# * For multiple files, add a separate -f option for each one, +# * For example: ./bump-version.sh -f src/plugin/package.json -f composer.json +# -p Push commits to remote repository, eg `-p origin` +# -n Don't perform a commit automatically. +# * You may want to do that yourself, for example. +# -b Don't create automatic `release-` branch +# -h Show help message. + +# +# Detailed notes: +# – The contents of the `VERSION` file which should be a semantic version number such as "1.2.3" +# or even "1.2.3-beta+001.ab" +# +# – It pulls a list of changes from git history & prepends to a file called CHANGELOG.md +# under the title of the new version # number, allows the user to review and update the changelist +# +# – Creates a Git tag with the version number +# +# - Creates automatic `release-` branch +# +# – Commits the new version to the current repository +# +# – Optionally pushes the commit to remote repository +# +# – Make sure to set execute permissions for the script, eg `$ chmod 755 bump-version.sh` +# +# Credits: +# – https://github.com/jv-k/bump-version +# +# - Inspired by the scripts from @pete-otaqui and @mareksuscak +# https://gist.github.com/pete-otaqui/4188238 +# https://gist.github.com/mareksuscak/1f206fbc3bb9d97dec9c +# + +NOW="$(date +'%B %d, %Y')" + +# ANSI/VT100 colours +YELLOW='\033[1;33m' +LIGHTYELLOW='\033[0;33m' +RED='\033[0;31m' +LIGHTRED='\033[1;31m' +GREEN='\033[0;32m' +LIGHTGREEN='\033[1;32m' +BLUE='\033[0;34m' +LIGHTBLUE='\033[1;34m' +PURPLE='\033[0;35m' +LIGHTPURPLE='\033[1;35m' +CYAN='\033[0;36m' +LIGHTCYAN='\033[1;36m' +WHITE='\033[1;37m' +LIGHTGRAY='\033[0;37m' +DARKGRAY='\033[1;30m' +BOLD="\033[1m" +INVERT="\033[7m" +RESET='\033[0m' + +# Default options +FLAG_JSON="false" +FLAG_PUSH="false" + +I_OK="✅"; I_STOP="🚫"; I_ERROR="❌"; I_END="👋🏻" + +S_NORM="${WHITE}" +S_LIGHT="${LIGHTGRAY}" +S_NOTICE="${GREEN}" +S_QUESTION="${YELLOW}" +S_WARN="${LIGHTRED}" +S_ERROR="${RED}" + +V_SUGGEST="0.1.0" # This is suggested in case VERSION file or user supplied version via -v is missing +GIT_MSG="" +REL_NOTE="" +REL_PREFIX="release-" +PUSH_DEST="origin" + +# Show credits & help +usage() { + echo -e "$GREEN"\ + "\n █▄▄ █░█ █▀▄▀█ █▀█ ▄▄ █░█ █▀▀ █▀█ █▀ █ █▀█ █▄░█ "\ + "\n █▄█ █▄█ █░▀░█ █▀▀ ░░ ▀▄▀ ██▄ █▀▄ ▄█ █ █▄█ █░▀█ "\ + "\n\t\t\t\t\t$LIGHTGRAY v${SCRIPT_VER}"\ + + echo -e " ${S_NORM}${BOLD}Usage:${RESET}"\ + "\n $0 [-v ] [-m ] [-j ] [-j ].. [-n] [-p] [-h]" 1>&2; + + echo -e "\n ${S_NORM}${BOLD}Options:${RESET}" + echo -e " $S_WARN-v$S_NORM \tSpecify a manual version number" + echo -e " $S_WARN-m$S_NORM \tCustom release message." + echo -e " $S_WARN-f$S_NORM \tUpdate version number inside JSON files."\ + "\n\t\t\t* For multiple files, add a separate -f option for each one,"\ + "\n\t\t\t* For example: ./bump-version.sh -f src/plugin/package.json -f composer.json" + echo -e " $S_WARN-p$S_NORM \t\t\tPush commits to ORIGIN. " + echo -e " $S_WARN-n$S_NORM \t\t\tDon't perform a commit automatically. "\ + "\n\t\t\t* You may want to do that manually after checking everything, for example." + echo -e " $S_WARN-b$S_NORM \t\t\tDon't create automatic \`release-\` branch" + echo -e " $S_WARN-h$S_NORM \t\t\tShow this help message. " + echo -e "\n ${S_NORM}${BOLD}Author:$S_LIGHT https://github.com/jv-t/bump-version $RESET\n" + +} + +# If there are no commits in repo, quit, because you can't tag with zero commits. +check-commits-exist() { + git rev-parse HEAD &> /dev/null + if [ ! "$?" -eq 0 ]; then + echo -e "\n${I_STOP} ${S_ERROR}Your current branch doesn't have any commits yet. Can't tag without at least one commit." >&2 + echo + exit 1 + fi +} + +get-commit-msg() { + echo Bumped $([ -n "${V_PREV}" ] && echo "${V_PREV} –>" || echo "to ") "$V_USR_INPUT" +} + +exit_abnormal() { + echo -e " ${S_LIGHT}––––––" + usage # Show help + exit 1 +} + +# Process script options +process-arguments() { + local OPTIONS OPTIND OPTARG + + # Get positional parameters + JSON_FILES=( ) + while getopts ":v:p:m:f:hbn" OPTIONS; do # Note: Adding the first : before the flags takes control of flags and prevents default error msgs. + case "$OPTIONS" in + h ) + # Show help + exit_abnormal + ;; + v ) + # User has supplied a version number + V_USR_SUPPLIED=$OPTARG + ;; + m ) + REL_NOTE=$OPTARG + # Custom release note + echo -e "\n${S_LIGHT}Option set: ${S_NOTICE}Release note:" ${S_NORM}"'"$REL_NOTE"'" + ;; + f ) + FLAG_JSON=true + echo -e "\n${S_LIGHT}Option set: ${S_NOTICE}JSON file via [-f]: <${S_NORM}${OPTARG}${S_LIGHT}>" + # Store JSON filenames(s) + JSON_FILES+=($OPTARG) + ;; + p ) + FLAG_PUSH=true + PUSH_DEST=${OPTARG} # Replace default with user input + echo -e "\n${S_LIGHT}Option set: ${S_NOTICE}Pushing to <${S_NORM}${PUSH_DEST}${S_LIGHT}>, as the last action in this script." + ;; + n ) + FLAG_NOCOMMIT=true + echo -e "\n${S_LIGHT}Option set: ${S_NOTICE}Disable commit after tagging." + ;; + b ) + FLAG_NOBRANCH=true + echo -e "\n${S_LIGHT}Option set: ${S_NOTICE}Disable committing to new branch." + ;; + \? ) + echo -e "\n${I_ERROR}${S_ERROR} Invalid option: ${S_WARN}-$OPTARG" >&2 + echo + exit_abnormal + ;; + : ) + echo -e "\n${I_ERROR}${S_ERROR} Option ${S_WARN}-$OPTARG ${S_ERROR}requires an argument." >&2 + echo + exit_abnormal + ;; + esac + done +} + +# Suggests version from VERSION file, or grabs from user supplied -v . +# If none is set, suggest default from options. +process-version() { + if [ -f VERSION ] && [ -s VERSION ]; then + V_PREV=`cat VERSION` + + echo -e "\n${S_NOTICE}Current version from <${S_NORM}VERSION${S_NOTICE}> file: ${S_NORM}$V_PREV" + + # Suggest incremented value from VERSION file + V_PREV_LIST=(`echo $V_PREV | tr '.' ' '`) + V_MAJOR=${V_PREV_LIST[0]}; V_MINOR=${V_PREV_LIST[1]}; V_PATCH=${V_PREV_LIST[2]}; + + # Test if V_PATCH is a number, then increment it. Otherwise, do nothing + if [ "$V_PATCH" -eq "$V_PATCH" ] 2>/dev/null; then # discard stderr (2) output to black hole (suppress it) + V_PATCH=$((V_PATCH + 1)) # Increment + fi + + V_SUGGEST="$V_MAJOR.$V_MINOR.$V_PATCH" + else + echo -ne "\n${S_WARN}The [${S_NORM}VERSION${S_WARN}] " + if [ ! -f VERSION ]; then + echo "file was not found."; + elif [ ! -s VERSION ]; then + echo "file is empty."; + fi + fi + + # If a version number is supplied by the user with [-v ], then use it + if [ -n "$V_USR_SUPPLIED" ]; then + echo -e "\n${S_NOTICE}You selected version using [-v]:" "${S_WARN}${V_USR_SUPPLIED}" + V_USR_INPUT="${V_USR_SUPPLIED}" + else + echo -ne "\n${S_QUESTION}Enter a new version number [${S_NORM}$V_SUGGEST${S_QUESTION}]: " + echo -ne "$S_WARN" + read V_USR_INPUT + + if [ "$V_USR_INPUT" = "" ]; then + V_USR_INPUT="${V_SUGGEST}" + fi + fi + + # echo -e "${S_NOTICE}Setting version to [${S_NORM}${V_USR_INPUT}${S_NOTICE}] ...." +} + +# Only tag if tag doesn't already exist +check-tag-exists() { + TAG_CHECK_EXISTS=`git tag -l v"$V_USR_INPUT"` + if [ -n "$TAG_CHECK_EXISTS" ]; then + echo -e "\n${I_STOP} ${S_ERROR}Error: A release with that tag version number already exists!\n" + exit 0 + fi +} + +# $1 : version +# $2 : release note +tag() { + if [ -z "$2" ]; then + # Default release note + git tag -a "v$1" -m "Tag version $1." + else + # Custom release note + git tag -a "v$1" -m "$2" + fi + echo -e "\n${I_OK} ${S_NOTICE}Added GIT tag" +} + +# Change `version:` value in JSON files, like packager.json, composer.json, etc +bump-json-files() { + if [ "$FLAG_JSON" != true ]; then return; fi + + JSON_PROCESSED=( ) # holds filenames after they've been changed + + for FILE in "${JSON_FILES[@]}"; do + if [ -f $FILE ]; then + # Get the existing version number + V_OLD=$( sed -n 's/.*"version": "\(.*\)",/\1/p' $FILE ) + + if [ "$V_OLD" = "$V_USR_INPUT" ]; then + echo -e "\n${S_WARN}File <${S_NORM}$FILE${S_WARN}> already contains version: ${S_NORM}$V_OLD" + else + # Write to output file + FILE_MSG=`sed -i .temp "s/\"version\": \"$V_OLD\"/\"version\": \"$V_USR_INPUT\"/g" $FILE 2>&1` + if [ "$?" -eq 0 ]; then + echo -e "\n${I_OK} ${S_NOTICE}Updated file: <${S_NOTICE}$FILE${S_LIGHT}> from ${S_NORM}$V_OLD -> $V_USR_INPUT" + rm -f ${FILE}.temp + # Add file change to commit message: + GIT_MSG+="${GIT_MSG}Updated $FILE, " + else + echo -e "\n${I_STOP} ${S_ERROR}Error\n$PUSH_MSG\n" + fi + fi + + JSON_PROCESSED+=($FILE) + else + echo -e "\n${S_WARN}File <${S_NORM}$FILE${S_WARN}> not found." + fi + done + # Stage files that were changed: + [ -n "${JSON_PROCESSED}" ] && git add "${JSON_PROCESSED[@]}" +} + +# Handle VERSION file +do-versionfile() { + [ -f VERSION ] && ACTION_MSG="Updated" || ACTION_MSG="Created" + + GIT_MSG+="${ACTION_MSG} VERSION, " + echo $V_USR_INPUT > VERSION # Create file + echo -e "\n${I_OK} ${S_NOTICE}${ACTION_MSG} [${S_NORM}VERSION${S_NOTICE}] file" + + # Stage file for commit + git add VERSION +} + +# Dump git log history to CHANGELOG.md +do-changelog() { + + # Log latest commits to CHANGELOG.md: + # Get latest commits + LOG_MSG=`git log --pretty=format:"- %s" $([ -n "$V_PREV" ] && echo "v${V_PREV}...HEAD") 2>&1` + if [ ! "$?" -eq 0 ]; then + echo -e "\n${I_STOP} ${S_ERROR}Error getting commit history for logging to CHANGELOG.\n$LOG_MSG\n" + exit 1 + fi + + [ -f CHANGELOG.md ] && ACTION_MSG="Updated" || ACTION_MSG="Created" + # Add info to commit message for later: + GIT_MSG+="${ACTION_MSG} CHANGELOG.md, " + + # Add heading + echo "## $V_USR_INPUT ($NOW)" > tmpfile + + # Log the bumping commit: + # - The final commit is done after do-changelog(), so we need to create the log entry for it manually: + echo "- ${GIT_MSG}$(get-commit-msg)" >> tmpfile + # Add previous commits + [ -n "$LOG_MSG" ] && echo "$LOG_MSG" >> tmpfile + + echo -en "\n" >> tmpfile + + if [ -f CHANGELOG.md ]; then + # Append existing log + cat CHANGELOG.md >> tmpfile + else + echo -e "\n${S_WARN}A [${S_NORM}CHANGELOG.md${S_WARN}] file was not found." + fi + + mv tmpfile CHANGELOG.md + + # User prompts + echo -e "\n${I_OK} ${S_NOTICE}${ACTION_MSG} [${S_NORM}CHANGELOG.md${S_NOTICE}] file" + # Pause & allow user to open and edit the file: + echo -en "\n${S_QUESTION}Make adjustments to [${S_NORM}CHANGELOG.md${S_QUESTION}] if required now. Press to continue." + read + + # Stage log file, to commit later + git add CHANGELOG.md +} + +# +check-branch-exist() { + [ "$FLAG_NOBRANCH" = true ] && return + + BRANCH_MSG=`git rev-parse --verify "${REL_PREFIX}${V_USR_INPUT}" 2>&1` + if [ "$?" -eq 0 ]; then + echo -e "\n${I_STOP} ${S_ERROR}Error: Branch <${S_NORM}${REL_PREFIX}${V_USR_INPUT}${S_ERROR}> already exists!\n" + exit 1 + fi +} + +# +do-branch() { + [ "$FLAG_NOBRANCH" = true ] && return + + echo -e "\n${S_NOTICE}Creating new release branch..." + + BRANCH_MSG=`git branch "${REL_PREFIX}${V_USR_INPUT}" 2>&1` + if [ ! "$?" -eq 0 ]; then + echo -e "\n${I_STOP} ${S_ERROR}Error\n$BRANCH_MSG\n" + exit 1 + else + BRANCH_MSG=`git checkout "${REL_PREFIX}${V_USR_INPUT}" 2>&1` + echo -e "\n${I_OK} ${S_NOTICE}${BRANCH_MSG}" + fi + + # REL_PREFIX +} + +# Stage & commit all files modified by this script +do-commit() { + [ "$FLAG_NOCOMMIT" = true ] && return + + GIT_MSG+="$(get-commit-msg)" + echo -e "\n${S_NOTICE}Committing..." + COMMIT_MSG=`git commit -m "${GIT_MSG}" 2>&1` + if [ ! "$?" -eq 0 ]; then + echo -e "\n${I_STOP} ${S_ERROR}Error\n$COMMIT_MSG\n" + exit 1 + else + echo -e "\n${I_OK} ${S_NOTICE}$COMMIT_MSG" + fi +} + +# Pushes files + tags to remote repo. Changes are staged by earlier functions +do-push() { + [ "$FLAG_NOCOMMIT" = true ] && return + + if [ "$FLAG_PUSH" = true ]; then + CONFIRM="Y" + else + echo -ne "\n${S_QUESTION}Push tags to <${S_NORM}${PUSH_DEST}${S_QUESTION}>? [${S_NORM}N/y${S_QUESTION}]: " + read CONFIRM + fi + + case "$CONFIRM" in + [yY][eE][sS]|[yY] ) + echo -e "\n${S_NOTICE}Pushing files + tags to <${S_NORM}${PUSH_DEST}${S_NOTICE}>..." + PUSH_MSG=`git push "${PUSH_DEST}" v"$V_USR_INPUT" 2>&1` # Push new tag + if [ ! "$?" -eq 0 ]; then + echo -e "\n${I_STOP} ${S_WARN}Warning\n$PUSH_MSG" + # exit 1 + else + echo -e "\n${I_OK} ${S_NOTICE}$PUSH_MSG" + fi + ;; + esac +} + +#### Initiate Script ########################### + +check-commits-exist + +# Process and prepare +process-arguments "$@" +process-version + +check-branch-exist +check-tag-exists + +echo -e "\n${S_LIGHT}––––––" + +# Update files +bump-json-files +do-versionfile +# do-changelog +# do-branch +do-commit +tag "${V_USR_INPUT}" "${REL_NOTE}" +do-push + +echo -e "\n${S_LIGHT}––––––" +echo -e "\n${I_OK} ${S_NOTICE}"Bumped $([ -n "${V_PREV}" ] && echo "${V_PREV} –>" || echo "to ") "$V_USR_INPUT" +echo -e "\n${GREEN}Done ${I_END}\n" \ No newline at end of file diff --git a/scripts/install-fedora.sh b/scripts/install-fedora.sh new file mode 100755 index 0000000..37bab58 --- /dev/null +++ b/scripts/install-fedora.sh @@ -0,0 +1,9 @@ +#!/bin/bash -e + +sudo dnf install -y \ + qt5-qtbase-devel \ + qt5-qtwebengine-devel \ + qt5-qtwebsockets-devel \ + openconnect + +./scripts/install.sh \ No newline at end of file diff --git a/scripts/install-opensuse.sh b/scripts/install-opensuse.sh new file mode 100755 index 0000000..3bd78c5 --- /dev/null +++ b/scripts/install-opensuse.sh @@ -0,0 +1,9 @@ +#!/bin/bash -e + +sudo zypper install -y \ + libqt5-qtbase-devel \ + libqt5-qtwebsockets-devel \ + libqt5-qtwebengine-devel \ + openconnect + +./scripts/install.sh \ No newline at end of file diff --git a/scripts/install-ubuntu.sh b/scripts/install-ubuntu.sh new file mode 100755 index 0000000..663c8fc --- /dev/null +++ b/scripts/install-ubuntu.sh @@ -0,0 +1,11 @@ +#!/bin/bash -e + +sudo apt update +sudo apt install -y \ + build-essential \ + qtbase5-dev \ + libqt5websockets5-dev \ + qtwebengine5-dev \ + openconnect + +./scripts/install.sh \ No newline at end of file diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 0000000..672c0a1 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,10 @@ +#!/bin/bash -e + +./cmakew -B build -DCMAKE_BUILD_TYPE=Release +MAKEFLAGS=-j$(nproc) ./cmakew --build build +sudo ./cmakew --install build + +sudo systemctl daemon-reload +sudo systemctl restart gpservice.service + +echo -e "\nSuccess. You can launch the GlobalProtect VPN client from the application dashboard.\n" \ No newline at end of file diff --git a/singleapplication b/singleapplication deleted file mode 160000 index 0f6695e..0000000 --- a/singleapplication +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0f6695e2a9d8fdaa336e7ad941855c46c61f218a diff --git a/version.h.in b/version.h.in new file mode 100644 index 0000000..e275553 --- /dev/null +++ b/version.h.in @@ -0,0 +1 @@ +#define VERSION "@GlobalProtect-openconnect_VERSION@" \ No newline at end of file