mirror of
				https://github.com/yuezk/GlobalProtect-openconnect.git
				synced 2025-05-20 07:26:58 -04:00 
			
		
		
		
	Install gpgui from archive
This commit is contained in:
		
							
								
								
									
										22
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										22
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| @@ -1527,8 +1527,10 @@ dependencies = [ | |||||||
|  "openconnect", |  "openconnect", | ||||||
|  "serde", |  "serde", | ||||||
|  "serde_json", |  "serde_json", | ||||||
|  |  "tar", | ||||||
|  "tokio", |  "tokio", | ||||||
|  "tokio-util", |  "tokio-util", | ||||||
|  |  "xz2", | ||||||
| ] | ] | ||||||
|  |  | ||||||
| [[package]] | [[package]] | ||||||
| @@ -2198,6 +2200,17 @@ dependencies = [ | |||||||
|  "tracing-subscriber", |  "tracing-subscriber", | ||||||
| ] | ] | ||||||
|  |  | ||||||
|  | [[package]] | ||||||
|  | name = "lzma-sys" | ||||||
|  | version = "0.1.20" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27" | ||||||
|  | dependencies = [ | ||||||
|  |  "cc", | ||||||
|  |  "libc", | ||||||
|  |  "pkg-config", | ||||||
|  | ] | ||||||
|  |  | ||||||
| [[package]] | [[package]] | ||||||
| name = "mac" | name = "mac" | ||||||
| version = "0.1.1" | version = "0.1.1" | ||||||
| @@ -5124,6 +5137,15 @@ version = "0.13.6" | |||||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
| checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" | checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" | ||||||
|  |  | ||||||
|  | [[package]] | ||||||
|  | name = "xz2" | ||||||
|  | version = "0.1.7" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2" | ||||||
|  | dependencies = [ | ||||||
|  |  "lzma-sys", | ||||||
|  | ] | ||||||
|  |  | ||||||
| [[package]] | [[package]] | ||||||
| name = "zeroize" | name = "zeroize" | ||||||
| version = "1.7.0" | version = "1.7.0" | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								Makefile
									
									
									
									
									
								
							| @@ -79,7 +79,7 @@ clean: | |||||||
