mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 22:46:14 -05:00
fix: separate packaged and runtime GUI binaries
This commit is contained in:
15 files changed
+251
-59
No files matched your search
Generated
+1
@@ -1966,6 +1966,7 @@ dependencies = [
|
|||||||
"openconnect",
|
"openconnect",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"sha256",
|
||||||
"tar",
|
"tar",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"thiserror 2.0.18",
|
"thiserror 2.0.18",
|
||||||
|
|||||||
@@ -252,8 +252,10 @@ package-openbsd: clean-bsd-package
|
|||||||
cp packaging/bsd/openbsd/COMMENT .build/openbsd/+COMMENT
|
cp packaging/bsd/openbsd/COMMENT .build/openbsd/+COMMENT
|
||||||
cp packaging/bsd/openbsd/DESC .build/openbsd/+DESC
|
cp packaging/bsd/openbsd/DESC .build/openbsd/+DESC
|
||||||
{ \
|
{ \
|
||||||
echo '@unexec-delete /bin/rm -f /var/db/gpclient/scripts/vpnc-script /var/db/gpclient/scripts/vpnc-script.metadata || echo "Warning: failed to remove the installed VPN script" >&2'; \
|
echo '@unexec-delete /bin/rm -f /usr/local/libexec/gpclient/gpgui /var/db/gpclient/scripts/vpnc-script /var/db/gpclient/scripts/vpnc-script.metadata || echo "Warning: failed to remove gpclient runtime files" >&2'; \
|
||||||
|
echo '@unexec-delete /bin/rmdir /usr/local/libexec/gpclient 2>/dev/null || true'; \
|
||||||
echo '@unexec-delete /bin/rmdir /var/db/gpclient/scripts 2>/dev/null || true'; \
|
echo '@unexec-delete /bin/rmdir /var/db/gpclient/scripts 2>/dev/null || true'; \
|
||||||
|
echo '@unexec-delete /bin/rmdir /var/db/gpclient 2>/dev/null || true'; \
|
||||||
find .build/openbsd/pkgroot$(PREFIX) -type f -print | sed 's|^.build/openbsd/pkgroot$(PREFIX)/||' | sort; \
|
find .build/openbsd/pkgroot$(PREFIX) -type f -print | sed 's|^.build/openbsd/pkgroot$(PREFIX)/||' | sort; \
|
||||||
} > .build/openbsd/PLIST
|
} > .build/openbsd/PLIST
|
||||||
comment=$$(cat .build/openbsd/+COMMENT); \
|
comment=$$(cat .build/openbsd/+COMMENT); \
|
||||||
@@ -300,10 +302,12 @@ uninstall:
|
|||||||
rm -f $(DESTDIR)/usr/share/icons/hicolor/256x256@2/apps/gpgui.png
|
rm -f $(DESTDIR)/usr/share/icons/hicolor/256x256@2/apps/gpgui.png
|
||||||
rm -f $(DESTDIR)/usr/share/polkit-1/actions/com.yuezk.gpgui.policy
|
rm -f $(DESTDIR)/usr/share/polkit-1/actions/com.yuezk.gpgui.policy
|
||||||
|
|
||||||
rm -f $(DESTDIR)/var/lib/gpclient/scripts/vpnc-script \
|
rm -f $(DESTDIR)/var/lib/gpclient/gpgui \
|
||||||
|
$(DESTDIR)/var/lib/gpclient/scripts/vpnc-script \
|
||||||
$(DESTDIR)/var/lib/gpclient/scripts/vpnc-script.metadata || \
|
$(DESTDIR)/var/lib/gpclient/scripts/vpnc-script.metadata || \
|
||||||
echo "Warning: failed to remove the installed VPN script" >&2
|
echo "Warning: failed to remove gpclient runtime files" >&2
|
||||||
rmdir $(DESTDIR)/var/lib/gpclient/scripts 2>/dev/null || true
|
rmdir $(DESTDIR)/var/lib/gpclient/scripts 2>/dev/null || true
|
||||||
|
rmdir $(DESTDIR)/var/lib/gpclient 2>/dev/null || true
|
||||||
|
|
||||||
clean-debian:
|
clean-debian:
|
||||||
rm -rf .build/deb
|
rm -rf .build/deb
|
||||||
|
|||||||
@@ -41,6 +41,22 @@ const GUI_LIBC_SUFFIX: &str = "-musl";
|
|||||||
#[cfg(not(target_env = "musl"))]
|
#[cfg(not(target_env = "musl"))]
|
||||||
const GUI_LIBC_SUFFIX: &str = "";
|
const GUI_LIBC_SUFFIX: &str = "";
|
||||||
|
|
||||||
|
fn gui_asset_name() -> Option<String> {
|
||||||
|
gui_asset_name_for(std::env::consts::OS, std::env::consts::ARCH, GUI_LIBC_SUFFIX)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gui_asset_name_for(os: &str, arch: &str, libc_suffix: &str) -> Option<String> {
|
||||||
|
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(),
|
||||||
|
("openbsd", "aarch64") => "gpgui_openbsd_arm64.bin.tar.xz".to_owned(),
|
||||||
|
_ => return None,
|
||||||
|
};
|
||||||
|
Some(name)
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ProgressNotifier {
|
pub struct ProgressNotifier {
|
||||||
win: WebviewWindow,
|
win: WebviewWindow,
|
||||||
}
|
}
|
||||||
@@ -366,10 +382,10 @@ impl GuiUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update(&self) {
|
pub async fn update(&self) {
|
||||||
if !cfg!(any(target_arch = "x86_64", target_arch = "aarch64")) {
|
let Some(asset_name) = gui_asset_name() else {
|
||||||
info!("GUI version is not supported on this architecture.");
|
info!("GUI updates are not supported on this platform.");
|
||||||
return;
|
return;
|
||||||
}
|
};
|
||||||
info!("Update GUI, version: {}", self.version);
|
info!("Update GUI, version: {}", self.version);
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
@@ -381,16 +397,8 @@ impl GuiUpdater {
|
|||||||
format!("v{}", self.version)
|
format!("v{}", self.version)
|
||||||
};
|
};
|
||||||
|
|
||||||
let arch = if cfg!(target_arch = "x86_64") {
|
let file_url =
|
||||||
"x86_64"
|
format!("https://github.com/yuezk/GlobalProtect-openconnect/releases/download/{release_tag}/{asset_name}");
|
||||||
} else {
|
|
||||||
"aarch64"
|
|
||||||
};
|
|
||||||
|
|
||||||
let file_url = format!(
|
|
||||||
"https://github.com/yuezk/GlobalProtect-openconnect/releases/download/{}/gpgui_{}{}.bin.tar.xz",
|
|
||||||
release_tag, arch, GUI_LIBC_SUFFIX
|
|
||||||
);
|
|
||||||
let checksum_url = format!("{}.sha256", file_url);
|
let checksum_url = format!("{}.sha256", file_url);
|
||||||
|
|
||||||
info!("Downloading file: {}", file_url);
|
info!("Downloading file: {}", file_url);
|
||||||
@@ -494,6 +502,27 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn selects_platform_specific_gui_assets() {
|
||||||
|
assert_eq!(
|
||||||
|
gui_asset_name_for("linux", "x86_64", ""),
|
||||||
|
Some("gpgui_x86_64.bin.tar.xz".to_owned())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
gui_asset_name_for("linux", "aarch64", "-musl"),
|
||||||
|
Some("gpgui_aarch64-musl.bin.tar.xz".to_owned())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
gui_asset_name_for("freebsd", "x86_64", ""),
|
||||||
|
Some("gpgui_freebsd_amd64.bin.tar.xz".to_owned())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
gui_asset_name_for("openbsd", "aarch64", ""),
|
||||||
|
Some("gpgui_openbsd_arm64.bin.tar.xz".to_owned())
|
||||||
|
);
|
||||||
|
assert_eq!(gui_asset_name_for("macos", "aarch64", ""), None);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn pending_install_reconnects_with_a_fresh_handshake() {
|
async fn pending_install_reconnects_with_a_fresh_handshake() {
|
||||||
let credential = Arc::new(SessionCredential::generate(Uuid::new_v4(), env!("CARGO_PKG_VERSION")).unwrap());
|
let credential = Arc::new(SessionCredential::generate(Uuid::new_v4(), env!("CARGO_PKG_VERSION")).unwrap());
|
||||||
|
|||||||
@@ -31,3 +31,4 @@ nix = { version = "0.31", features = ["fs", "socket", "user"] }
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio-tungstenite = "0.29"
|
tokio-tungstenite = "0.29"
|
||||||
|
sha256.workspace = true
|
||||||
@@ -160,7 +160,10 @@ enum GuiInstallError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn install_gui(src: &str, checksum: &str) -> Result<(), GuiInstallError> {
|
fn install_gui(src: &str, checksum: &str) -> Result<(), GuiInstallError> {
|
||||||
let target = binary_paths::gpgui();
|
install_gui_at(Path::new(src), checksum, &binary_paths::gpgui_update_target())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn install_gui_at(src: &Path, checksum: &str, target: &Path) -> Result<(), GuiInstallError> {
|
||||||
let Some(dir) = target.parent() else {
|
let Some(dir) = target.parent() else {
|
||||||
return Err(GuiInstallError::Install(anyhow::anyhow!(
|
return Err(GuiInstallError::Install(anyhow::anyhow!(
|
||||||
"Failed to get parent directory of GUI binary"
|
"Failed to get parent directory of GUI binary"
|
||||||
@@ -168,7 +171,7 @@ fn install_gui(src: &str, checksum: &str) -> Result<(), GuiInstallError> {
|
|||||||
};
|
};
|
||||||
fs::create_dir_all(dir).map_err(|err| GuiInstallError::Install(err.into()))?;
|
fs::create_dir_all(dir).map_err(|err| GuiInstallError::Install(err.into()))?;
|
||||||
|
|
||||||
let staged_archive = stage_gui_archive(Path::new(src), dir)?;
|
let staged_archive = stage_gui_archive(src, dir)?;
|
||||||
let archive_path = staged_archive.path().to_string_lossy();
|
let archive_path = staged_archive.path().to_string_lossy();
|
||||||
verify_checksum(&archive_path, checksum).map_err(GuiInstallError::Checksum)?;
|
verify_checksum(&archive_path, checksum).map_err(GuiInstallError::Checksum)?;
|
||||||
|
|
||||||
@@ -260,7 +263,7 @@ fn extract_gui_binary<R: Read>(archive: &mut Archive<R>, dir: &Path) -> Result<N
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::io::Cursor;
|
use std::{io::Cursor, os::unix::fs::PermissionsExt};
|
||||||
|
|
||||||
use gpapi::{
|
use gpapi::{
|
||||||
gateway::Gateway,
|
gateway::Gateway,
|
||||||
@@ -270,6 +273,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use tar::{Builder, EntryType, Header};
|
use tar::{Builder, EntryType, Header};
|
||||||
|
use xz2::write::XzEncoder;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@@ -288,6 +292,17 @@ mod tests {
|
|||||||
data
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn compressed_gui_archive(contents: &[u8]) -> NamedTempFile {
|
||||||
|
let tar = archive_with_entry(EntryType::Regular, contents);
|
||||||
|
let mut encoder = XzEncoder::new(Vec::new(), 6);
|
||||||
|
encoder.write_all(&tar).unwrap();
|
||||||
|
let compressed = encoder.finish().unwrap();
|
||||||
|
let mut archive = NamedTempFile::new().unwrap();
|
||||||
|
archive.write_all(&compressed).unwrap();
|
||||||
|
archive.flush().unwrap();
|
||||||
|
archive
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rejects_non_file_and_empty_gui_entries() {
|
fn rejects_non_file_and_empty_gui_entries() {
|
||||||
let output = tempfile::tempdir().unwrap();
|
let output = tempfile::tempdir().unwrap();
|
||||||
@@ -337,6 +352,31 @@ mod tests {
|
|||||||
assert!(extract_gui_binary(&mut archive, output.path()).is_err());
|
assert!(extract_gui_binary(&mut archive, output.path()).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn installs_gui_at_the_supplied_target() {
|
||||||
|
let archive = compressed_gui_archive(b"gui binary");
|
||||||
|
let checksum = sha256::try_digest(archive.path()).unwrap();
|
||||||
|
let output = tempfile::tempdir().unwrap();
|
||||||
|
let target = output.path().join("gpclient/gpgui");
|
||||||
|
|
||||||
|
install_gui_at(archive.path(), &checksum, &target).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(std::fs::read(&target).unwrap(), b"gui binary");
|
||||||
|
assert_eq!(std::fs::metadata(&target).unwrap().permissions().mode() & 0o777, 0o755);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn checksum_failure_preserves_the_existing_gui() {
|
||||||
|
let archive = compressed_gui_archive(b"replacement");
|
||||||
|
let output = tempfile::tempdir().unwrap();
|
||||||
|
let target = output.path().join("gpclient/gpgui");
|
||||||
|
std::fs::create_dir_all(target.parent().unwrap()).unwrap();
|
||||||
|
std::fs::write(&target, b"existing").unwrap();
|
||||||
|
|
||||||
|
assert!(install_gui_at(archive.path(), "invalid", &target).is_err());
|
||||||
|
assert_eq!(std::fs::read(target).unwrap(), b"existing");
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn brokered_mode_rejects_gui_management_and_root_readable_identity_paths() {
|
async fn brokered_mode_rejects_gui_management_and_root_readable_identity_paths() {
|
||||||
let (request_tx, _request_rx) = mpsc::channel(1);
|
let (request_tx, _request_rx) = mpsc::channel(1);
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(debug_assertions),
|
||||||
|
any(target_os = "linux", target_os = "freebsd", target_os = "openbsd")
|
||||||
|
))]
|
||||||
|
use crate::constants::GP_DOWNLOADED_GUI_BINARY;
|
||||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||||
use crate::constants::GP_VPNC_SCRIPT_INSTALLER_BINARY;
|
use crate::constants::GP_VPNC_SCRIPT_INSTALLER_BINARY;
|
||||||
use crate::constants::{GP_AUTH_BINARY, GP_CLIENT_BINARY, GP_GUI_BINARY, GP_GUI_HELPER_BINARY, GP_SERVICE_BINARY};
|
use crate::constants::{GP_AUTH_BINARY, GP_CLIENT_BINARY, GP_GUI_BINARY, GP_GUI_HELPER_BINARY, GP_SERVICE_BINARY};
|
||||||
@@ -32,6 +37,24 @@ pub fn gpgui() -> PathBuf {
|
|||||||
resolve("GP_GUI_BINARY", "gpgui", GP_GUI_BINARY)
|
resolve("GP_GUI_BINARY", "gpgui", GP_GUI_BINARY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn gpgui_update_target() -> PathBuf {
|
||||||
|
#[cfg(all(
|
||||||
|
not(debug_assertions),
|
||||||
|
any(target_os = "linux", target_os = "freebsd", target_os = "openbsd")
|
||||||
|
))]
|
||||||
|
{
|
||||||
|
PathBuf::from(GP_DOWNLOADED_GUI_BINARY)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(
|
||||||
|
debug_assertions,
|
||||||
|
not(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))
|
||||||
|
))]
|
||||||
|
{
|
||||||
|
gpgui()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn gpgui_helper() -> PathBuf {
|
pub fn gpgui_helper() -> PathBuf {
|
||||||
resolve("GP_GUI_HELPER_BINARY", "gpgui-helper", GP_GUI_HELPER_BINARY)
|
resolve("GP_GUI_HELPER_BINARY", "gpgui-helper", GP_GUI_HELPER_BINARY)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ pub const GP_CLIENT_BINARY: &str = "/usr/local/bin/gpclient";
|
|||||||
pub const GP_SERVICE_BINARY: &str = "/usr/local/bin/gpservice";
|
pub const GP_SERVICE_BINARY: &str = "/usr/local/bin/gpservice";
|
||||||
#[cfg(all(not(debug_assertions), any(target_os = "freebsd", target_os = "openbsd")))]
|
#[cfg(all(not(debug_assertions), any(target_os = "freebsd", target_os = "openbsd")))]
|
||||||
pub const GP_GUI_BINARY: &str = "/usr/local/bin/gpgui";
|
pub const GP_GUI_BINARY: &str = "/usr/local/bin/gpgui";
|
||||||
|
#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
|
||||||
|
pub const GP_DOWNLOADED_GUI_BINARY: &str = "/usr/local/libexec/gpclient/gpgui";
|
||||||
#[cfg(all(not(debug_assertions), any(target_os = "freebsd", target_os = "openbsd")))]
|
#[cfg(all(not(debug_assertions), any(target_os = "freebsd", target_os = "openbsd")))]
|
||||||
pub const GP_GUI_HELPER_BINARY: &str = "/usr/local/bin/gpgui-helper";
|
pub const GP_GUI_HELPER_BINARY: &str = "/usr/local/bin/gpgui-helper";
|
||||||
#[cfg(all(not(debug_assertions), any(target_os = "freebsd", target_os = "openbsd")))]
|
#[cfg(all(not(debug_assertions), any(target_os = "freebsd", target_os = "openbsd")))]
|
||||||
@@ -69,6 +71,8 @@ pub const GP_SERVICE_BINARY: &str = "/usr/bin/gpservice";
|
|||||||
not(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd"))
|
not(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd"))
|
||||||
))]
|
))]
|
||||||
pub const GP_GUI_BINARY: &str = "/usr/bin/gpgui";
|
pub const GP_GUI_BINARY: &str = "/usr/bin/gpgui";
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub const GP_DOWNLOADED_GUI_BINARY: &str = "/var/lib/gpclient/gpgui";
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
not(debug_assertions),
|
not(debug_assertions),
|
||||||
not(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd"))
|
not(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd"))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
path::PathBuf,
|
path::{Path, PathBuf},
|
||||||
process::{ExitStatus, Stdio},
|
process::{ExitStatus, Stdio},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
@@ -16,7 +16,7 @@ use super::command_traits::CommandExt;
|
|||||||
|
|
||||||
pub struct GuiLauncher<'a> {
|
pub struct GuiLauncher<'a> {
|
||||||
version: &'a str,
|
version: &'a str,
|
||||||
program: PathBuf,
|
programs: Vec<PathBuf>,
|
||||||
credential: Arc<SessionCredential>,
|
credential: Arc<SessionCredential>,
|
||||||
minimized: bool,
|
minimized: bool,
|
||||||
envs: Option<HashMap<String, String>>,
|
envs: Option<HashMap<String, String>>,
|
||||||
@@ -24,9 +24,17 @@ pub struct GuiLauncher<'a> {
|
|||||||
|
|
||||||
impl<'a> GuiLauncher<'a> {
|
impl<'a> GuiLauncher<'a> {
|
||||||
pub fn new(version: &'a str, credential: Arc<SessionCredential>) -> Self {
|
pub fn new(version: &'a str, credential: Arc<SessionCredential>) -> Self {
|
||||||
|
let primary = binary_paths::gpgui();
|
||||||
|
let update_target = binary_paths::gpgui_update_target();
|
||||||
|
let programs = if primary == update_target {
|
||||||
|
vec![primary]
|
||||||
|
} else {
|
||||||
|
vec![primary, update_target]
|
||||||
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
version,
|
version,
|
||||||
program: binary_paths::gpgui(),
|
programs,
|
||||||
credential,
|
credential,
|
||||||
minimized: false,
|
minimized: false,
|
||||||
envs: None,
|
envs: None,
|
||||||
@@ -44,18 +52,33 @@ impl<'a> GuiLauncher<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn launch(&self) -> anyhow::Result<ExitStatus> {
|
pub async fn launch(&self) -> anyhow::Result<ExitStatus> {
|
||||||
// Check if the program's version
|
if let Some(program) = self.find_compatible_program().await {
|
||||||
if let Err(err) = self.check_version().await {
|
return self.launch_program(&program).await;
|
||||||
info!("Check version failed: {}", err);
|
|
||||||
// Download the program and replace the current one
|
|
||||||
self.download_program().await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.launch_program().await
|
self.download_program().await?;
|
||||||
|
|
||||||
|
let program = binary_paths::gpgui_update_target();
|
||||||
|
self.check_version(&program).await?;
|
||||||
|
self.launch_program(&program).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn launch_program(&self) -> anyhow::Result<ExitStatus> {
|
async fn find_compatible_program(&self) -> Option<PathBuf> {
|
||||||
let mut cmd = Command::new(&self.program);
|
for program in &self.programs {
|
||||||
|
match self.check_version(program).await {
|
||||||
|
Ok(()) => return Some(program.clone()),
|
||||||
|
Err(err) => info!(
|
||||||
|
"GUI candidate {} is unavailable or incompatible: {err}",
|
||||||
|
program.display()
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn launch_program(&self, program: &Path) -> anyhow::Result<ExitStatus> {
|
||||||
|
let mut cmd = Command::new(program);
|
||||||
|
|
||||||
if let Some(envs) = &self.envs {
|
if let Some(envs) = &self.envs {
|
||||||
cmd.env_clear();
|
cmd.env_clear();
|
||||||
@@ -73,7 +96,7 @@ impl<'a> GuiLauncher<'a> {
|
|||||||
let child = non_root_cmd.kill_on_drop(true).stdin(Stdio::piped()).spawn();
|
let child = non_root_cmd.kill_on_drop(true).stdin(Stdio::piped()).spawn();
|
||||||
let mut child = match child {
|
let mut child = match child {
|
||||||
Ok(child) => child,
|
Ok(child) => child,
|
||||||
Err(err) => bail!("Failed to spawn {}: {}", self.program.display(), err),
|
Err(err) => bail!("Failed to spawn {}: {}", program.display(), err),
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(mut stdin) = child.stdin.take() else {
|
let Some(mut stdin) = child.stdin.take() else {
|
||||||
@@ -89,9 +112,18 @@ impl<'a> GuiLauncher<'a> {
|
|||||||
Ok(exit_status)
|
Ok(exit_status)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn check_version(&self) -> anyhow::Result<()> {
|
async fn check_version(&self, program: &Path) -> anyhow::Result<()> {
|
||||||
let cmd = Command::new(&self.program).arg("--version").output().await?;
|
let mut cmd = Command::new(program);
|
||||||
let output = String::from_utf8_lossy(&cmd.stdout);
|
if let Some(envs) = &self.envs {
|
||||||
|
cmd.env_clear();
|
||||||
|
cmd.envs(envs);
|
||||||
|
}
|
||||||
|
cmd.arg("--version");
|
||||||
|
let output = cmd.into_non_root()?.output().await?;
|
||||||
|
if !output.status.success() {
|
||||||
|
bail!("Version command exited with {}", output.status);
|
||||||
|
}
|
||||||
|
let output = String::from_utf8_lossy(&output.stdout);
|
||||||
|
|
||||||
// Version string: "gpgui 2.0.0 (2024-02-05)"
|
// Version string: "gpgui 2.0.0 (2024-02-05)"
|
||||||
let Some(version) = output.split_whitespace().nth(1) else {
|
let Some(version) = output.split_whitespace().nth(1) else {
|
||||||
@@ -114,11 +146,68 @@ impl<'a> GuiLauncher<'a> {
|
|||||||
.envs(self.envs.as_ref())
|
.envs(self.envs.as_ref())
|
||||||
.gui_version(Some(self.version))
|
.gui_version(Some(self.version))
|
||||||
.launch()
|
.launch()
|
||||||
.await?;
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check the version again
|
#[cfg(test)]
|
||||||
self.check_version().await?;
|
mod tests {
|
||||||
|
use std::{fs, os::unix::fs::PermissionsExt};
|
||||||
|
|
||||||
Ok(())
|
use tempfile::TempDir;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
const VERSION: &str = "test-version";
|
||||||
|
|
||||||
|
fn executable(dir: &TempDir, name: &str, output: &str, exit_code: i32) -> PathBuf {
|
||||||
|
let path = dir.path().join(name);
|
||||||
|
fs::write(
|
||||||
|
&path,
|
||||||
|
format!("#!/bin/sh\nprintf '%s\\n' '{output}'\nexit {exit_code}\n"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
fs::set_permissions(&path, fs::Permissions::from_mode(0o755)).unwrap();
|
||||||
|
path
|
||||||
|
}
|
||||||
|
|
||||||
|
fn launcher(version: &'static str, programs: Vec<PathBuf>) -> GuiLauncher<'static> {
|
||||||
|
GuiLauncher {
|
||||||
|
version,
|
||||||
|
programs,
|
||||||
|
credential: Arc::new(SessionCredential::generate(Uuid::new_v4(), version).unwrap()),
|
||||||
|
minimized: false,
|
||||||
|
envs: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn prefers_the_first_compatible_program() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let packaged = executable(&dir, "packaged", "gpgui test-version", 0);
|
||||||
|
let downloaded = executable(&dir, "downloaded", "gpgui test-version", 0);
|
||||||
|
let launcher = launcher(VERSION, vec![packaged.clone(), downloaded]);
|
||||||
|
|
||||||
|
assert_eq!(launcher.find_compatible_program().await, Some(packaged));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn falls_back_when_the_first_program_is_incompatible() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let packaged = executable(&dir, "packaged", "gpgui other-version", 0);
|
||||||
|
let downloaded = executable(&dir, "downloaded", "gpgui test-version", 0);
|
||||||
|
let launcher = launcher(VERSION, vec![packaged, downloaded.clone()]);
|
||||||
|
|
||||||
|
assert_eq!(launcher.find_compatible_program().await, Some(downloaded));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn rejects_an_unsuccessful_version_command() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let program = executable(&dir, "broken", "gpgui test-version", 1);
|
||||||
|
let launcher = launcher(VERSION, vec![program]);
|
||||||
|
|
||||||
|
assert_eq!(launcher.find_compatible_program().await, None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
rm -f \
|
rm -f \
|
||||||
|
/var/lib/gpclient/gpgui \
|
||||||
/var/lib/gpclient/scripts/vpnc-script \
|
/var/lib/gpclient/scripts/vpnc-script \
|
||||||
/var/lib/gpclient/scripts/vpnc-script.metadata ||
|
/var/lib/gpclient/scripts/vpnc-script.metadata ||
|
||||||
echo "Warning: failed to remove the installed VPN script" >&2
|
echo "Warning: failed to remove gpclient runtime files" >&2
|
||||||
rmdir /var/lib/gpclient/scripts 2>/dev/null || true
|
rmdir /var/lib/gpclient/scripts 2>/dev/null || true
|
||||||
|
rmdir /var/lib/gpclient 2>/dev/null || true
|
||||||
@@ -3,22 +3,19 @@ post_install() {
|
|||||||
update-desktop-database -q
|
update-desktop-database -q
|
||||||
}
|
}
|
||||||
|
|
||||||
pre_upgrade() {
|
|
||||||
rm -f /usr/bin/gpgui
|
|
||||||
}
|
|
||||||
|
|
||||||
post_upgrade() {
|
post_upgrade() {
|
||||||
update-mime-database /usr/share/mime
|
update-mime-database /usr/share/mime
|
||||||
update-desktop-database -q
|
update-desktop-database -q
|
||||||
}
|
}
|
||||||
|
|
||||||
post_remove() {
|
post_remove() {
|
||||||
rm -f /usr/bin/gpgui
|
|
||||||
rm -f \
|
rm -f \
|
||||||
|
/var/lib/gpclient/gpgui \
|
||||||
/var/lib/gpclient/scripts/vpnc-script \
|
/var/lib/gpclient/scripts/vpnc-script \
|
||||||
/var/lib/gpclient/scripts/vpnc-script.metadata ||
|
/var/lib/gpclient/scripts/vpnc-script.metadata ||
|
||||||
echo "Warning: failed to remove the installed VPN script" >&2
|
echo "Warning: failed to remove gpclient runtime files" >&2
|
||||||
rmdir /var/lib/gpclient/scripts 2>/dev/null || true
|
rmdir /var/lib/gpclient/scripts 2>/dev/null || true
|
||||||
|
rmdir /var/lib/gpclient 2>/dev/null || true
|
||||||
update-mime-database /usr/share/mime
|
update-mime-database /usr/share/mime
|
||||||
update-desktop-database -q
|
update-desktop-database -q
|
||||||
}
|
}
|
||||||
@@ -53,6 +53,8 @@ uninstall:
|
|||||||
rm -f $(DESTDIR)/usr/share/polkit-1/actions/com.yuezk.gpgui.policy
|
rm -f $(DESTDIR)/usr/share/polkit-1/actions/com.yuezk.gpgui.policy
|
||||||
|
|
||||||
rm -f $(DESTDIR)/var/lib/gpclient/scripts/vpnc-script \
|
rm -f $(DESTDIR)/var/lib/gpclient/scripts/vpnc-script \
|
||||||
|
$(DESTDIR)/var/lib/gpclient/gpgui \
|
||||||
$(DESTDIR)/var/lib/gpclient/scripts/vpnc-script.metadata || \
|
$(DESTDIR)/var/lib/gpclient/scripts/vpnc-script.metadata || \
|
||||||
echo "Warning: failed to remove the installed VPN script" >&2
|
echo "Warning: failed to remove gpclient runtime files" >&2
|
||||||
rmdir $(DESTDIR)/var/lib/gpclient/scripts 2>/dev/null || true
|
rmdir $(DESTDIR)/var/lib/gpclient/scripts 2>/dev/null || true
|
||||||
|
rmdir $(DESTDIR)/var/lib/gpclient 2>/dev/null || true
|
||||||
@@ -3,7 +3,10 @@
|
|||||||
root=${PKG_ROOTDIR:-}
|
root=${PKG_ROOTDIR:-}
|
||||||
|
|
||||||
rm -f \
|
rm -f \
|
||||||
|
"$root/usr/local/libexec/gpclient/gpgui" \
|
||||||
"$root/var/db/gpclient/scripts/vpnc-script" \
|
"$root/var/db/gpclient/scripts/vpnc-script" \
|
||||||
"$root/var/db/gpclient/scripts/vpnc-script.metadata" ||
|
"$root/var/db/gpclient/scripts/vpnc-script.metadata" ||
|
||||||
echo "Warning: failed to remove the installed VPN script" >&2
|
echo "Warning: failed to remove gpclient runtime files" >&2
|
||||||
|
rmdir "$root/usr/local/libexec/gpclient" 2>/dev/null || true
|
||||||
rmdir "$root/var/db/gpclient/scripts" 2>/dev/null || true
|
rmdir "$root/var/db/gpclient/scripts" 2>/dev/null || true
|
||||||
|
rmdir "$root/var/db/gpclient" 2>/dev/null || true
|
||||||
@@ -4,18 +4,12 @@ set -e
|
|||||||
case "$1" in
|
case "$1" in
|
||||||
purge|remove)
|
purge|remove)
|
||||||
rm -f \
|
rm -f \
|
||||||
|
/var/lib/gpclient/gpgui \
|
||||||
/var/lib/gpclient/scripts/vpnc-script \
|
/var/lib/gpclient/scripts/vpnc-script \
|
||||||
/var/lib/gpclient/scripts/vpnc-script.metadata ||
|
/var/lib/gpclient/scripts/vpnc-script.metadata ||
|
||||||
echo "Warning: failed to remove the installed VPN script" >&2
|
echo "Warning: failed to remove gpclient runtime files" >&2
|
||||||
rmdir /var/lib/gpclient/scripts 2>/dev/null || true
|
rmdir /var/lib/gpclient/scripts 2>/dev/null || true
|
||||||
|
rmdir /var/lib/gpclient 2>/dev/null || true
|
||||||
# Remove the gpgui binary downloaded at runtime
|
|
||||||
rm -f /usr/bin/gpgui
|
|
||||||
;;
|
|
||||||
|
|
||||||
upgrade)
|
|
||||||
# Remove the gpgui binary downloaded at runtime
|
|
||||||
rm -f /usr/bin/gpgui
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
post_remove() {
|
post_remove() {
|
||||||
rm -f \
|
rm -f \
|
||||||
|
/var/lib/gpclient/gpgui \
|
||||||
/var/lib/gpclient/scripts/vpnc-script \
|
/var/lib/gpclient/scripts/vpnc-script \
|
||||||
/var/lib/gpclient/scripts/vpnc-script.metadata ||
|
/var/lib/gpclient/scripts/vpnc-script.metadata ||
|
||||||
echo "Warning: failed to remove the installed VPN script" >&2
|
echo "Warning: failed to remove gpclient runtime files" >&2
|
||||||
rmdir /var/lib/gpclient/scripts 2>/dev/null || true
|
rmdir /var/lib/gpclient/scripts 2>/dev/null || true
|
||||||
|
rmdir /var/lib/gpclient 2>/dev/null || true
|
||||||
}
|
}
|
||||||
@@ -51,12 +51,13 @@ A GUI for GlobalProtect VPN, based on OpenConnect, supports the SSO authenticati
|
|||||||
|
|
||||||
%postun
|
%postun
|
||||||
if [ "$1" -eq 0 ]; then
|
if [ "$1" -eq 0 ]; then
|
||||||
rm -f %{_bindir}/gpgui
|
|
||||||
rm -f \
|
rm -f \
|
||||||
|
/var/lib/gpclient/gpgui \
|
||||||
/var/lib/gpclient/scripts/vpnc-script \
|
/var/lib/gpclient/scripts/vpnc-script \
|
||||||
/var/lib/gpclient/scripts/vpnc-script.metadata ||
|
/var/lib/gpclient/scripts/vpnc-script.metadata ||
|
||||||
echo "Warning: failed to remove the installed VPN script" >&2
|
echo "Warning: failed to remove gpclient runtime files" >&2
|
||||||
rmdir /var/lib/gpclient/scripts 2>/dev/null || :
|
rmdir /var/lib/gpclient/scripts 2>/dev/null || :
|
||||||
|
rmdir /var/lib/gpclient 2>/dev/null || :
|
||||||
fi
|
fi
|
||||||
|
|
||||||
%build
|
%build
|
||||||
|
|||||||
Reference in new issue
Block a user