From e7384fb3f45d7c6cf50c4173e05ee6f43613dae9 Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Sat, 21 Nov 2026 02:41:00 +0800 Subject: [PATCH] Release 3.7.0 --- .github/workflows/build-gpgui-nsh-linux.yaml | 50 +-- .github/workflows/build.yaml | 68 +++- .github/workflows/release.yaml | 13 +- .github/workflows/update-flake-hashes.yaml | 9 + Cargo.lock | 26 +- Cargo.toml | 2 +- Makefile | 42 ++- README.md | 8 +- apps/gpclient/src/cli.rs | 19 + apps/gpclient/src/launch_gui.rs | 19 +- apps/gpgui-helper/src-tauri/src/cli.rs | 17 +- apps/gpgui-helper/src-tauri/src/updater.rs | 40 +-- changelog.md | 8 + crates/gpapi/src/gui.rs | 31 +- crates/gpapi/src/process/desktop_child.rs | 9 +- crates/gpapi/src/process/desktop_launcher.rs | 63 +++- .../gpapi/src/process/gui_helper_launcher.rs | 2 +- crates/gpapi/src/process/gui_launcher.rs | 340 +++++++++++------- crates/gpapi/src/process/nsh_runtime.rs | 73 +++- flake.nix | 39 +- nix/ci.nix | 13 +- nix/gui-package.nix | 14 +- nix/tests/desktop-interfaces.nix | 92 +++++ nix/tests/native-runtime.nix | 1 + packaging/apk/APKBUILD.in | 3 + packaging/binary/Makefile.in | 5 +- packaging/deb/rules.in | 4 + .../rpm/globalprotect-openconnect.spec.in | 8 +- scripts/build-linux-nsh.sh | 38 ++ scripts/gh-release.sh | 9 +- scripts/prepare-release-promotion.sh | 2 +- scripts/release-assets.sh | 5 + scripts/tests/install-layout.sh | 14 +- scripts/tests/nix-desktop-authorization.sh | 1 + scripts/tests/test_release_flow.py | 42 ++- scripts/update-flake-hashes.sh | 8 + scripts/validate-release-version.py | 2 +- scripts/verify-linux-nsh-assets.sh | 19 + scripts/verify-linux-package.sh | 43 +++ 39 files changed, 903 insertions(+), 298 deletions(-) create mode 100644 nix/tests/desktop-interfaces.nix create mode 100755 scripts/build-linux-nsh.sh create mode 100755 scripts/verify-linux-nsh-assets.sh create mode 100755 scripts/verify-linux-package.sh diff --git a/.github/workflows/build-gpgui-nsh-linux.yaml b/.github/workflows/build-gpgui-nsh-linux.yaml index 478f040..347b5fc 100644 --- a/.github/workflows/build-gpgui-nsh-linux.yaml +++ b/.github/workflows/build-gpgui-nsh-linux.yaml @@ -27,13 +27,14 @@ jobs: strategy: fail-fast: false matrix: - include: + platform: - runner: ubuntu-24.04 arch: x86_64 - runner: ubuntu-24.04-arm arch: aarch64 - runs-on: ${{ matrix.runner }} - name: build (${{ matrix.arch }}) + suffix: ['', '-musl'] + runs-on: ${{ matrix.platform.runner }} + name: build (${{ matrix.platform.arch }}${{ matrix.suffix }}) timeout-minutes: 90 env: CARGO_INCREMENTAL: '0' @@ -62,6 +63,7 @@ jobs: ref: ${{ inputs.gpgui_ref }} path: source/gpgui - name: Install Ubuntu 24.04 dependencies + if: matrix.suffix == '' run: | sudo apt-get update sudo apt-get install -y autoconf automake gettext libtool pkg-config \ @@ -69,8 +71,10 @@ jobs: libgnutls28-dev liblz4-dev libwayland-dev libxkbcommon-dev libdbus-1-dev pkg-config --exists gtk4 gnutls dbus-1 wayland-client xkbcommon - name: Install the NSH compiler + if: matrix.suffix == '' run: rustup toolchain install 1.97.0 --profile minimal - name: Cache public crate downloads + if: matrix.suffix == '' uses: actions/cache@v5 with: path: | @@ -79,33 +83,39 @@ jobs: key: nsh-crates-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('source/gpgui/apps/desktop-nsh/Cargo.lock') }} restore-keys: nsh-crates-${{ runner.os }}-${{ runner.arch }}- - name: Build and package Native Shell + env: + LIBC_SUFFIX: ${{ matrix.suffix }} run: | trap 'code=$?; if [ "$code" -ne 0 ]; then echo "::error::Native Shell build failed; diagnostics suppressed."; fi' EXIT ( set -euo pipefail - cd source/gpgui - cargo +1.97.0 build --manifest-path apps/desktop-nsh/Cargo.toml --locked \ - --release --bin gpgui-nsh --target-dir target - target/release/gpgui-nsh --version - version="$(cargo +1.97.0 metadata --manifest-path apps/desktop-nsh/Cargo.toml --no-deps --format-version 1 \ - | jq -r '.packages[] | select(.name == "gpgui-nsh") | .version')" - directory="gpgui-nsh_$version" - archive="gpgui-nsh_$(uname -m).bin.tar.xz" - mkdir -p ".build/package/$directory" - cp target/release/gpgui-nsh ".build/package/$directory/" - cp apps/desktop-nsh/ICU4X-LICENSE.txt ".build/package/$directory/ICU4X-LICENSE.txt" - if ldd target/release/gpgui-nsh | grep -q 'libicu'; then - echo "The release executable must not depend on ICU4C." >&2 - exit 1 + if [[ "$LIBC_SUFFIX" == "-musl" ]]; then + docker run --rm --user root -v "$PWD/source:/source" -w /source/gpgui \ + -e GPGUI_BUILD_VERSION -e GPGUI_GIT_COMMIT -e GPGUI_UPDATE_CHANNEL \ + -e GPGUI_LICENSE_SIGNING_KEYS -e CARGO_INCREMENTAL -e CARGO_BUILD_JOBS \ + yuezk/gpdev:gpgui-alpine-builder-tauri2 bash -ec ' + apk add --no-cache clang clang-dev gtk4.0-dev dbus-dev wayland-dev libxkbcommon-dev + rustup toolchain install 1.97.0 --profile minimal + ../gp/scripts/build-linux-nsh.sh + ' + else + cd source/gpgui + ../gp/scripts/build-linux-nsh.sh fi - tar -cJf ".build/package/$archive" -C .build/package "$directory" - sha256sum ".build/package/$archive" | cut -d ' ' -f 1 > ".build/package/$archive.sha256" ) >/dev/null 2>&1 echo "Native Shell build and version check passed." + - name: Verify musl archive on Alpine + if: matrix.suffix == '-musl' + run: | + docker run --rm -v "$PWD/source/gpgui/.build/package:/assets:ro" alpine:3.23 sh -ec ' + apk add --no-cache gtk4.0 gnutls dbus-libs libgcc xz + tar -xJf "/assets/gpgui-nsh_$(uname -m)-musl.bin.tar.xz" + ./gpgui-nsh_*/gpgui-nsh --version >/dev/null 2>&1 + ' - name: Upload Native Shell uses: actions/upload-artifact@v7 with: - name: artifact-gpgui-nsh-${{ matrix.arch }} + name: artifact-gpgui-nsh${{ matrix.suffix }}-${{ matrix.platform.arch }} if-no-files-found: error path: | source/gpgui/.build/package/*.bin.tar.xz diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index fb51363..2efc24b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -311,14 +311,19 @@ jobs: if: ${{ !(startsWith(github.ref, 'refs/tags/') || (github.event_name == 'workflow_dispatch' && inputs.channel == 'stable')) }} needs: - tarball + - build-gpgui-glibc + - build-gpgui-musl + - build-gpgui-nsh strategy: fail-fast: false matrix: os: - runner: ubuntu-latest arch: amd64 + uname: x86_64 - runner: ubuntu-24.04-arm arch: ubuntu-24.04-arm + uname: aarch64 package: [deb, rpm, pkg, apk, binary, ubuntu-rolling] runs-on: ${{ matrix.os.runner }} name: build-gp (${{ matrix.package }}, ${{ matrix.os.arch }}) @@ -332,22 +337,41 @@ jobs: with: name: artifact-source path: build-gp-${{ matrix.package }} + - name: Download Tauri for this package + uses: actions/download-artifact@v8 + with: + name: artifact-gpgui${{ matrix.package == 'apk' && '-musl' || '' }}-${{ matrix.os.arch }} + path: gui-assets + - name: Download Native Shell for this package + uses: actions/download-artifact@v8 + with: + name: artifact-gpgui-nsh${{ matrix.package == 'apk' && '-musl' || '' }}-${{ matrix.os.uname }} + path: gui-assets - name: Build ${{ matrix.package }} package in Docker # LIBXML2_STATIC is needed to avoid the dynamic linking issue on different distros run: | docker run --rm \ -e COREPACK_INTEGRITY_KEYS=0 \ -e LIBXML2_STATIC=1 \ - -v $(pwd)/build-gp-${{ matrix.package }}:/workspace \ + -e INCLUDE_GUI=1 \ + -e GUI_ASSET_BASE=file:///gui-assets \ + -v "$PWD/gui-assets:/gui-assets:ro" \ + -v "$PWD/build-gp-${{ matrix.package }}:/workspace" \ yuezk/gpdev:${{ matrix.package }}-builder-tauri2 + - name: Checkout package verification script + uses: actions/checkout@v6 + with: + path: .ci + sparse-checkout: scripts + persist-credentials: false - name: Install ${{ matrix.package }} package in Docker run: | docker run --rm \ + -v "$PWD/.ci/scripts/verify-linux-package.sh:/verify-linux-package.sh:ro" \ -e COREPACK_INTEGRITY_KEYS=0 \ - -e GPGUI_INSTALLED=0 \ - -v $(pwd)/build-gp-${{ matrix.package }}:/workspace \ + -v "$PWD/build-gp-${{ matrix.package }}:/workspace" \ yuezk/gpdev:${{ matrix.package }}-builder-tauri2 \ - bash install.sh + bash -ec 'bash install.sh && bash /verify-linux-package.sh "$1"' _ "${{ matrix.package }}" # Don't upload package for ubuntu-rolling because it's duplicate of deb package - name: Upload ${{ matrix.package }} package if: ${{ matrix.package != 'ubuntu-rolling' }} @@ -498,16 +522,18 @@ jobs: WINDOWS_UPDATE_PRIVATE_KEY: ${{ secrets.WINDOWS_UPDATE_PRIVATE_KEY }} nix-source: - needs: [validate-inputs, build-gpgui-glibc] + needs: [validate-inputs, build-gpgui-glibc, build-gpgui-nsh] strategy: fail-fast: false matrix: platform: - runner: ubuntu-latest system: x86_64-linux + nsh_arch: x86_64 artifact_arch: amd64 - runner: ubuntu-24.04-arm system: aarch64-linux + nsh_arch: aarch64 artifact_arch: ubuntu-24.04-arm runs-on: ${{ matrix.platform.runner }} name: nix-source (${{ matrix.platform.system }}) @@ -527,6 +553,11 @@ jobs: with: name: artifact-gpgui-${{ matrix.platform.artifact_arch }} path: nix-artifacts/gui + - name: Download current Native Shell artifact + uses: actions/download-artifact@v8 + with: + name: artifact-gpgui-nsh-${{ matrix.platform.nsh_arch }} + path: nix-artifacts/nsh - name: Install Nix uses: cachix/install-nix-action@v31 - name: Configure current source and GUI inputs @@ -535,6 +566,9 @@ jobs: gui_archive=$(find "$PWD/nix-artifacts/gui" -name '*.bin.tar.xz' -type f) test -f "$gui_archive" echo "GP_GUI_ARCHIVE=$gui_archive" >> "$GITHUB_ENV" + nsh_archive="$PWD/nix-artifacts/nsh/gpgui-nsh_${{ matrix.platform.nsh_arch }}.bin.tar.xz" + test -f "$nsh_archive" + echo "GP_NSH_ARCHIVE=$nsh_archive" >> "$GITHUB_ENV" - name: Build source package run: | nix build --impure --file gp/nix/ci.nix source \ @@ -547,16 +581,18 @@ jobs: --extra-experimental-features "nix-command flakes" --print-build-logs nix-prebuilt: - needs: [validate-inputs, build-gp, build-gpgui-glibc] + needs: [validate-inputs, build-gp, build-gpgui-glibc, build-gpgui-nsh] strategy: fail-fast: false matrix: platform: - runner: ubuntu-latest system: x86_64-linux + nsh_arch: x86_64 artifact_arch: amd64 - runner: ubuntu-24.04-arm system: aarch64-linux + nsh_arch: aarch64 artifact_arch: ubuntu-24.04-arm nixpkgs: [locked, nixos-25.11, nixos-26.05, nixpkgs-unstable] runs-on: ${{ matrix.platform.runner }} @@ -582,6 +618,11 @@ jobs: with: name: artifact-gpgui-${{ matrix.platform.artifact_arch }} path: nix-artifacts/gui + - name: Download current Native Shell artifact + uses: actions/download-artifact@v8 + with: + name: artifact-gpgui-nsh-${{ matrix.platform.nsh_arch }} + path: nix-artifacts/nsh - name: Install Nix uses: cachix/install-nix-action@v31 - name: Configure current artifact inputs @@ -593,6 +634,9 @@ jobs: test -f "$gui_archive" echo "GP_BINARY_ARCHIVE=$binary_archive" >> "$GITHUB_ENV" echo "GP_GUI_ARCHIVE=$gui_archive" >> "$GITHUB_ENV" + nsh_archive="$PWD/nix-artifacts/nsh/gpgui-nsh_${{ matrix.platform.nsh_arch }}.bin.tar.xz" + test -f "$nsh_archive" + echo "GP_NSH_ARCHIVE=$nsh_archive" >> "$GITHUB_ENV" - name: Build package through host NixOS module run: | nix build --impure --file gp/nix/ci.nix module \ @@ -603,10 +647,20 @@ jobs: run: | nix build --impure --file gp/nix/ci.nix prebuilt \ --extra-experimental-features "nix-command flakes" --print-build-logs + - name: Install and run downloaded Native Shell through the Nix installer + if: matrix.nixpkgs == 'locked' + run: | + gui_archive="$GP_NSH_ARCHIVE" + target="$RUNNER_TEMP/nix-gui-install/gpgui-nsh" + mkdir -p "$(dirname "$target")" + checksum=$(sha256sum "$gui_archive" | cut -d ' ' -f1) + result/libexec/gpclient/gp-gui-installer "$gui_archive" "$checksum" "$target" + test -L "$target" + test "$("$target" --version)" = "$(result/bin/gpgui-nsh --version)" - name: Test prebuilt runtime in NixOS if: matrix.nixpkgs == 'locked' && matrix.platform.system == 'x86_64-linux' run: | - nix build --impure --file gp/nix/ci.nix runtime-prebuilt \ + nix build --impure --file gp/nix/ci.nix runtime-prebuilt graphical-prebuilt \ --extra-experimental-features "nix-command flakes" --print-build-logs build-macos: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 07e90cd..838b2e0 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -127,19 +127,26 @@ jobs: # LIBXML2_STATIC is needed to avoid the dynamic linking issue on different distros run: | docker run --rm \ - -v $(pwd)/build-${{ matrix.package }}:/workspace \ + -v "$PWD/build-${{ matrix.package }}:/workspace" \ -e COREPACK_INTEGRITY_KEYS=0 \ -e LIBXML2_STATIC=1 \ -e INCLUDE_GUI=1 \ yuezk/gpdev:${{ matrix.package }}-builder-tauri2 + - name: Checkout package verification script + uses: actions/checkout@v6 + with: + path: .ci + sparse-checkout: scripts + persist-credentials: false - name: Install ${{ matrix.package }} package in Docker run: | docker run --rm \ + -v "$PWD/.ci/scripts/verify-linux-package.sh:/verify-linux-package.sh:ro" \ -e COREPACK_INTEGRITY_KEYS=0 \ - -v $(pwd)/build-${{ matrix.package }}:/workspace \ + -v "$PWD/build-${{ matrix.package }}:/workspace" \ yuezk/gpdev:${{ matrix.package }}-builder-tauri2 \ - bash install.sh + bash -ec 'bash install.sh && bash /verify-linux-package.sh "$1"' _ "${{ matrix.package }}" - name: Upload ${{ matrix.package }} package uses: actions/upload-artifact@v7 diff --git a/.github/workflows/update-flake-hashes.yaml b/.github/workflows/update-flake-hashes.yaml index d082f22..7d29de8 100644 --- a/.github/workflows/update-flake-hashes.yaml +++ b/.github/workflows/update-flake-hashes.yaml @@ -62,6 +62,15 @@ jobs: }, indent=2) + '\n') PYRELEASE + - name: Verify all published Native Shell downloads before promotion + env: + GH_TOKEN: ${{ github.token }} + RELEASE_TAG: ${{ steps.release.outputs.release_tag }} + run: | + gh release download "$RELEASE_TAG" --repo yuezk/GlobalProtect-openconnect \ + --pattern 'gpgui-nsh_*.bin.tar.xz*' --dir "$RUNNER_TEMP/nsh-release" + scripts/verify-linux-nsh-assets.sh "$RUNNER_TEMP/nsh-release" + - name: Install Nix uses: cachix/install-nix-action@v31 diff --git a/Cargo.lock b/Cargo.lock index bf55386..000b87b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -292,7 +292,7 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "auth" -version = "3.6.0" +version = "3.7.0" dependencies = [ "anyhow", "block2", @@ -554,7 +554,7 @@ dependencies = [ [[package]] name = "browser-launcher" -version = "3.6.0" +version = "3.7.0" dependencies = [ "anyhow", "log", @@ -919,7 +919,7 @@ dependencies = [ [[package]] name = "common" -version = "3.6.0" +version = "3.7.0" dependencies = [ "tempfile", ] @@ -2133,7 +2133,7 @@ dependencies = [ [[package]] name = "gp-xml" -version = "3.6.0" +version = "3.7.0" dependencies = [ "url", "xmltree", @@ -2141,7 +2141,7 @@ dependencies = [ [[package]] name = "gpapi" -version = "3.6.0" +version = "3.7.0" dependencies = [ "anyhow", "base64 0.23.1", @@ -2205,7 +2205,7 @@ dependencies = [ [[package]] name = "gpauth" -version = "3.6.0" +version = "3.7.0" dependencies = [ "anyhow", "auth", @@ -2223,7 +2223,7 @@ dependencies = [ [[package]] name = "gpclient" -version = "3.6.0" +version = "3.7.0" dependencies = [ "anyhow", "clap", @@ -2254,7 +2254,7 @@ dependencies = [ [[package]] name = "gpgui-helper" -version = "3.6.0" +version = "3.7.0" dependencies = [ "anyhow", "clap", @@ -2275,7 +2275,7 @@ dependencies = [ [[package]] name = "gphip" -version = "3.6.0" +version = "3.7.0" dependencies = [ "anyhow", "askama", @@ -2294,7 +2294,7 @@ dependencies = [ [[package]] name = "gpservice" -version = "3.6.0" +version = "3.7.0" dependencies = [ "anyhow", "axum", @@ -2332,7 +2332,7 @@ dependencies = [ [[package]] name = "gptunnel" -version = "3.6.0" +version = "3.7.0" dependencies = [ "gpapi", "log", @@ -2344,7 +2344,7 @@ dependencies = [ [[package]] name = "gpvpnc" -version = "3.6.0" +version = "3.7.0" dependencies = [ "base64 0.23.1", "ipnet", @@ -3860,7 +3860,7 @@ dependencies = [ [[package]] name = "openconnect" -version = "3.6.0" +version = "3.7.0" dependencies = [ "autotools", "cc", diff --git a/Cargo.toml b/Cargo.toml index f677fb5..0d53833 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ [workspace.package] rust-version = "1.91" -version = "3.6.0" +version = "3.7.0" authors = ["Kevin Yue "] homepage = "https://github.com/yuezk/GlobalProtect-openconnect" edition = "2024" diff --git a/Makefile b/Makefile index 3c6b085..e1dd239 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ SOURCE_COMMIT_VALUE := $(shell \ git rev-parse --short=9 HEAD 2>/dev/null || printf unknown; \ fi) GUI_LIBC_SUFFIX ?= $(shell ldd --version 2>&1 | grep -qi musl && echo -musl || true) +GUI_ASSET_BASE ?= https://github.com/yuezk/GlobalProtect-openconnect/releases/download/$(RELEASE_TAG) REVISION ?= 1 RPM_SOURCE ?= %{name}.tar.gz @@ -33,16 +34,21 @@ PUBLISH ?= 0 # Indicates whether to build the GUI components BUILD_GUI_HELPER ?= 1 -# Indicates whether to build embedded webview auth support into gpauth +# Build embedded webview authentication support into gpclient and gpauth BUILD_WEBVIEW_AUTH ?= 1 +ifneq ($(BUILD_WEBVIEW_AUTH),1) +AUTH_FEATURE_ARGS = --no-default-features +endif + ifeq ($(shell uname -s),Linux) PREFIX ?= /usr -GPGUI_BINARY ?= $(wildcard .build/gpgui/gpgui_*/gpgui) +GPGUI_BINARY ?= .build/gpgui/gpgui_$(VERSION)/gpgui else ifeq ($(shell uname -s)-$(shell uname -m),Darwin-arm64) PREFIX ?= /opt/homebrew else PREFIX ?= /usr/local endif +NSH_BUNDLE_DIR = .build/gpgui/gpgui-nsh_$(VERSION) BSD_FLAVOR ?= $(shell uname -s | tr '[:upper:]' '[:lower:]') GPGUI_BINARY ?= ../gpgui/target/release/gpgui @@ -109,9 +115,14 @@ download-gui: if [ $(INCLUDE_GUI) -eq 1 ]; then \ echo "Downloading GlobalProtect GUI..."; \ mkdir -p .build/gpgui; \ - curl -sSL https://github.com/yuezk/GlobalProtect-openconnect/releases/download/$(RELEASE_TAG)/gpgui_$(shell uname -m)$(GUI_LIBC_SUFFIX).bin.tar.xz \ - -o .build/gpgui/gpgui_$(shell uname -m)$(GUI_LIBC_SUFFIX).bin.tar.xz; \ - tar -xJf .build/gpgui/*.tar.xz -C .build/gpgui; \ + set -e; cd .build/gpgui; \ + for gui in gpgui gpgui-nsh; do \ + archive="$${gui}_$(shell uname -m)$(GUI_LIBC_SUFFIX).bin.tar.xz"; \ + curl -fsSL "$(GUI_ASSET_BASE)/$$archive" -o "$$archive"; \ + digest=$$(curl -fsSL "$(GUI_ASSET_BASE)/$$archive.sha256"); \ + printf '%s %s\n' "$$digest" "$$archive" | sha256sum -c -; \ + tar -xJf "$$archive"; \ + done; \ else \ echo "Skipping GlobalProtect GUI download (INCLUDE_GUI=0)"; \ fi @@ -128,14 +139,7 @@ build-rs: rm -vf rust-toolchain.toml; \ fi - $(CARGO) build $(CARGO_BUILD_ARGS) -p gpclient -p gpservice - - # Build gpauth with or without embedded webview auth support - if [ $(BUILD_WEBVIEW_AUTH) -eq 1 ]; then \ - $(CARGO) build $(CARGO_BUILD_ARGS) -p gpauth; \ - else \ - $(CARGO) build $(CARGO_BUILD_ARGS) -p gpauth --no-default-features; \ - fi + $(CARGO) build $(CARGO_BUILD_ARGS) $(AUTH_FEATURE_ARGS) -p gpclient -p gpservice -p gpauth # Only build the GUI components if BUILD_GUI_HELPER is set to 1 if [ $(BUILD_GUI_HELPER) -eq 1 ]; then \ @@ -197,6 +201,12 @@ install-unix: install-gpclient-unix done install-linux: install-unix +ifeq ($(INCLUDE_GUI),1) + test -x "$(GPGUI_BINARY)" + install -m 755 "$(NSH_BUNDLE_DIR)/gpgui-nsh" "$(DESTDIR)$(PREFIX)/bin/gpgui-nsh" + install -d "$(DESTDIR)$(PREFIX)/share/licenses/$(PKG_NAME)" + install -m 644 "$(NSH_BUNDLE_DIR)/ICU4X-LICENSE.txt" "$(DESTDIR)$(PREFIX)/share/licenses/$(PKG_NAME)/" +endif @echo "Installing Linux integration under $(PREFIX)..." set -e; for file in share/applications/gpgui.desktop \ share/applications/gpgui-helper.desktop \ @@ -327,6 +337,8 @@ uninstall-unix: rmdir "$(DESTDIR)$(PREFIX)/libexec/gpclient" 2>/dev/null || true uninstall-linux: uninstall-unix + rm -f "$(DESTDIR)$(PREFIX)/bin/gpgui-nsh" "$(DESTDIR)$(PREFIX)/share/licenses/$(PKG_NAME)/ICU4X-LICENSE.txt" + rmdir "$(DESTDIR)$(PREFIX)/share/licenses/$(PKG_NAME)" 2>/dev/null || true rm -f "$(DESTDIR)$(PREFIX)/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down" \ "$(DESTDIR)$(PREFIX)/lib/NetworkManager/dispatcher.d/gpclient-nm-hook" rm -f "$(DESTDIR)/var/lib/gpclient/gpgui" \ @@ -429,7 +441,7 @@ rpm: init-rpm tarball rpmdev-setuptree cp .build/tarball/${PKG}.tar.gz $(HOME)/rpmbuild/SOURCES/${PKG_NAME}.tar.gz - rpmbuild -ba .build/rpm/globalprotect-openconnect.spec + rpmbuild --define "include_gui $(INCLUDE_GUI)" -ba .build/rpm/globalprotect-openconnect.spec # Copy RPM package from build directory cp $(HOME)/rpmbuild/RPMS/$(shell uname -m)/$(PKG_NAME)*.rpm .build/rpm @@ -499,7 +511,7 @@ binary: clean-binary tarball mkdir -p .build/binary/$(PKG_NAME)_$(VERSION)/artifacts make -C .build/binary/${PKG} build INCLUDE_GUI=$(INCLUDE_GUI) - make -C .build/binary/${PKG} install DESTDIR=$(PWD)/.build/binary/$(PKG_NAME)_$(VERSION)/artifacts + make -C .build/binary/${PKG} install INCLUDE_GUI=$(INCLUDE_GUI) DESTDIR=$(PWD)/.build/binary/$(PKG_NAME)_$(VERSION)/artifacts cp packaging/binary/Makefile.in .build/binary/$(PKG_NAME)_$(VERSION)/Makefile diff --git a/README.md b/README.md index e46ba56..fd518a8 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,9 @@ Run `gpclient --help` or `gpclient --help` to view all available comma ``` > [!TIP] -> **On Linux, try Native Shell for lower memory usage.** Switch between Native Shell and Tauri in **Settings → General → Interface**. +> On Linux, GP Connect uses Native Shell when your system supports it. Your saved interface choice takes priority. Switch while disconnected in **Settings → General → Interface**. +> +> If the window stays blank, fully quit GP Connect and run `gpclient launch-gui --interface tauri`. To select Native Shell, use `--interface nsh`. The choice is saved when the interface starts. ## Installation @@ -252,7 +254,7 @@ sudo make install - [Rust](https://www.rust-lang.org/tools/install) 1.91 or later - Build tools: `make`, `pkg-config`, `autoconf`, `automake`, `libtool`, `gettext` -- Libraries: `gmp`, `gnutls`, `nettle`, `libxml2`, `zlib`, `lz4`, `p11-kit`, `libsecret`, and `webkit2gtk-4.1` (or GTK 4 for Native Shell) +- Libraries: `gmp`, `gnutls`, `nettle`, `libxml2`, `zlib`, `lz4`, `p11-kit`, `libsecret`, and `webkit2gtk-4.1` for the embedded sign-in window and download helper. Native Shell also requires GTK 4.14 or later. The generic glibc build requires glibc 2.39 or later - Polkit (`pkexec`) for privileged tunnel setup *(For FreeBSD and OpenBSD instructions, see [Building from Source on FreeBSD and OpenBSD](docs/bsd-source-build.md)).* @@ -269,7 +271,7 @@ sudo make install **Build Options:** - `INCLUDE_GUI=1` – Download and install the matching desktop application bundle. -- `BUILD_WEBVIEW_AUTH=0` – Build `gpauth` without embedded browser authentication (uses external browser or manual mode). +- `BUILD_WEBVIEW_AUTH=0` – Disable embedded browser authentication in both `gpclient` and `gpauth`. External-browser and manual sign-in remain available. - `BUILD_GUI_HELPER=0` – Skip building the helper UI. ## Troubleshooting diff --git a/apps/gpclient/src/cli.rs b/apps/gpclient/src/cli.rs index 3b01619..0a6f0ef 100644 --- a/apps/gpclient/src/cli.rs +++ b/apps/gpclient/src/cli.rs @@ -486,6 +486,25 @@ mod tests { assert!(cli.can_run_alongside_client()); } + #[test] + #[cfg(target_os = "linux")] + fn launch_gui_interface_accepts_minimized_launch_but_not_an_auth_callback() { + for variant in ["tauri", "nsh"] { + assert!(Cli::try_parse_from(["gpclient", "launch-gui", "--interface", variant, "--minimized"]).is_ok()); + assert!( + Cli::try_parse_from([ + "gpclient", + "launch-gui", + "--interface", + variant, + "globalprotectcallback:token" + ]) + .is_err() + ); + } + assert!(Cli::try_parse_from(["gpclient", "launch-gui", "--interface", "unknown"]).is_err()); + } + #[test] #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))] fn launch_gui_rejects_callback_with_minimized() { diff --git a/apps/gpclient/src/launch_gui.rs b/apps/gpclient/src/launch_gui.rs index 5109745..8253301 100644 --- a/apps/gpclient/src/launch_gui.rs +++ b/apps/gpclient/src/launch_gui.rs @@ -24,6 +24,14 @@ pub(crate) struct LaunchGuiArgs { help = "The external-browser authentication callback URL" )] callback: Option, + #[cfg(target_os = "linux")] + #[arg( + long, + value_enum, + conflicts_with = "callback", + help = "Launch this interface and remember it for future launches" + )] + interface: Option, #[arg(long, help = "Launch the GUI minimized")] minimized: bool, } @@ -61,7 +69,10 @@ impl<'a> LaunchGuiHandler<'a> { return forward_auth_callback(callback); } - if DesktopLauncher::activate_existing().await.is_ok() { + let launcher = DesktopLauncher::new(env!("CARGO_PKG_VERSION")).minimized(self.args.minimized); + #[cfg(target_os = "linux")] + let launcher = launcher.interface(self.args.interface); + if launcher.activate_or_reject_existing().await? { info!("The GUI is already running"); return Ok(()); } @@ -71,11 +82,7 @@ impl<'a> LaunchGuiHandler<'a> { info!("Log file: {}", log_file_path); - let exit_status = DesktopLauncher::new(env!("CARGO_PKG_VERSION")) - .minimized(self.args.minimized) - .log_file(&log_file_path) - .launch() - .await?; + let exit_status = launcher.log_file(&log_file_path).launch().await?; info!("Service exited with status: {}", exit_status); diff --git a/apps/gpgui-helper/src-tauri/src/cli.rs b/apps/gpgui-helper/src-tauri/src/cli.rs index 7ae5e27..7009d9b 100644 --- a/apps/gpgui-helper/src-tauri/src/cli.rs +++ b/apps/gpgui-helper/src-tauri/src/cli.rs @@ -4,7 +4,7 @@ use std::{io::Read, sync::Arc}; use anyhow::{Context, bail}; use gpapi::{ clap::InfoLevelVerbosity, - gui::GuiTheme, + gui::{GuiTheme, GuiVariant, NATIVE_SHELL_SUPPORTED}, service::transport::{MAX_CREDENTIAL_FRAME, SessionCredential}, utils::env_utils, }; @@ -30,8 +30,8 @@ struct Cli { #[arg(long, default_value = env!("CARGO_PKG_VERSION"), help = "The version of the GUI")] gui_version: String, - #[arg(long, default_value = "tauri", value_parser = ["tauri", "nsh"])] - gui_variant: String, + #[arg(long, value_enum, default_value_t = GuiVariant::Tauri)] + gui_variant: GuiVariant, #[arg(long, value_enum, default_value = "system", help = "Window appearance")] theme: GuiTheme, @@ -44,20 +44,15 @@ impl Cli { fn run(&self) -> anyhow::Result<()> { let credential = self.read_credential()?; let credential_lease = monitor_credential_lease().context("Failed to monitor service credential lifetime")?; - let variant = if self.gui_variant == "nsh" { - gpapi::gui::GuiVariant::Nsh - } else { - gpapi::gui::GuiVariant::Tauri - }; anyhow::ensure!( - variant != gpapi::gui::GuiVariant::Nsh || cfg!(target_os = "linux"), - "Native Shell is available only on Linux" + self.gui_variant != GuiVariant::Nsh || NATIVE_SHELL_SUPPORTED, + "Native Shell is unavailable for this platform" ); let app = App::new( Arc::new(credential), credential_lease, &self.gui_version, - variant, + self.gui_variant, self.theme, ); diff --git a/apps/gpgui-helper/src-tauri/src/updater.rs b/apps/gpgui-helper/src-tauri/src/updater.rs index 67650fd..6c1de5f 100644 --- a/apps/gpgui-helper/src-tauri/src/updater.rs +++ b/apps/gpgui-helper/src-tauri/src/updater.rs @@ -42,22 +42,17 @@ const GUI_LIBC_SUFFIX: &str = "-musl"; const GUI_LIBC_SUFFIX: &str = ""; fn gui_asset_name(variant: gpapi::gui::GuiVariant) -> Option { + gui_asset_name_for(variant, std::env::consts::OS, std::env::consts::ARCH, GUI_LIBC_SUFFIX) +} + +fn gui_asset_name_for(variant: gpapi::gui::GuiVariant, os: &str, arch: &str, libc_suffix: &str) -> Option { + if os == "linux" && matches!(arch, "x86_64" | "aarch64") { + return Some(format!("{}_{arch}{libc_suffix}.bin.tar.xz", variant.binary_name())); + } if variant == gpapi::gui::GuiVariant::Nsh { - return nsh_asset_name_for(std::env::consts::OS, std::env::consts::ARCH); + return None; } - gui_asset_name_for(std::env::consts::OS, std::env::consts::ARCH, GUI_LIBC_SUFFIX) -} - -fn nsh_asset_name_for(os: &str, arch: &str) -> Option { - match (os, arch) { - ("linux", "x86_64" | "aarch64") => Some(format!("gpgui-nsh_{arch}.bin.tar.xz")), - _ => None, - } -} - -fn gui_asset_name_for(os: &str, arch: &str, libc_suffix: &str) -> Option { let name = match (os, arch) { - ("linux", "x86_64" | "aarch64") => format!("gpgui_{arch}{libc_suffix}.bin.tar.xz"), ("freebsd", "x86_64") => "gpgui_freebsd_amd64.bin.tar.xz".to_owned(), ("freebsd", "aarch64") => "gpgui_freebsd_arm64.bin.tar.xz".to_owned(), ("openbsd", "x86_64") => "gpgui_openbsd_amd64.bin.tar.xz".to_owned(), @@ -506,6 +501,7 @@ impl GuiUpdater { #[cfg(test)] mod tests { + use gpapi::gui::GuiVariant; use gpapi::service::{ transport::{ClientPrelude, NoiseResponder}, vpn_env::{HostInfo, VpnEnv}, @@ -519,36 +515,36 @@ mod tests { #[test] fn selects_platform_specific_gui_assets() { assert_eq!( - gui_asset_name_for("linux", "x86_64", ""), + gui_asset_name_for(GuiVariant::Tauri, "linux", "x86_64", ""), Some("gpgui_x86_64.bin.tar.xz".to_owned()) ); assert_eq!( - gui_asset_name_for("linux", "aarch64", "-musl"), + gui_asset_name_for(GuiVariant::Tauri, "linux", "aarch64", "-musl"), Some("gpgui_aarch64-musl.bin.tar.xz".to_owned()) ); assert_eq!( - gui_asset_name_for("freebsd", "x86_64", ""), + gui_asset_name_for(GuiVariant::Tauri, "freebsd", "x86_64", ""), Some("gpgui_freebsd_amd64.bin.tar.xz".to_owned()) ); assert_eq!( - gui_asset_name_for("openbsd", "aarch64", ""), + gui_asset_name_for(GuiVariant::Tauri, "openbsd", "aarch64", ""), Some("gpgui_openbsd_arm64.bin.tar.xz".to_owned()) ); - assert_eq!(gui_asset_name_for("macos", "aarch64", ""), None); + assert_eq!(gui_asset_name_for(GuiVariant::Tauri, "macos", "aarch64", ""), None); } #[test] fn nsh_assets_are_linux_only_and_use_the_nsh_binary_archive() { assert_eq!( - nsh_asset_name_for("linux", "x86_64"), + gui_asset_name_for(GuiVariant::Nsh, "linux", "x86_64", ""), Some("gpgui-nsh_x86_64.bin.tar.xz".into()) ); assert_eq!( - nsh_asset_name_for("linux", "aarch64"), - Some("gpgui-nsh_aarch64.bin.tar.xz".into()) + gui_asset_name_for(GuiVariant::Nsh, "linux", "aarch64", "-musl"), + Some("gpgui-nsh_aarch64-musl.bin.tar.xz".into()) ); for os in ["freebsd", "openbsd", "macos"] { - assert_eq!(nsh_asset_name_for(os, "x86_64"), None); + assert_eq!(gui_asset_name_for(GuiVariant::Nsh, os, "x86_64", ""), None); } } diff --git a/changelog.md b/changelog.md index fdd36d5..84ed312 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,13 @@ # Changelog +## 3.7.0 + +- Linux now opens Native Shell by default on supported systems, including Alpine. Upgrades keep your saved interface choice. +- To choose an interface after quitting GP Connect, run `gpclient launch-gui --interface tauri` or `gpclient launch-gui --interface nsh`. +- Linux packages include both Native Shell and Tauri so you can switch interfaces without a separate download. +- The README now documents source and prebuilt installation from the Gentoo overlay. +- Source builds with `BUILD_WEBVIEW_AUTH=0` disable embedded browser sign-in in both `gpclient` and `gpauth`. + ## 3.6.0 - Added command-line VPN connections on Windows x64 and ARM64. diff --git a/crates/gpapi/src/gui.rs b/crates/gpapi/src/gui.rs index 44a475f..1f1e95f 100644 --- a/crates/gpapi/src/gui.rs +++ b/crates/gpapi/src/gui.rs @@ -4,6 +4,7 @@ use specta::Type; use std::path::PathBuf; #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Type)] +#[cfg_attr(feature = "clap", derive(clap::ValueEnum))] #[serde(rename_all = "kebab-case")] pub enum GuiVariant { #[default] @@ -77,21 +78,23 @@ fn preference_path(name: &str) -> anyhow::Result { Ok(dirs.config_dir().join(name)) } -pub fn preferred() -> anyhow::Result { - #[cfg(target_os = "linux")] - { - match std::fs::read_to_string(preference_path("gui")?) { - Ok(value) => match value.trim() { - "gpgui" => Ok(GuiVariant::Tauri), - "gpgui-nsh" => Ok(GuiVariant::Nsh), - _ => anyhow::bail!("Invalid GUI preference"), - }, - Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(GuiVariant::Tauri), - Err(error) => Err(error.into()), - } +pub const NATIVE_SHELL_SUPPORTED: bool = cfg!(all( + target_os = "linux", + any(target_arch = "x86_64", target_arch = "aarch64"), + any(target_env = "gnu", target_env = "musl") +)); + +#[cfg(target_os = "linux")] +pub(crate) fn saved_preference() -> anyhow::Result> { + match std::fs::read_to_string(preference_path("gui")?) { + Ok(value) => match value.trim() { + "gpgui" => Ok(Some(GuiVariant::Tauri)), + "gpgui-nsh" => Ok(Some(GuiVariant::Nsh)), + _ => anyhow::bail!("Invalid GUI preference"), + }, + Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(None), + Err(error) => Err(error.into()), } - #[cfg(not(target_os = "linux"))] - Ok(GuiVariant::Tauri) } #[cfg(target_os = "linux")] diff --git a/crates/gpapi/src/process/desktop_child.rs b/crates/gpapi/src/process/desktop_child.rs index 88ba362..bb7e111 100644 --- a/crates/gpapi/src/process/desktop_child.rs +++ b/crates/gpapi/src/process/desktop_child.rs @@ -5,7 +5,7 @@ use super::{ is_crash_exit, }, }; -use crate::service::transport::SessionCredential; +use crate::{gui::GuiVariant, service::transport::SessionCredential}; use anyhow::Context; use std::{ cell::Cell, @@ -23,10 +23,11 @@ pub(super) async fn launch_desktop_child( envs: Option<&HashMap>, credential: &SessionCredential, cancellation: &CancellationToken, - detect_gbm_failure: bool, + interface: Option, ) -> anyhow::Result { - let retry_eligible = eligible_with_inheritance(&command, envs.is_none()); - let detect_gbm_failure = detect_gbm_failure && allows_shared_memory_override(&command, envs.is_none()); + let retry_eligible = interface != Some(GuiVariant::Nsh) && eligible_with_inheritance(&command, envs.is_none()); + let detect_gbm_failure = + interface == Some(GuiVariant::Tauri) && allows_shared_memory_override(&command, envs.is_none()); let log_file = match envs { Some(envs) => envs.get("GP_LOG_FILE").map(PathBuf::from), None => std::env::var_os("GP_LOG_FILE").map(PathBuf::from), diff --git a/crates/gpapi/src/process/desktop_launcher.rs b/crates/gpapi/src/process/desktop_launcher.rs index 0668e05..17f1ec9 100644 --- a/crates/gpapi/src/process/desktop_launcher.rs +++ b/crates/gpapi/src/process/desktop_launcher.rs @@ -24,26 +24,48 @@ use crate::service::transport::{MAX_CREDENTIAL_FRAME, SessionCredential}; /// Owns the desktop GUI and its privileged service without leaving the desktop session. pub struct DesktopLauncher<'a> { version: &'a str, + #[cfg(target_os = "linux")] + interface: Option, minimized: bool, log_file: Option, } impl<'a> DesktopLauncher<'a> { - /// Bring an already-running GUI to the foreground through its service. - pub async fn activate_existing() -> anyhow::Result<()> { - let endpoint = crate::utils::endpoint::http_endpoint().await?; - crate::utils::request::client_builder() - .build()? - .post(format!("{endpoint}/active-gui")) - .send() - .await? - .error_for_status()?; - Ok(()) + /// Plain launches raise the existing window. Explicit selections require a cold launch. + pub async fn activate_or_reject_existing(&self) -> anyhow::Result { + let Ok(endpoint) = crate::utils::endpoint::http_endpoint().await else { + return Ok(false); + }; + let client = crate::utils::request::client_builder().no_proxy().build()?; + #[cfg(target_os = "linux")] + if self.interface.is_some() { + let response = client.get(format!("{endpoint}/health")).send().await; + ensure!( + !response.is_ok_and(|r| r.status().is_success()), + "GP Connect is already running. Quit GP Connect and run this command again." + ); + return Ok(false); + } + Ok( + client + .post(format!("{endpoint}/active-gui")) + .send() + .await + .is_ok_and(|r| r.status().is_success()), + ) + } + + #[cfg(target_os = "linux")] + pub fn interface(mut self, interface: Option) -> Self { + self.interface = interface; + self } pub fn new(version: &'a str) -> Self { Self { version, + #[cfg(target_os = "linux")] + interface: None, minimized: false, log_file: None, } @@ -87,6 +109,8 @@ impl<'a> DesktopLauncher<'a> { let result = { let operation = async { let mut minimized = self.minimized; + #[cfg(target_os = "linux")] + let mut explicit_interface = self.interface; let mut expecting_renewal = false; loop { let credential = tokio::select! { @@ -119,15 +143,27 @@ impl<'a> DesktopLauncher<'a> { if let Some(path) = &self.log_file { envs.insert("GP_LOG_FILE".into(), path.clone()); } - let launcher = GuiLauncher::new(self.version, Arc::new(credential), crate::gui::preferred()?) - .envs(envs) - .minimized(minimized); #[cfg(not(target_os = "linux"))] let mut unexpected = [0]; // Program resolution may launch the WebKit download helper. Keep it under // the same cancellation, service ownership and recovery budget as gpgui. let outcome = { let attempt = async { + #[cfg(target_os = "linux")] + let variant = { + let requested = match explicit_interface { + Some(variant) => Some(variant), + None => crate::gui::saved_preference()?, + }; + super::nsh_runtime::select(requested, &mut input, &mut output) + .await + .context(super::nsh_runtime::TAURI_RECOVERY)? + }; + #[cfg(not(target_os = "linux"))] + let variant = crate::gui::GuiVariant::Tauri; + let launcher = GuiLauncher::new(self.version, Arc::new(credential), variant) + .envs(envs) + .minimized(minimized); let program = launcher .resolve_program(&cancellation, crate::gui::GuiTheme::System) .await?; @@ -137,6 +173,7 @@ impl<'a> DesktopLauncher<'a> { &program, &cancellation, &switch_listener.listener, + &mut explicit_interface, &mut input, &mut output, ) diff --git a/crates/gpapi/src/process/gui_helper_launcher.rs b/crates/gpapi/src/process/gui_helper_launcher.rs index 0c969ba..bbb8055 100644 --- a/crates/gpapi/src/process/gui_helper_launcher.rs +++ b/crates/gpapi/src/process/gui_helper_launcher.rs @@ -79,7 +79,7 @@ impl<'a> GuiHelperLauncher<'a> { self.envs, self.credential, cancellation, - false, + None, ) .await?; Ok(()) diff --git a/crates/gpapi/src/process/gui_launcher.rs b/crates/gpapi/src/process/gui_launcher.rs index 8bd825c..8fca546 100644 --- a/crates/gpapi/src/process/gui_launcher.rs +++ b/crates/gpapi/src/process/gui_launcher.rs @@ -5,6 +5,8 @@ use std::{ sync::Arc, }; +#[cfg(target_os = "linux")] +use anyhow::Context; use anyhow::bail; use log::info; use tokio::process::Command; @@ -113,12 +115,12 @@ impl<'a> GuiLauncher<'a> { } info!("Launching {}", program.display()); super::desktop_child::launch_desktop_child( - "gpgui", + self.variant.binary_name(), cmd.into_std(), self.envs.as_ref(), &self.credential, cancellation, - self.variant == crate::gui::GuiVariant::Tauri, + Some(self.variant), ) .await } @@ -172,6 +174,7 @@ impl<'a> GuiLauncher<'a> { program: &Path, cancellation: &CancellationToken, listener: &tokio::net::UnixListener, + explicit_interface: &mut Option, service_input: &mut (impl tokio::io::AsyncWrite + Unpin), service_output: &mut (impl tokio::io::AsyncRead + Unpin), ) -> anyhow::Result { @@ -179,119 +182,111 @@ impl<'a> GuiLauncher<'a> { use crate::gui::GuiSwitchOutcome; use crate::service::transport::{DESKTOP_SWITCH_BEGIN, DESKTOP_SWITCH_CANCEL, DESKTOP_SWITCH_COMMIT}; use tokio::io::{AsyncReadExt, AsyncWriteExt}; - let mut current = Some(self.start_owned(program.to_owned(), cancellation.child_token())); + let mut cold_nsh = self.variant == crate::gui::GuiVariant::Nsh; + let first = if explicit_interface.is_some() { + let started = self.start_and_save(program, cancellation).await; + let child = if cold_nsh { + started.context(super::nsh_runtime::TAURI_RECOVERY)? + } else { + started? + }; + *explicit_interface = None; + child + } else { + self.start_owned(program, cancellation.child_token(), None) + }; + let mut current = Some(first); let mut retired = Vec::new(); let mut unexpected = [0]; - let result = async { loop { - tokio::select! { - biased; - outcome = &mut current.as_mut().unwrap().task => { - current.take(); - break outcome?; - } - accepted = listener.accept() => { - let (mut socket, _) = accepted?; - let mut pending = false; - let replacement = async { - let command = gui_switch::receive(&mut socket).await?; - let selection = command.selection; - let variant = selection.variant; - let candidate = Self::new(self.version, self.credential.clone(), variant).envs(self.envs.clone()); - let program = candidate.find_compatible_program(cancellation).await?; - if program.is_none() && variant == crate::gui::GuiVariant::Nsh { - use crate::service::transport::DESKTOP_GUI_INSTALLER; - service_input.write_all(&[DESKTOP_GUI_INSTALLER]).await?; - let supplies_runtime = match service_output.read_u8().await? { - 0 => false, - 1 => true, - _ => anyhow::bail!("Invalid GUI installer capability response"), - }; - if !supplies_runtime { - super::nsh_runtime::check()?; + let result = async { + loop { + tokio::select! { + biased; + outcome = &mut current.as_mut().unwrap().task => { + current.take(); + break if cold_nsh { + outcome?.context(super::nsh_runtime::TAURI_RECOVERY) + } else { + outcome? + }; + } + accepted = listener.accept() => { + let (mut socket, _) = accepted?; + let mut pending = false; + let replacement = async { + let command = gui_switch::receive(&mut socket).await?; + let selection = command.selection; + let variant = selection.variant; + super::nsh_runtime::select(Some(variant), service_input, service_output).await?; + let candidate = Self::new(self.version, self.credential.clone(), variant).envs(self.envs.clone()); + let program = candidate.find_compatible_program(cancellation).await?; + if program.is_none() && !selection.allow_download { + gui_switch::reply(&mut socket, Ok(GuiSwitchOutcome::DownloadRequired)).await?; + return Ok(None); } - } - if program.is_none() && !selection.allow_download { - gui_switch::reply(&mut socket, Ok(GuiSwitchOutcome::DownloadRequired)).await?; - return Ok(None); - } - use super::rendering_recovery::{GbmBufferFailure, RecoveryState}; - let mut recovery = RecoveryState::default(); - let mut program = program; - let (child, start_result) = loop { - service_input.write_all(&[DESKTOP_SWITCH_BEGIN]).await?; - pending = true; - let credential = super::desktop_launcher::read_credential(service_output).await? - .ok_or_else(|| anyhow::anyhow!("Service closed before issuing the switch credential"))?; - anyhow::ensure!(credential.product_version() == self.version, "Service product version mismatch"); - let ready = gui_switch::SwitchListener::new()?; - let mut envs = self.envs.clone().unwrap_or_else(|| std::env::vars().collect()); - envs.insert(gui_switch::READY_ENV.into(), ready.path().to_string_lossy().into_owned()); - let launcher = Self::new(self.version, Arc::new(credential), variant) - .envs(envs) - .minimized(false); - let executable = match &program { - Some(program) => program.clone(), - None => launcher.resolve_program(cancellation, command.theme).await?, - }; - let mut child = launcher.start_owned(executable.clone(), cancellation.child_token()); - let start_result = tokio::select! { - result = tokio::time::timeout(std::time::Duration::from_secs(30), ready.ready()) => { - result.map_err(|_| anyhow::anyhow!("The selected GUI did not finish starting" )).and_then(|result| result) - }, - outcome = &mut child.task => { - match outcome? { - Ok(status) => return Err(anyhow::anyhow!("The selected GUI exited during startup: {status}")), - Err(error) if error.is::() && recovery.recover(&error) => { - log::warn!("{error}; restarting the selected GUI with compatibility graphics"); - service_input.write_all(&[DESKTOP_SWITCH_CANCEL]).await?; - pending = false; - program = Some(executable); - continue; - } - Err(error) => return Err(recovery.terminal(error)), + use super::rendering_recovery::{GbmBufferFailure, RecoveryState}; + let mut recovery = RecoveryState::default(); + let mut program = program; + let child = loop { + service_input.write_all(&[DESKTOP_SWITCH_BEGIN]).await?; + pending = true; + let credential = super::desktop_launcher::read_credential(service_output).await? + .ok_or_else(|| anyhow::anyhow!("Service closed before issuing the switch credential"))?; + anyhow::ensure!(credential.product_version() == self.version, "Service product version mismatch"); + let launcher = Self::new(self.version, Arc::new(credential), variant).envs(self.envs.clone()); + let executable = match &program { + Some(program) => program.clone(), + None => launcher.resolve_program(cancellation, command.theme).await?, + }; + match launcher.start_and_save(&executable, cancellation).await { + Ok(child) => break child, + Err(error) if error.is::() && recovery.recover(&error) => { + log::warn!("{error}; restarting the selected GUI with compatibility graphics"); + service_input.write_all(&[DESKTOP_SWITCH_CANCEL]).await?; + pending = false; + program = Some(executable); } + Err(error) => return Err(recovery.terminal(error)), } }; - break (child, start_result); - }; - if let Err(error) = start_result.and_then(|()| crate::gui::save_preference(variant)) { - child.cancel.cancel(); - let _ = child.task.await; - return Err(error); - } - if let Err(error) = gui_switch::reply(&mut socket, Ok(GuiSwitchOutcome::Switched)).await { - child.cancel.cancel(); - let _ = child.task.await; - return Err(error); - } - if let Err(error) = service_input.write_all(&[DESKTOP_SWITCH_COMMIT]).await { - child.cancel.cancel(); - let _ = child.task.await; - return Err(error.into()); - } - pending = false; - Ok(Some(child)) - }.await; - match replacement { - Ok(Some(child)) => retired.push(current.replace(child).unwrap()), - Ok(None) => {}, - Err(error) => { - if pending { - service_input.write_all(&[DESKTOP_SWITCH_CANCEL]).await?; + if let Err(error) = gui_switch::reply(&mut socket, Ok(GuiSwitchOutcome::Switched)).await { + child.cancel.cancel(); + let _ = child.task.await; + return Err(error); + } + if let Err(error) = service_input.write_all(&[DESKTOP_SWITCH_COMMIT]).await { + child.cancel.cancel(); + let _ = child.task.await; + return Err(error.into()); + } + pending = false; + Ok(Some(child)) + }.await; + match replacement { + Ok(Some(child)) => { + cold_nsh = false; + retired.push(current.replace(child).unwrap()); + } + Ok(None) => {}, + Err(error) => { + if pending { + service_input.write_all(&[DESKTOP_SWITCH_CANCEL]).await?; + } + let _ = gui_switch::reply(&mut socket, Err(format!("{error:#}"))).await; } - let _ = gui_switch::reply(&mut socket, Err(format!("{error:#}"))).await; } } - } - result = service_output.read(&mut unexpected) => { - break match result { - Ok(0) => Err(anyhow::anyhow!("The privileged service closed its credential channel")), - Ok(_) => Err(anyhow::anyhow!("Unexpected service credential data while the GUI is running")), - Err(error) => Err(error.into()), - }; + result = service_output.read(&mut unexpected) => { + break match result { + Ok(0) => Err(anyhow::anyhow!("The privileged service closed its credential channel")), + Ok(_) => Err(anyhow::anyhow!("Unexpected service credential data while the GUI is running")), + Err(error) => Err(error.into()), + }; + } } } - }}.await; + } + .await; // Every GUI remains owned by this supervisor until it is reaped. The retiring // GUI exits after the successful switch reply; cancellation also joins it. if let Some(child) = current { @@ -307,11 +302,38 @@ impl<'a> GuiLauncher<'a> { } #[cfg(target_os = "linux")] - fn start_owned(&self, program: PathBuf, cancel: CancellationToken) -> RunningGui { + /// Cold CLI selection and a Settings switch commit the preference after native readiness. + async fn start_and_save(&self, program: &Path, cancellation: &CancellationToken) -> anyhow::Result { + let ready = super::gui_switch::SwitchListener::new()?; + let mut child = self.start_owned(program, cancellation.child_token(), Some(&ready.path())); + let started = tokio::select! { + biased; + _ = cancellation.cancelled() => Err(anyhow::anyhow!("GUI startup cancelled")), + status = &mut child.task => bail!("The selected GUI exited during startup: {}", status??), + result = tokio::time::timeout(std::time::Duration::from_secs(30), ready.ready()) => { + result.context("The selected GUI did not finish starting").and_then(|result| result) + } + }; + if let Err(error) = started.and_then(|()| crate::gui::save_preference(self.variant)) { + child.cancel.cancel(); + let _ = child.task.await; + return Err(error); + } + Ok(child) + } + + #[cfg(target_os = "linux")] + fn start_owned(&self, program: &Path, cancel: CancellationToken, ready: Option<&Path>) -> RunningGui { + let program = program.to_owned(); let version = self.version.to_owned(); let variant = self.variant; let credential = self.credential.clone(); - let envs = self.envs.clone(); + let mut envs = self.envs.clone(); + if let Some(path) = ready { + envs + .get_or_insert_with(|| std::env::vars().collect()) + .insert(super::gui_switch::READY_ENV.into(), path.to_string_lossy().into_owned()); + } let minimized = self.minimized; let task_cancel = cancel.clone(); let task = tokio::spawn(async move { @@ -501,30 +523,6 @@ mod tests { ); } - #[tokio::test] - async fn nsh_version_mismatch_cannot_select_a_compatible_tauri_binary() { - let dir = TempDir::new().unwrap(); - let _tauri = executable(&dir, "gpgui", "gpgui test-version", 0); - let nsh = executable(&dir, "gpgui-nsh", "gpgui-nsh old-version", 0); - let mut selected = launcher(VERSION, vec![nsh.clone()]); - selected.variant = crate::gui::GuiVariant::Nsh; - assert!( - selected - .find_compatible_program(&CancellationToken::new()) - .await - .unwrap() - .is_none() - ); - executable(&dir, "gpgui-nsh", "gpgui-nsh test-version", 0); - assert_eq!( - selected - .find_compatible_program(&CancellationToken::new()) - .await - .unwrap(), - Some(nsh) - ); - } - #[test] #[cfg(target_os = "linux")] fn supervisor_switch_success_and_failure_preserve_child_ownership() { @@ -535,6 +533,11 @@ mod tests { "incompatible", "runtime-too-old", "runtime-too-old-confirmed", + "cold-default", + "cold-explicit", + "cold-explicit-failure", + "cold-explicit-clean-exit", + "cold-default-failure", ] { let directory = TempDir::new().unwrap(); let executable = std::env::current_exe().unwrap(); @@ -542,7 +545,7 @@ mod tests { let gtk = super::super::nsh_runtime::tests::gtk_fixture(directory.path(), 12); fs::rename(gtk, directory.path().join("libgtk-4.so.1")).unwrap(); for name in ["gpgui", "gpgui-nsh"] { - if (scenario == "missing" || scenario.starts_with("runtime-too-old")) && name == "gpgui-nsh" { + if (scenario == "missing" || scenario == "runtime-too-old") && name == "gpgui-nsh" { continue; } let version = if scenario == "incompatible" && name == "gpgui-nsh" { @@ -631,7 +634,7 @@ mod tests { async fn upgrade_fixture() { crate::gui::save_preference(crate::gui::GuiVariant::Nsh).unwrap(); let credential = Arc::new(SessionCredential::generate(Uuid::new_v4(), VERSION).unwrap()); - let selected = GuiLauncher::new(VERSION, credential, crate::gui::preferred().unwrap()); + let selected = GuiLauncher::new(VERSION, credential, crate::gui::saved_preference().unwrap().unwrap()); let program = selected .resolve_program(&CancellationToken::new(), crate::gui::GuiTheme::System) .await @@ -670,8 +673,14 @@ mod tests { input.read_exact(&mut frame).unwrap(); let directory = PathBuf::from(std::env::var_os("GP_SWITCH_DIRECTORY").unwrap()); let variant = std::env::var("GP_SWITCH_GUI_VARIANT").unwrap(); - if variant == "gpgui-nsh" && std::env::var("GP_SWITCH_SCENARIO").unwrap() == "failure" { - panic!("fixture: native host failed to initialize"); + if variant == "gpgui-nsh" { + let scenario = std::env::var("GP_SWITCH_SCENARIO").unwrap(); + if scenario.ends_with("failure") { + panic!("fixture: native host failed to initialize"); + } + if scenario.ends_with("clean-exit") { + return; + } } super::super::gui_switch::notify_ready().unwrap(); fs::write(directory.join(format!("{variant}-started")), "").unwrap(); @@ -719,13 +728,64 @@ mod tests { } }); let envs = std::env::vars().collect::>(); - let launcher = launcher(VERSION, vec![]).envs(envs); + let mut launcher = launcher(VERSION, vec![]).envs(envs); let cancel = CancellationToken::new(); + if runtime_too_old { + assert_eq!( + super::super::nsh_runtime::select(None, &mut service_input, &mut service_output) + .await + .unwrap(), + crate::gui::GuiVariant::Tauri + ); + } + if scenario.starts_with("cold-") { + use crate::gui::{GuiVariant, saved_preference}; + let mut explicit = scenario.contains("explicit").then_some(GuiVariant::Nsh); + if explicit.is_some() { + crate::gui::save_preference(GuiVariant::Tauri).unwrap(); + } + launcher.variant = super::super::nsh_runtime::select(explicit, &mut service_input, &mut service_output) + .await + .unwrap(); + assert_eq!(launcher.variant, GuiVariant::Nsh); + let program = directory.join(launcher.variant.binary_name()); + let run = launcher.launch_with_switches( + &program, + &cancel, + &listener.listener, + &mut explicit, + &mut service_input, + &mut service_output, + ); + if scenario.ends_with("failure") || scenario.ends_with("clean-exit") { + assert!(run.await.unwrap_err().to_string().contains("--interface tauri")); + let original = explicit.map(|_| GuiVariant::Tauri); + assert_eq!(saved_preference().unwrap(), original); + } else { + let expected = scenario.contains("explicit").then_some(GuiVariant::Nsh); + let stop = async { + while !directory.join("gpgui-nsh-started").exists() || saved_preference().unwrap() != expected { + tokio::time::sleep(std::time::Duration::from_millis(10)).await; + } + fs::write(directory.join("stop-gpgui-nsh"), "").unwrap(); + }; + let (status, ()) = tokio::time::timeout(std::time::Duration::from_secs(10), async { tokio::join!(run, stop) }) + .await + .unwrap(); + assert!(status.unwrap().success()); + assert!(explicit.is_none()); + assert_eq!(saved_preference().unwrap(), expected); + } + service.abort(); + return; + } let program = directory.join("gpgui"); + let mut explicit = None; let run = launcher.launch_with_switches( &program, &cancel, &listener.listener, + &mut explicit, &mut service_input, &mut service_output, ); @@ -756,6 +816,12 @@ mod tests { ); } else { anyhow::ensure!(result.is_ok() == success, "Unexpected switch result: {result:?}"); + if let Err(error) = &result { + anyhow::ensure!( + !error.to_string().contains("--interface tauri"), + "Unexpected CLI recovery hint" + ); + } if success { anyhow::ensure!( result? == crate::gui::GuiSwitchOutcome::Switched, @@ -779,7 +845,7 @@ mod tests { ); if success { anyhow::ensure!( - crate::gui::preferred()? == crate::gui::GuiVariant::Nsh, + crate::gui::saved_preference()? == Some(crate::gui::GuiVariant::Nsh), "Successful switch did not save preference" ); fs::write(directory.join("stop-gpgui"), "")?; @@ -788,7 +854,7 @@ mod tests { } } else { anyhow::ensure!( - crate::gui::preferred()? == crate::gui::GuiVariant::Tauri, + crate::gui::saved_preference()?.is_none(), "Failed switch changed preference" ); } diff --git a/crates/gpapi/src/process/nsh_runtime.rs b/crates/gpapi/src/process/nsh_runtime.rs index 8c875ef..e05f702 100644 --- a/crates/gpapi/src/process/nsh_runtime.rs +++ b/crates/gpapi/src/process/nsh_runtime.rs @@ -1,4 +1,4 @@ -//! Checks the generic Linux NSH runtime before offering a download. +//! Selects the Linux GUI using its installed or package-managed runtime. //! Runs in the desktop supervisor, which does not load either GUI's GTK runtime. use std::{ffi::OsStr, os::raw::c_uint}; @@ -11,14 +11,70 @@ use libloading::{ // Match nsh-platform-linux's gtk4/v4_14 feature when changing the NSH build. const MIN_GTK_MINOR: u32 = 14; +#[cfg(target_os = "linux")] +pub(super) const TAURI_RECOVERY: &str = "To use Tauri, run: gpclient launch-gui --interface tauri"; + +#[cfg(target_os = "linux")] +pub(super) async fn select( + requested: Option, + service_input: &mut (impl tokio::io::AsyncWrite + Unpin), + service_output: &mut (impl tokio::io::AsyncRead + Unpin), +) -> anyhow::Result { + use crate::{gui::GuiVariant, service::transport::DESKTOP_GUI_INSTALLER}; + use tokio::io::{AsyncReadExt, AsyncWriteExt}; + + if requested == Some(GuiVariant::Tauri) { + return Ok(GuiVariant::Tauri); + } + + let runtime = if crate::gui::NATIVE_SHELL_SUPPORTED { + service_input.write_all(&[DESKTOP_GUI_INSTALLER]).await?; + match service_output.read_u8().await? { + 0 => check(), + // The package installer provides and wraps NSH's dependencies (e.g. NixOS). + 1 => Ok(()), + _ => anyhow::bail!("Invalid GUI installer capability response"), + } + } else { + Err(anyhow::anyhow!("Native Shell is unavailable for this platform.")) + }; + + match runtime { + Ok(()) => Ok(GuiVariant::Nsh), + Err(err) if requested.is_some() => Err(err), + Err(err) => { + log::info!("Selecting Tauri: {err:#}"); + Ok(GuiVariant::Tauri) + } + } +} + #[cfg(target_os = "linux")] pub(super) fn check() -> anyhow::Result<()> { check_gtk(OsStr::new("libgtk-4.so.1"))?; + #[cfg(target_env = "gnu")] + { + // glibc returns a static, NUL-terminated runtime version string. + let version = unsafe { std::ffi::CStr::from_ptr(nix::libc::gnu_get_libc_version()) }; + check_glibc_version(version.to_str()?)?; + } load_library(OsStr::new("libgnutls.so.30"), "GnuTLS 3")?; load_library(OsStr::new("libdbus-1.so.3"), "D-Bus")?; Ok(()) } +#[cfg(any(all(target_os = "linux", target_env = "gnu"), test))] +fn check_glibc_version(version: &str) -> anyhow::Result<()> { + let mut parts = version.split('.'); + let major = parts.next().and_then(|part| part.parse::().ok()); + let minor = parts.next().and_then(|part| part.parse::().ok()); + ensure!( + major.zip(minor).is_some_and(|version| version >= (2, 39)), + "Native Shell requires glibc 2.39 or later. This system reports glibc {version}." + ); + Ok(()) +} + fn load_library(path: &OsStr, name: &str) -> anyhow::Result { // Resolve symbols now as well as transitive dependencies, without initializing GTK. let library = unsafe { libloading::os::unix::Library::open(Some(path), RTLD_LOCAL | RTLD_NOW) }; @@ -55,6 +111,21 @@ pub(super) mod tests { use super::*; use std::{fs, process::Command}; + #[test] + fn requires_glibc_2_39_or_later() { + for version in ["2.9", "2.38", "unknown"] { + assert!( + check_glibc_version(version) + .unwrap_err() + .to_string() + .contains("glibc 2.39") + ); + } + for version in ["2.39", "2.39.1", "2.40", "3.0"] { + check_glibc_version(version).unwrap(); + } + } + pub(in crate::process) fn gtk_fixture(directory: &std::path::Path, minor: u32) -> std::path::PathBuf { let source = directory.join(format!("gtk-{minor}.c")); let library = directory.join(format!("gtk-{minor}.so")); diff --git a/flake.nix b/flake.nix index 62f1017..9501f57 100644 --- a/flake.nix +++ b/flake.nix @@ -69,6 +69,30 @@ archive = gpguiArchive; }; + nshHashes = { + x86_64 = "sha256-HWQ7Lh0NA6lEjLIPjmvqsB1DhzUPMeZ6NPpyUTfLbng="; + aarch64 = "sha256-GT6arWaFyZNDCMrK676+JlPJnCAJ0DhDugcCMQlPmIM="; + }; + + nshArchive = pkgs.fetchurl { + url = "https://github.com/yuezk/GlobalProtect-openconnect/releases/download/${releaseTag}/gpgui-nsh_${cpu}.bin.tar.xz"; + hash = nshHashes.${cpu}; + }; + + installNativeShell = archive: version: + let nsh = import ./nix/gui-package.nix { + inherit pkgs version; + src = archive; + binaryName = "gpgui-nsh"; + }; + in '' + # A direct invocation hands off to gpclient in the enclosing package. + makeWrapper ${nsh}/bin/gpgui-nsh "$out/bin/gpgui-nsh" \ + --set-default GP_CLIENT_BINARY "$out/bin/gpclient" + install -Dm644 ${nsh}/share/licenses/gpgui-nsh/ICU4X-LICENSE.txt \ + "$out/share/licenses/globalprotect-openconnect/ICU4X-LICENSE.txt" + ''; + binaryHashes = { x86_64 = "sha256-gK8VWHw1VbXE7wHU1wGYw4fQ0khk24JWUwAQk+47WF8="; aarch64 = "sha256-nqSuIW1fz742+2rF0QpnN8hswFm5lezC9JEOMs/8OHM="; @@ -99,7 +123,13 @@ config = {}; overlays = []; }; - inherit archive checksum binaryName; + inherit binaryName; + src = builtins.path { + path = builtins.toPath archive; + name = "''${binaryName}.tar.xz"; + recursive = false; + sha256 = checksum; + }; version = "${version}"; } ''; @@ -191,7 +221,7 @@ EOF ''; - fromSource = lib.makeOverridable ({ gui ? gpgui }: naersk'.buildPackage { + fromSource = lib.makeOverridable ({ gui ? gpgui, nativeShellArchive ? nshArchive }: naersk'.buildPackage { inherit pname version; SNAPSHOT = lib.boolToString (releaseTag == "snapshot"); src = assert lib.assertMsg @@ -238,6 +268,7 @@ runtimeDependencies = lib.optionals pkgs.stdenv.isLinux linuxRuntimeDependencies; preFixup = nativeRuntimeWrapping; + postFixup = lib.optionalString pkgs.stdenv.isLinux (installNativeShell nativeShellArchive version); postInstall = '' make install PREFIX="$out" ${lib.optionalString pkgs.stdenv.isLinux ''GPGUI_BINARY="${gui}/gpgui"''} @@ -253,6 +284,7 @@ prebuilt = lib.makeOverridable ({ binaries ? binaryPackage, + nativeShellArchive ? nshArchive, gui ? gpgui, version ? releaseVersion, }: pkgs.stdenv.mkDerivation { @@ -269,6 +301,7 @@ buildInputs = linuxBuildInputs; runtimeDependencies = linuxRuntimeDependencies; preFixup = nativeRuntimeWrapping; + postFixup = installNativeShell nativeShellArchive version; installPhase = '' runHook preInstall @@ -282,6 +315,8 @@ cp -r artifacts/usr/lib $out/lib fi + # The Native Shell archive gets its own GTK4 wrapper in postFixup. + rm -f "$out/bin/gpgui-nsh" install -Dm755 ${gui}/gpgui $out/bin/gpgui ${rewriteVpncScriptToolPaths} diff --git a/nix/ci.nix b/nix/ci.nix index ab14814..9d9f0f6 100644 --- a/nix/ci.nix +++ b/nix/ci.nix @@ -18,9 +18,13 @@ let ''; binaries = unpack "gp-ci-binaries" "GP_BINARY_ARCHIVE"; gui = unpack "gp-ci-gui" "GP_GUI_ARCHIVE"; - sourcePackage = gp.packages.${system}.fromSource.override { inherit gui; }; + nativeShellArchive = builtins.path { + path = builtins.toPath (builtins.getEnv "GP_NSH_ARCHIVE"); + name = "gpgui-nsh.tar.xz"; + }; + sourcePackage = gp.packages.${system}.fromSource.override { inherit gui nativeShellArchive; }; prebuiltInputs = { - inherit binaries gui; + inherit binaries gui nativeShellArchive; version = sourcePackage.version; }; prebuiltPackage = gp.packages.${system}.prebuilt.override prebuiltInputs; @@ -52,6 +56,11 @@ in { package = sourcePackage; module = gp.nixosModules.default; }; + graphical-prebuilt = import ./tests/desktop-interfaces.nix { + inherit pkgs; + package = prebuiltPackage; + module = gp.nixosModules.default; + }; runtime-prebuilt = import ./tests/native-runtime.nix { inherit pkgs; package = prebuiltPackage; diff --git a/nix/gui-package.nix b/nix/gui-package.nix index f2dc3c9..b0b45ee 100644 --- a/nix/gui-package.nix +++ b/nix/gui-package.nix @@ -1,23 +1,19 @@ -{ pkgs, archive, checksum, binaryName, version }: +{ pkgs, src, binaryName, version }: let nativeShell = binaryName == "gpgui-nsh"; in assert builtins.elem binaryName [ "gpgui" "gpgui-nsh" ]; +assert pkgs.lib.assertMsg (!nativeShell || pkgs.lib.versionAtLeast pkgs.gtk4.version "4.14") + "Native Shell requires GTK 4.14 or later."; pkgs.stdenv.mkDerivation { pname = binaryName; - inherit version; - src = builtins.path { - path = builtins.toPath archive; - name = "${binaryName}.tar.xz"; - recursive = false; - sha256 = checksum; - }; + inherit src version; dontBuild = true; nativeBuildInputs = [ pkgs.autoPatchelfHook ] ++ ( if nativeShell then [ pkgs.wrapGAppsHook4 ] else [ pkgs.wrapGAppsHook3 ] ); buildInputs = with pkgs; - [ gnutls ] ++ (if nativeShell then [ gtk4 ] else [ + [ gnutls ] ++ (if nativeShell then [ gtk4 dbus ] else [ gtk3 webkitgtk_4_1 libsoup_3 glib-networking libsecret ]); runtimeDependencies = [ pkgs.libglvnd ] ++ pkgs.lib.optionals (!nativeShell) [ diff --git a/nix/tests/desktop-interfaces.nix b/nix/tests/desktop-interfaces.nix new file mode 100644 index 0000000..0b48bc9 --- /dev/null +++ b/nix/tests/desktop-interfaces.nix @@ -0,0 +1,92 @@ +{ pkgs, package, module }: +let + testPython = pkgs.python3.withPackages (ps: [ ps.pyatspi ps.pygobject3 ]); + typelibs = pkgs.lib.makeSearchPath "lib/girepository-1.0" [ + pkgs.at-spi2-core + pkgs.glib.out + pkgs.gobject-introspection + ]; + chooseTauri = pkgs.writeScript "choose-tauri" '' + #!${testPython}/bin/python3 + import pyatspi + import subprocess + + desktop = pyatspi.Registry.getDesktop(0) + target = pyatspi.findDescendant(desktop, lambda node: node.name == "Interface: Tauri") + if target is None: + raise SystemExit("The Tauri control is not visible yet") + # GTK4 exposes bounds relative to the window, even on X11. + rect = target.queryComponent().getExtents(pyatspi.WINDOW_COORDS) + if rect.width <= 0 or rect.height <= 0: + raise SystemExit("The Tauri control has no visible bounds") + window = subprocess.check_output(["xdotool", "search", "--onlyvisible", "--name", + "^GP Connect Settings$"], text=True).splitlines()[-1] + subprocess.run(["xdotool", "mousemove", "--window", window, str(rect.x + rect.width // 2), + str(rect.y + rect.height // 2), "click", "1"], check=True) + ''; +in +pkgs.testers.runNixOSTest { + name = "gp-offline-desktop-interfaces"; + nodes.machine = { + imports = [ module (pkgs.path + "/nixos/tests/common/x11.nix") ]; + programs.globalprotect-openconnect = { enable = true; inherit package; }; + test-support.displayManager.auto.user = "alice"; + users.users.alice = { isNormalUser = true; uid = 1000; }; + services.gnome.at-spi2-core.enable = true; + environment.systemPackages = [ pkgs.xdotool ]; + security.polkit.extraConfig = '' + polkit.addRule(function(action, subject) { + if (subject.user == "alice" && action.id == "com.yuezk.gpgui.service") { + return polkit.Result.YES; + } + }); + ''; + virtualisation.memorySize = 4096; + }; + + testScript = '' + from datetime import timedelta + import shlex + + machine.start() + machine.wait_for_unit("display-manager.service") + def as_alice(command): + environment = "export DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1000 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus GTK_A11Y=atspi; " + return "su - alice -c " + shlex.quote(environment + command) + + accessibility_env = "GI_TYPELIB_PATH=${typelibs} " + machine.succeed(as_alice(accessibility_env + "${testPython}/bin/python3 -c 'import pyatspi'")) + machine.wait_until_succeeds(as_alice("xdotool getdisplaygeometry")) + # Leave loopback available for the local privileged service. + machine.succeed("for dev in /sys/class/net/*; do dev=$(basename \"$dev\"); [ \"$dev\" = lo ] || ip link set \"$dev\" down; done") + + def launch(): + machine.succeed(as_alice("gpclient launch-gui > ~/gp-launch.log 2>&1 & echo $! > ~/gp-launch.pid")) + + def wait_for_gui(name): + # Identify the process which owns the mapped main window, including Nix's executable wrapper. + machine.wait_until_succeeds(as_alice( + "pid=$(xdotool search --onlyvisible --name '^GP Connect$' | tail -n 1 | xargs xdotool getwindowpid) && " + "readlink /proc/$pid/exe | grep -E '/[.]?" + name + "(-wrapped)?$'" + )) + + launch() + wait_for_gui("gpgui-nsh") + machine.succeed(as_alice("test ! -e ~/.config/gpclient/gui")) + machine.succeed(as_alice("${pkgs.glib.bin}/bin/gapplication action com.yuezk.gpgui settings")) + machine.wait_until_succeeds( + as_alice("xdotool search --onlyvisible --name '^GP Connect Settings$'"), + timeout=timedelta(seconds=60), + ) + machine.screenshot("native-shell-settings") + machine.wait_until_succeeds(as_alice(accessibility_env + "${chooseTauri}"), timeout=timedelta(seconds=60)) + wait_for_gui("gpgui") + machine.succeed(as_alice("grep -Fx gpgui ~/.config/gpclient/gui")) + machine.succeed(as_alice("kill -TERM $(cat ~/gp-launch.pid)")) + machine.wait_until_succeeds("test ! -e /var/run/gpservice.lock") + + launch() + wait_for_gui("gpgui") + machine.screenshot("tauri-relaunch") + ''; +} diff --git a/nix/tests/native-runtime.nix b/nix/tests/native-runtime.nix index c2e11f4..d492579 100644 --- a/nix/tests/native-runtime.nix +++ b/nix/tests/native-runtime.nix @@ -61,6 +61,7 @@ pkgs.testers.runNixOSTest { return machine.succeed("su - alice -c " + shlex.quote(command)) # Exercise real host pkexec, private credential pipes and launcher cancellation. + as_alice("mkdir -p ~/.config/gpclient && echo gpgui > ~/.config/gpclient/gui") command = "GP_GUI_BINARY=${guiProbe} " + package + "/bin/gpclient --lock-file /tmp/gp-client.lock launch-gui" as_alice(command + " > /tmp/gp-client-output 2>&1 & echo $! > /tmp/gp-client-pid") try: diff --git a/packaging/apk/APKBUILD.in b/packaging/apk/APKBUILD.in index 90c243d..add55e2 100644 --- a/packaging/apk/APKBUILD.in +++ b/packaging/apk/APKBUILD.in @@ -45,6 +45,8 @@ source="$pkgname-$pkgver.tar.gz" builddir="$srcdir/$pkgname-$pkgver" install="$pkgname.post-deinstall" options="!check" +# GTK4 is loaded only by the optional Native Shell. Keep dependency tracing for the rest of the package. +somask="libgtk-4.so.1 libgraphene-1.0.so.0" build() { cd "$builddir" @@ -64,6 +66,7 @@ package() { make install \ DESTDIR="$pkgdir" \ + INCLUDE_GUI="${INCLUDE_GUI:-0}" \ BUILD_GUI_HELPER="${BUILD_GUI_HELPER:-1}" } diff --git a/packaging/binary/Makefile.in b/packaging/binary/Makefile.in index e287e7e..19abde1 100644 --- a/packaging/binary/Makefile.in +++ b/packaging/binary/Makefile.in @@ -8,7 +8,9 @@ install: install -Dm755 artifacts/usr/bin/gpgui-helper $(DESTDIR)/usr/bin/gpgui-helper if [ -f artifacts/usr/bin/gpgui ]; then \ - install -Dm755 artifacts/usr/bin/gpgui $(DESTDIR)/usr/bin/gpgui; \ + install -Dm755 artifacts/usr/bin/gpgui $(DESTDIR)/usr/bin/gpgui && \ + install -Dm755 artifacts/usr/bin/gpgui-nsh $(DESTDIR)/usr/bin/gpgui-nsh && \ + install -Dm644 artifacts/usr/share/licenses/globalprotect-openconnect/ICU4X-LICENSE.txt $(DESTDIR)/usr/share/licenses/globalprotect-openconnect/ICU4X-LICENSE.txt; \ fi install -Dm755 artifacts/usr/libexec/gpclient/vpnc-script $(DESTDIR)/usr/libexec/gpclient/vpnc-script @@ -37,6 +39,7 @@ uninstall: rm -f $(DESTDIR)/usr/bin/gpauth rm -f $(DESTDIR)/usr/bin/gpgui-helper rm -f $(DESTDIR)/usr/bin/gpgui + rm -f $(DESTDIR)/usr/bin/gpgui-nsh $(DESTDIR)/usr/share/licenses/globalprotect-openconnect/ICU4X-LICENSE.txt rm -f $(DESTDIR)/usr/libexec/gpclient/vpnc-script rm -f $(DESTDIR)/usr/libexec/gpclient/gp-vpnc-script-installer diff --git a/packaging/deb/rules.in b/packaging/deb/rules.in index bc58331..d07c31b 100755 --- a/packaging/deb/rules.in +++ b/packaging/deb/rules.in @@ -11,3 +11,7 @@ export PATH := /usr/lib/rust-@RUST_VERSION@/bin:/usr/local/cargo/bin:$(PATH) which cargo which rustc dh $@ --no-parallel + +# Native Shell checks its optional runtime on launch. +override_dh_shlibdeps: + dh_shlibdeps -X/bin/gpgui-nsh diff --git a/packaging/rpm/globalprotect-openconnect.spec.in b/packaging/rpm/globalprotect-openconnect.spec.in index d7953be..0dbcba1 100644 --- a/packaging/rpm/globalprotect-openconnect.spec.in +++ b/packaging/rpm/globalprotect-openconnect.spec.in @@ -35,6 +35,7 @@ Requires: xdg-utils Conflicts: globalprotect-openconnect-snapshot %global debug_package %{nil} +%global __requires_exclude_from ^%{_bindir}/gpgui-nsh$ %description A GUI for GlobalProtect VPN, based on OpenConnect, supports the SSO authentication method. @@ -57,14 +58,17 @@ fi %build # The injected RUSTFLAGS could fail the build unset RUSTFLAGS -make build +make build INCLUDE_GUI=%{?include_gui}%{!?include_gui:0} %install -%make_install +%make_install INCLUDE_GUI=%{?include_gui}%{!?include_gui:0} %files %defattr(-,root,root) %{_bindir}/* +%if 0%{?include_gui} +%license %{_datadir}/licenses/%{name}/ICU4X-LICENSE.txt +%endif %{_libexecdir}/gpclient/vpnc-script %{_libexecdir}/gpclient/gp-hip-script-installer %{_libexecdir}/gpclient/gp-vpnc-script-installer diff --git a/scripts/build-linux-nsh.sh b/scripts/build-linux-nsh.sh new file mode 100755 index 0000000..6c65a0e --- /dev/null +++ b/scripts/build-linux-nsh.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# Run in the gpgui checkout with its matching gp sibling on a native Linux builder. +set -euo pipefail + +manifest=apps/desktop-nsh/Cargo.toml +toolchain=1.97.0 +host=$(rustc "+$toolchain" -vV | sed -n 's/^host: //p') +case "$host" in + x86_64-unknown-linux-gnu|aarch64-unknown-linux-gnu) suffix= ;; + x86_64-unknown-linux-musl|aarch64-unknown-linux-musl) + suffix=-musl + export RUSTFLAGS="-C target-feature=-crt-static" + ;; + *) echo "Unsupported Linux NSH build target: $host" >&2; exit 1 ;; +esac + +pkg-config --exists 'gtk4 >= 4.14' gnutls dbus-1 wayland-client xkbcommon +cargo "+$toolchain" build --manifest-path "$manifest" --locked --release --bin gpgui-nsh \ + --target "$host" --target-dir target +binary="target/$host/release/gpgui-nsh" +"$binary" --version +needed=$(readelf -d "$binary") +if grep -q 'NEEDED.*libicu' <<<"$needed"; then + echo 'The release executable must not depend on ICU4C.' >&2 + exit 1 +fi +if [[ $suffix == -musl ]]; then + readelf -lW "$binary" | grep 'Requesting program interpreter: /lib/ld-musl-' >/dev/null +fi +version=$(cargo "+$toolchain" metadata --manifest-path "$manifest" --no-deps --format-version 1 \ + | jq -er '.packages[] | select(.name == "gpgui-nsh") | .version') +directory="gpgui-nsh_$version" +archive="gpgui-nsh_$(uname -m)$suffix.bin.tar.xz" +mkdir -p ".build/package/$directory" +cp "$binary" apps/desktop-nsh/ICU4X-LICENSE.txt ".build/package/$directory/" +cd .build/package +tar -cJf "$archive" "$directory" +sha256sum "$archive" | cut -d ' ' -f 1 > "$archive.sha256" diff --git a/scripts/gh-release.sh b/scripts/gh-release.sh index 67fce6e..37d82df 100755 --- a/scripts/gh-release.sh +++ b/scripts/gh-release.sh @@ -47,10 +47,6 @@ upload_files() { done } -release_assets() { - "$SCRIPT_DIR/release-assets.sh" "$TAG" -} - release_assets_json() { retry_gh gh -R "$REPO" release view "$TAG" --json assets } @@ -134,7 +130,6 @@ upload_file() { # Keep its tag fixed; only release assets advance with subsequent builds. # Preserve its macOS update assets when the current run does not replace them. release_snapshot() { - mapfile -t files < <(release_assets) local existing_assets local is_current local asset @@ -201,11 +196,13 @@ release_tag() { --notes-file "$release_notes_file" fi - mapfile -t files < <(release_assets) GITHUB_REPOSITORY="$REPO" "$SCRIPT_DIR/upload-release-assets.sh" "$TAG" "${files[@]}" gh -R "$REPO" release edit "$TAG" --prerelease=false } +asset_list=$("$SCRIPT_DIR/release-assets.sh" "$TAG") +mapfile -t files <<<"$asset_list" + if [[ $TAG == *"snapshot" ]]; then release_snapshot else diff --git a/scripts/prepare-release-promotion.sh b/scripts/prepare-release-promotion.sh index 271c3de..da25505 100755 --- a/scripts/prepare-release-promotion.sh +++ b/scripts/prepare-release-promotion.sh @@ -47,7 +47,7 @@ path = Path('flake.nix') promoted = path.read_text() fields = [(name, rf'(\b{name}\s*=\s*")([^"]+)(")') for name in ('releaseTag', 'releaseVersion')] -for block in ('gpguiHashes', 'binaryHashes'): +for block in ('gpguiHashes', 'nshHashes', 'binaryHashes'): for arch in ('x86_64', 'aarch64'): fields.append((f'{block}.{arch}', rf'(\b{block}\s*=\s*\{{[^}}]*?\b{arch}\s*=\s*")([^"]+)(")')) for name, pattern in fields: diff --git a/scripts/release-assets.sh b/scripts/release-assets.sh index f3871bf..dffee2f 100755 --- a/scripts/release-assets.sh +++ b/scripts/release-assets.sh @@ -20,6 +20,11 @@ elif [ "$SELECTION" != "all" ]; then SELECTION=tag fi +# The follow-up distro-package workflow uses "all" for its own package artifacts. +if [[ "$SELECTION" != "all" ]]; then + "$SCRIPT_DIR/verify-linux-nsh-assets.sh" "$ARTIFACT_DIR" --actions +fi + case "$SELECTION" in snapshot|all) printf '%s\n' "$ARTIFACT_DIR"/artifact-*/* diff --git a/scripts/tests/install-layout.sh b/scripts/tests/install-layout.sh index 00d15b3..8ae7844 100644 --- a/scripts/tests/install-layout.sh +++ b/scripts/tests/install-layout.sh @@ -5,10 +5,11 @@ cd "$root" temp=$(mktemp -d) trap 'rm -rf "$temp"' EXIT HUP INT TERM mkdir -p "$temp/release" -for binary in gpclient gpauth gpservice gpgui gpgui-helper gp-vpnc-script-installer gp-hip-script-installer; do +for binary in gpclient gpauth gpservice gpgui gpgui-nsh gpgui-helper gp-vpnc-script-installer gp-hip-script-installer; do printf '#!/bin/sh\nexit 0\n' > "$temp/release/$binary" chmod 755 "$temp/release/$binary" done +echo 'ICU4X license fixture' > "$temp/release/ICU4X-LICENSE.txt" mkdir -p "$temp/client-release" cp "$temp/release/gpclient" "$temp/client-release/" make install-gpclient-unix PREFIX='/custom/gp install' DESTDIR="$temp/client-stage" \ @@ -19,7 +20,7 @@ test -x "$installed/libexec/gpclient/vpnc-script" test "$(find "$installed" -type f | wc -l | tr -d ' ')" = 2 for platform in linux bsd; do stage="$temp/$platform-stage" - make "install-$platform" PREFIX=/custom/gp DESTDIR="$stage" \ + make "install-$platform" PREFIX=/custom/gp DESTDIR="$stage" INCLUDE_GUI=1 NSH_BUNDLE_DIR="$temp/release" \ CARGO_RELEASE_DIR="$temp/release" GPGUI_BINARY="$temp/release/gpgui" > "$temp/$platform.log" installed="$stage/custom/gp" test -x "$installed/bin/gpclient" @@ -35,8 +36,11 @@ for platform in linux bsd; do ! grep -F "$stage" "$installed/share/applications/gpgui.desktop" if [ "$platform" = bsd ]; then test ! -d "$installed/lib/NetworkManager" + test ! -e "$installed/bin/gpgui-nsh" else test -x "$installed/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down" + test -x "$installed/bin/gpgui-nsh" + cmp "$temp/release/ICU4X-LICENSE.txt" "$installed/share/licenses/globalprotect-openconnect/ICU4X-LICENSE.txt" fi runtime="$stage/var/lib/gpclient" if [ "$platform" = bsd ]; then @@ -60,6 +64,12 @@ for platform in linux bsd; do test -f "$installed/libexec/gpclient/unrelated" test -f "$runtime/scripts/unrelated" done +if make install-linux INCLUDE_GUI=1 PREFIX=/usr DESTDIR="$temp/missing-nsh" \ + GPGUI_BINARY="$temp/release/gpgui" NSH_BUNDLE_DIR="$temp/absent" \ + CARGO_RELEASE_DIR="$temp/release" > "$temp/missing-nsh.log" 2>&1; then + echo 'FAIL: bundled package installation succeeded without Native Shell' >&2 + exit 1 +fi mv "$temp/release/gpclient" "$temp/release/gpclient.saved" if make install-linux PREFIX=/custom/gp DESTDIR="$temp/missing-client-stage" \ CARGO_RELEASE_DIR="$temp/release" > "$temp/missing-client.log" 2>&1; then diff --git a/scripts/tests/nix-desktop-authorization.sh b/scripts/tests/nix-desktop-authorization.sh index d556072..ba06034 100644 --- a/scripts/tests/nix-desktop-authorization.sh +++ b/scripts/tests/nix-desktop-authorization.sh @@ -45,3 +45,4 @@ check_authorization() { check_authorization "$package_path/bin/gpclient" launch-gui --minimized check_authorization "$package_path/bin/gpclient" --lock-file "$test_workspace/client.lock" launch-gui check_authorization "$package_path/bin/gpgui" --minimized +check_authorization "$package_path/bin/gpgui-nsh" --minimized diff --git a/scripts/tests/test_release_flow.py b/scripts/tests/test_release_flow.py index e1340a3..83a2d55 100644 --- a/scripts/tests/test_release_flow.py +++ b/scripts/tests/test_release_flow.py @@ -1,3 +1,4 @@ +import hashlib import importlib.util import json import os @@ -80,7 +81,7 @@ class ReleaseVersionTests(unittest.TestCase): write_version(root, '3.2.0') package = root / 'result' (package / 'bin').mkdir(parents=True) - for name in ('gpclient', 'gpservice', 'gpauth', 'gpgui'): + for name in ('gpclient', 'gpservice', 'gpauth', 'gpgui', 'gpgui-nsh'): tool = package / 'bin' / name tool.write_text(f'#!/bin/sh\necho "{name} 3.2.0 (PRIVATE_IDENTITY)"\n') tool.chmod(0o755) @@ -90,6 +91,44 @@ class ReleaseVersionTests(unittest.TestCase): versions.validate(root, package=package) +class LinuxNshAssetsTests(unittest.TestCase): + def test_releases_require_both_architectures_and_libcs_with_matching_checksums(self): + with tempfile.TemporaryDirectory() as temp: + root = Path(temp) + assets = [] + for arch in ('x86_64', 'aarch64'): + for suffix in ('', '-musl'): + directory = root / f'artifact-gpgui-nsh{suffix}-{arch}' + directory.mkdir() + archive = directory / f'gpgui-nsh_{arch}{suffix}.bin.tar.xz' + archive.write_bytes(archive.name.encode()) + sidecar = archive.with_name(archive.name + '.sha256') + sidecar.write_text(hashlib.sha256(archive.read_bytes()).hexdigest() + '\n') + assets.extend((archive, sidecar)) + + for channel in ('snapshot', 'v3.7.0'): + command = [ROOT / 'scripts/release-assets.sh', channel, root] + valid = subprocess.run(command, capture_output=True, text=True, check=True) + self.assertEqual(set(valid.stdout.splitlines()), {str(asset) for asset in assets}) + for asset in assets: + data = asset.read_bytes() + asset.unlink() + self.assertNotEqual(subprocess.run(command, capture_output=True).returncode, 0, asset.name) + asset.write_bytes(data) + archive = assets[0] + data = archive.read_bytes() + archive.write_bytes(b'corrupt') + self.assertNotEqual(subprocess.run(command, capture_output=True).returncode, 0) + archive.write_bytes(data) + + for asset in assets: + asset.rename(root / asset.name) + verify_published = [ROOT / 'scripts/verify-linux-nsh-assets.sh', root] + subprocess.run(verify_published, capture_output=True, check=True) + (root / assets[-1].name).unlink() + self.assertNotEqual(subprocess.run(verify_published, capture_output=True).returncode, 0) + + class BuildIdentityTests(unittest.TestCase): def test_retry_uses_original_sources_after_both_branches_advance(self): with tempfile.TemporaryDirectory() as temp: @@ -145,6 +184,7 @@ class PromotionTests(unittest.TestCase): initialize(repo) write_version(repo) hashes = 'gpguiHashes = { x86_64 = "old-gui-x64"; aarch64 = "old-gui-arm64"; };\n' \ + 'nshHashes = { x86_64 = "old-nsh-x64"; aarch64 = "old-nsh-arm64"; };\n' \ 'binaryHashes = { x86_64 = "old-cli-x64"; aarch64 = "old-cli-arm64"; };\n' with (repo / 'flake.nix').open('a') as flake: flake.write('packageSetting = "original";\n' + hashes) diff --git a/scripts/update-flake-hashes.sh b/scripts/update-flake-hashes.sh index 4492179..1839db9 100755 --- a/scripts/update-flake-hashes.sh +++ b/scripts/update-flake-hashes.sh @@ -81,11 +81,15 @@ release_url() { gpgui_x86_64_hash="$(prefetch_hash "$(release_url "gpgui_x86_64.bin.tar.xz")")" gpgui_aarch64_hash="$(prefetch_hash "$(release_url "gpgui_aarch64.bin.tar.xz")")" +nsh_x86_64_hash="$(prefetch_hash "$(release_url "gpgui-nsh_x86_64.bin.tar.xz")")" +nsh_aarch64_hash="$(prefetch_hash "$(release_url "gpgui-nsh_aarch64.bin.tar.xz")")" binary_x86_64_hash="$(prefetch_hash "$(release_url "globalprotect-openconnect_${version}_x86_64.bin.tar.xz")")" binary_aarch64_hash="$(prefetch_hash "$(release_url "globalprotect-openconnect_${version}_aarch64.bin.tar.xz")")" GPGUI_X86_64_HASH="$gpgui_x86_64_hash" \ GPGUI_AARCH64_HASH="$gpgui_aarch64_hash" \ +NSH_X86_64_HASH="$nsh_x86_64_hash" \ +NSH_AARCH64_HASH="$nsh_aarch64_hash" \ BINARY_X86_64_HASH="$binary_x86_64_hash" \ BINARY_AARCH64_HASH="$binary_aarch64_hash" \ RELEASE_TAG="$release_tag" \ @@ -95,12 +99,16 @@ perl -0pi -e ' s|(releaseVersion = ")[^"]+(";)|$1 . $ENV{"RELEASE_VERSION"} . $2|e; s|(gpguiHashes = \{\n\s*x86_64 = ")[^"]+(";)|$1 . $ENV{"GPGUI_X86_64_HASH"} . $2|e; s|(gpguiHashes = \{\n\s*x86_64 = "[^"]+";\n\s*aarch64 = ")[^"]+(";)|$1 . $ENV{"GPGUI_AARCH64_HASH"} . $2|e; + s|(nshHashes = \{\n\s*x86_64 = ")[^"]+(";)|$1 . $ENV{"NSH_X86_64_HASH"} . $2|e; + s|(nshHashes = \{\n\s*x86_64 = "[^"]+";\n\s*aarch64 = ")[^"]+(";)|$1 . $ENV{"NSH_AARCH64_HASH"} . $2|e; s|(binaryHashes = \{\n\s*x86_64 = ")[^"]+(";)|$1 . $ENV{"BINARY_X86_64_HASH"} . $2|e; s|(binaryHashes = \{\n\s*x86_64 = "[^"]+";\n\s*aarch64 = ")[^"]+(";)|$1 . $ENV{"BINARY_AARCH64_HASH"} . $2|e; ' "$FLAKE_FILE" grep -F "$gpgui_x86_64_hash" "$FLAKE_FILE" > /dev/null grep -F "$gpgui_aarch64_hash" "$FLAKE_FILE" > /dev/null +grep -F "$nsh_x86_64_hash" "$FLAKE_FILE" > /dev/null +grep -F "$nsh_aarch64_hash" "$FLAKE_FILE" > /dev/null grep -F "$binary_x86_64_hash" "$FLAKE_FILE" > /dev/null grep -F "$binary_aarch64_hash" "$FLAKE_FILE" > /dev/null grep -F "releaseTag = \"$release_tag\";" "$FLAKE_FILE" > /dev/null diff --git a/scripts/validate-release-version.py b/scripts/validate-release-version.py index de261c0..427c8f0 100644 --- a/scripts/validate-release-version.py +++ b/scripts/validate-release-version.py @@ -40,7 +40,7 @@ def validate(root, version=None, release_tag=None, package=None, base_ref=None): if tuple(map(int, expected.split("."))) < tuple(map(int, base.split("."))): raise ValueError("candidate release is older than the main base") if package: - for name in ("gpclient", "gpservice", "gpauth", "gpgui"): + for name in ("gpclient", "gpservice", "gpauth", "gpgui", "gpgui-nsh"): result = subprocess.run([str(package / "bin" / name), "--version"], capture_output=True, text=True, check=True) # Keep private source identity and other command output out of logs. diff --git a/scripts/verify-linux-nsh-assets.sh b/scripts/verify-linux-nsh-assets.sh new file mode 100755 index 0000000..1dcdd8e --- /dev/null +++ b/scripts/verify-linux-nsh-assets.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -euo pipefail + +root="${1:?Expected a release download directory or Actions artifact directory}" +for arch in x86_64 aarch64; do + for suffix in '' '-musl'; do + directory="$root" + if [[ ${2:-} == --actions ]]; then + directory="$root/artifact-gpgui-nsh${suffix}-$arch" + fi + archive="$directory/gpgui-nsh_${arch}${suffix}.bin.tar.xz" + digest=$(cat "$archive.sha256") + if [[ ! $digest =~ ^[[:xdigit:]]{64}$ ]]; then + echo "Invalid SHA-256 sidecar: $archive.sha256" >&2 + exit 1 + fi + printf '%s %s\n' "$digest" "$archive" | sha256sum -c - >&2 + done +done diff --git a/scripts/verify-linux-package.sh b/scripts/verify-linux-package.sh new file mode 100755 index 0000000..dc0cd45 --- /dev/null +++ b/scripts/verify-linux-package.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# Run inside the distro builder after install.sh installs the newly built package. +set -euo pipefail + +package=globalprotect-openconnect +notice=/usr/share/licenses/$package/ICU4X-LICENSE.txt +for path in /usr/bin/gpgui /usr/bin/gpgui-nsh; do + test -x "$path" +done +test -s "$notice" + +case "${1:?Expected a package format}" in + binary) exit 0 ;; + deb|ubuntu-rolling) + files=$(dpkg-query -L "$package") + requires=$(dpkg-query -W -f='${Pre-Depends} ${Depends}\n' "$package") + ;; + rpm) + files=$(rpm -ql "$package") + requires=$(rpm -q --requires "$package") + ;; + apk) + files=$(apk info -L "$package") + requires=$(apk info -R "$package") + ;; + pkg) + files=$(pacman -Qlq "$package") + requires=$(bsdtar -xOf /workspace/artifacts/*.pkg.tar.zst .PKGINFO | sed -n 's/^depend = //p') + ;; + *) echo "Unknown package format: $1" >&2; exit 1 ;; +esac + +# apk emits paths relative to /. Other package managers use absolute paths. +for path in /usr/bin/gpgui /usr/bin/gpgui-nsh "$notice"; do + if ! grep -Fxq -e "$path" -e "${path#/}" <<<"$files"; then + echo "$package does not own $path" >&2 + exit 1 + fi +done +if grep -Eq '(^|[[:space:],:(|])(lib)?gtk-?4([^[:alnum:]_]|$)' <<<"$requires"; then + echo "Package metadata makes GTK4 mandatory: $requires" >&2 + exit 1 +fi