From d59c3fef0a44d1264418ad914338a1d7256d53a3 Mon Sep 17 00:00:00 2001 From: Reactor Scram Date: Thu, 16 May 2024 18:03:21 -0500 Subject: [PATCH] build(gui-client): add post-install and pre-remove scripts to the deb package (#5011) Closes #4987 ```[tasklist] ### Before merging - [x] Get an x64 test VM on the Windows laptop and test a CI-built deb ``` --- rust/gui-client/build.sh | 25 ++++++++++++++++++++ rust/gui-client/docs/intended_behavior.md | 2 -- rust/gui-client/src-tauri/deb_files/postinst | 15 ++++++++++++ rust/gui-client/src-tauri/deb_files/prerm | 9 +++++++ scripts/build/tauri-rename-ubuntu.sh | 2 +- scripts/firezone-client-gui-install.sh | 9 +------ 6 files changed, 51 insertions(+), 11 deletions(-) create mode 100755 rust/gui-client/src-tauri/deb_files/postinst create mode 100755 rust/gui-client/src-tauri/deb_files/prerm diff --git a/rust/gui-client/build.sh b/rust/gui-client/build.sh index 1de8286d8..b3d855fa6 100755 --- a/rust/gui-client/build.sh +++ b/rust/gui-client/build.sh @@ -2,6 +2,9 @@ set -euo pipefail +# Dir where all the bundles are built +BUNDLES_DIR=../target/release/bundle/deb + # Copy frontend dependencies cp node_modules/flowbite/dist/flowbite.min.js src/ @@ -11,5 +14,27 @@ pnpm tsc # Compile CSS pnpm tailwindcss -i src/input.css -o src/output.css +# Get rid of any existing debs, since we need to discover the path later +rm -rf "$BUNDLES_DIR" + # Compile Rust and bundle pnpm tauri build + +# Delete the deb that Tauri built. We're going to modify and rebuild it. +rm "$BUNDLES_DIR"/*.deb + +# There should be only one directory in `bundle/deb`, we need to modify +# files inside that dir +INTERMEDIATE_DIR=$(ls -d "$BUNDLES_DIR"/*/) + +# Add the scripts +cp src-tauri/deb_files/postinst src-tauri/deb_files/prerm "$INTERMEDIATE_DIR/control/" + +pushd "$INTERMEDIATE_DIR" +# Rebuild the control tarball +tar -C "control" -czf "control.tar.gz" control md5sums postinst prerm + +# Rebuild the deb package, and give it a predictable name that +# `tauri-rename-ubuntu.sh` can fix +ar rcs "../firezone-client-gui.deb" debian-binary control.tar.gz data.tar.gz +popd diff --git a/rust/gui-client/docs/intended_behavior.md b/rust/gui-client/docs/intended_behavior.md index 8872fad4f..b9375bb94 100644 --- a/rust/gui-client/docs/intended_behavior.md +++ b/rust/gui-client/docs/intended_behavior.md @@ -83,9 +83,7 @@ x86_64 only, see issue #2992. Best performed on a clean VM. ## Un-install checklist (Linux) 1. Close the Firezone GUI -1. Run `sudo systemctl stop firezone-client-ipc.service` 1. Run `sudo apt-get remove firezone-client-gui` -1. Run `sudo systemctl daemon-reload` ## Un-install checklist (Windows) diff --git a/rust/gui-client/src-tauri/deb_files/postinst b/rust/gui-client/src-tauri/deb_files/postinst new file mode 100755 index 000000000..ca019fa1b --- /dev/null +++ b/rust/gui-client/src-tauri/deb_files/postinst @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# Usage: dpkg will call this after installing our files +# This must be idempotent + +set -euo pipefail + +SERVICE_NAME="firezone-client-ipc" + +# Creates the system group `firezone-client` +sudo systemd-sysusers + +echo "Starting and enabling Firezone IPC service..." +sudo systemctl daemon-reload +sudo systemctl enable "$SERVICE_NAME" +sudo systemctl restart "$SERVICE_NAME" diff --git a/rust/gui-client/src-tauri/deb_files/prerm b/rust/gui-client/src-tauri/deb_files/prerm new file mode 100755 index 000000000..f0b30e031 --- /dev/null +++ b/rust/gui-client/src-tauri/deb_files/prerm @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# Usage: dpkg will call this after installing our files + +set -euo pipefail + +SERVICE_NAME="firezone-client-ipc" + +sudo systemctl disable "$SERVICE_NAME" +sudo systemctl stop "$SERVICE_NAME" diff --git a/scripts/build/tauri-rename-ubuntu.sh b/scripts/build/tauri-rename-ubuntu.sh index d1e660e8b..f5a83910c 100755 --- a/scripts/build/tauri-rename-ubuntu.sh +++ b/scripts/build/tauri-rename-ubuntu.sh @@ -17,7 +17,7 @@ ls ../target/release ../target/release/bundle/deb # Using a glob for the source, there will only be one exe and one deb anyway cp ../target/release/firezone-client-gui "$BINARY_DEST_PATH" cp ../target/release/firezone-gui-client.dwp "$BINARY_DEST_PATH.dwp" -cp ../target/release/bundle/deb/*_amd64.deb "$BINARY_DEST_PATH.deb" +cp ../target/release/bundle/deb/firezone-client-gui.deb "$BINARY_DEST_PATH.deb" # TODO: Debug symbols for Linux function make_hash() { diff --git a/scripts/firezone-client-gui-install.sh b/scripts/firezone-client-gui-install.sh index dbc2f7433..9f1282513 100755 --- a/scripts/firezone-client-gui-install.sh +++ b/scripts/firezone-client-gui-install.sh @@ -9,19 +9,12 @@ set -euox pipefail # `apt-get` needs either a leading `./` or `/` to recognize a local file path DEB_PATH=$(realpath "$1") GROUP_NAME="firezone-client" -SERVICE_NAME="firezone-client-ipc" echo "Installing Firezone..." sudo apt-get install --yes "$DEB_PATH" echo "Adding your user to the $GROUP_NAME group..." -# Creates the system group `firezone-client` -sudo systemd-sysusers -sudo adduser "$USER" "$GROUP_NAME" - -echo "Starting and enabling Firezone IPC service..." -sudo systemctl enable "$SERVICE_NAME" -sudo systemctl restart "$SERVICE_NAME" +sudo usermod -a -G "$GROUP_NAME" "$USER" # Check if the user is already in the group if ! groups | grep "$GROUP_NAME" &>/dev/null; then