| 	rm -rf apps/gpgui-helper/node_modules | 	rm -rf apps/gpgui-helper/node_modules | ||||||
|  |  | ||||||
| install: | install: | ||||||
| 	@echo "Installing $(PKG_NAME) $(VERSION)" | 	@echo "Installing $(PKG_NAME)..." | ||||||
|  |  | ||||||
| 	install -Dm755 target/release/gpclient $(DESTDIR)/usr/bin/gpclient | 	install -Dm755 target/release/gpclient $(DESTDIR)/usr/bin/gpclient | ||||||
| 	install -Dm755 target/release/gpauth $(DESTDIR)/usr/bin/gpauth | 	install -Dm755 target/release/gpauth $(DESTDIR)/usr/bin/gpauth | ||||||
| @@ -94,7 +94,7 @@ install: | |||||||
| 	install -Dm644 packaging/files/usr/share/polkit-1/actions/com.yuezk.gpgui.policy $(DESTDIR)/usr/share/polkit-1/actions/com.yuezk.gpgui.policy | 	install -Dm644 packaging/files/usr/share/polkit-1/actions/com.yuezk.gpgui.policy $(DESTDIR)/usr/share/polkit-1/actions/com.yuezk.gpgui.policy | ||||||
|  |  | ||||||
| uninstall: | uninstall: | ||||||
| 	@echo "Uninstalling $(PKG_NAME) $(VERSION)" | 	@echo "Uninstalling $(PKG_NAME)..." | ||||||
|  |  | ||||||
| 	rm -f $(DESTDIR)/usr/bin/gpclient | 	rm -f $(DESTDIR)/usr/bin/gpclient | ||||||
| 	rm -f $(DESTDIR)/usr/bin/gpauth | 	rm -f $(DESTDIR)/usr/bin/gpauth | ||||||
|   | |||||||
| @@ -86,7 +86,7 @@ impl GuiUpdater { | |||||||
|     let arch = "aarch64"; |     let arch = "aarch64"; | ||||||
|  |  | ||||||
|     let file_url = format!( |     let file_url = format!( | ||||||
|       "https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v{}/gpgui_${}_${}.bin.tar.xz", |       "https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v{}/gpgui_{}_{}.bin.tar.xz", | ||||||
|       self.version, self.version, arch |       self.version, self.version, arch | ||||||
|     ); |     ); | ||||||
|     let checksum_url = format!("{}.sha256", file_url); |     let checksum_url = format!("{}.sha256", file_url); | ||||||
|   | |||||||
| @@ -18,3 +18,5 @@ serde_json.workspace = true | |||||||
| env_logger.workspace = true | env_logger.workspace = true | ||||||
| log.workspace = true | log.workspace = true | ||||||
| compile-time.workspace = true | compile-time.workspace = true | ||||||
|  | xz2 = "0.1" | ||||||
|  | tar = "0.4" | ||||||
|   | |||||||
| @@ -1,4 +1,12 @@ | |||||||
| use std::{borrow::Cow, fs::Permissions, ops::ControlFlow, os::unix::fs::PermissionsExt, path::PathBuf, sync::Arc}; | use std::{ | ||||||
|  |   borrow::Cow, | ||||||
|  |   fs::{File, Permissions}, | ||||||
|  |   io::BufReader, | ||||||
|  |   ops::ControlFlow, | ||||||
|  |   os::unix::fs::PermissionsExt, | ||||||
|  |   path::PathBuf, | ||||||
|  |   sync::Arc, | ||||||
|  | }; | ||||||
|  |  | ||||||
| use anyhow::bail; | use anyhow::bail; | ||||||
| use axum::{ | use axum::{ | ||||||
| @@ -17,7 +25,9 @@ use gpapi::{ | |||||||
|   GP_GUI_BINARY, |   GP_GUI_BINARY, | ||||||
| }; | }; | ||||||
| use log::{info, warn}; | use log::{info, warn}; | ||||||
|  | use tar::Archive; | ||||||
| use tokio::fs; | use tokio::fs; | ||||||
|  | use xz2::read::XzDecoder; | ||||||
|  |  | ||||||
| use crate::ws_server::WsServerContext; | use crate::ws_server::WsServerContext; | ||||||
|  |  | ||||||
| @@ -60,6 +70,7 @@ pub async fn update_gui(State(ctx): State<Arc<WsServerContext>>, body: Bytes) -> | |||||||
|   Ok(()) |   Ok(()) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // Unpack GPGUI archive, gpgui_2.0.0_{arch}.bin.tar.xz and install it | ||||||
| async fn install_gui(src: &str) -> anyhow::Result<()> { | async fn install_gui(src: &str) -> anyhow::Result<()> { | ||||||
|   let path = PathBuf::from(GP_GUI_BINARY); |   let path = PathBuf::from(GP_GUI_BINARY); | ||||||
|   let Some(dir) = path.parent() else { |   let Some(dir) = path.parent() else { | ||||||
| @@ -68,8 +79,27 @@ async fn install_gui(src: &str) -> anyhow::Result<()> { | |||||||
|  |  | ||||||
|   fs::create_dir_all(dir).await?; |   fs::create_dir_all(dir).await?; | ||||||
|  |  | ||||||
|   // Copy the file to the final location and make it executable |   // Unpack the archive | ||||||
|   fs::copy(src, GP_GUI_BINARY).await?; |   info!("Unpacking GUI archive"); | ||||||
|  |   let tar = XzDecoder::new(BufReader::new(File::open(src)?)); | ||||||
|  |   let mut ar = Archive::new(tar); | ||||||
|  |  | ||||||
|  |   for entry in ar.entries()? { | ||||||
|  |     let mut entry = entry?; | ||||||
|  |     let path = entry.path()?; | ||||||
|  |  | ||||||
|  |     if let Some(name) = path.file_name() { | ||||||
|  |       let name = name.to_string_lossy(); | ||||||
|  |  | ||||||
|  |       if name == "gpgui" { | ||||||
|  |         let mut file = File::create(GP_GUI_BINARY)?; | ||||||
|  |         std::io::copy(&mut entry, &mut file)?; | ||||||
|  |         break; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   // Make the binary executable | ||||||
|   fs::set_permissions(GP_GUI_BINARY, Permissions::from_mode(0o755)).await?; |   fs::set_permissions(GP_GUI_BINARY, Permissions::from_mode(0o755)).await?; | ||||||
|  |  | ||||||
|   Ok(()) |   Ok(()) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user