Add self update functionality
Signed-off-by: Jacob Kiers <code@kiers.eu>
This commit is contained in:
19
src/main.rs
19
src/main.rs
@@ -1,14 +1,33 @@
|
||||
mod config;
|
||||
mod servers;
|
||||
mod update;
|
||||
mod upstreams;
|
||||
|
||||
use crate::config::ConfigV1;
|
||||
use crate::servers::Server;
|
||||
|
||||
use log::{debug, error, info};
|
||||
use pico_args::Arguments;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
let mut args = Arguments::from_env();
|
||||
|
||||
match args.subcommand().expect("Unexpected error").as_deref() {
|
||||
Some("serve") => serve(),
|
||||
Some("update") => update::update(),
|
||||
Some(cmd) => {
|
||||
eprintln!("Invalid command: {cmd}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
None => {
|
||||
eprintln!("Calling l4p without argument is deprecated now. Please use: l4p serve");
|
||||
serve();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn serve() {
|
||||
let config_path = match find_config() {
|
||||
Ok(p) => p,
|
||||
Err(paths) => {
|
||||
|
22
src/update.rs
Normal file
22
src/update.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use self_update::{cargo_crate_version, version};
|
||||
|
||||
pub(crate) fn update() {
|
||||
println!("Updating to the latest version...");
|
||||
|
||||
let backend = self_update::backends::gitea::Update::configure()
|
||||
.with_host("https://code.kiers.eu")
|
||||
.repo_owner("jjkiers")
|
||||
.repo_name("layer4-proxy")
|
||||
.bin_name("l4p")
|
||||
.show_download_progress(true)
|
||||
.current_version(cargo_crate_version!())
|
||||
.build()
|
||||
.expect("Should initialize correctly.");
|
||||
|
||||
let status = backend.update_extended();
|
||||
|
||||
match status {
|
||||
Err(e) => eprintln!("Error updating: {e}"),
|
||||
Ok(_) => (),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user