Add self update functionality
Signed-off-by: Jacob Kiers <code@kiers.eu>
This commit is contained in:
parent
95149ffd9f
commit
e6ecdf5ed8
923
Cargo.lock
generated
923
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "l4p"
|
name = "l4p"
|
||||||
version = "0.1.8"
|
version = "0.1.9"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Jacob Kiers <code@kiers.eu>"]
|
authors = ["Jacob Kiers <code@kiers.eu>"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
@ -25,7 +25,9 @@ byte_string = "1"
|
|||||||
bytes = "1.1"
|
bytes = "1.1"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
pico-args = "0.5.0"
|
||||||
pretty_env_logger = "0.5"
|
pretty_env_logger = "0.5"
|
||||||
|
self_update = { version = "0.40.0", features = ["rustls"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_yaml = "0.9.21"
|
serde_yaml = "0.9.21"
|
||||||
time = { version = "0.3.1", features = ["local-offset", "formatting"] }
|
time = { version = "0.3.1", features = ["local-offset", "formatting"] }
|
||||||
|
19
src/main.rs
19
src/main.rs
@ -1,14 +1,33 @@
|
|||||||
mod config;
|
mod config;
|
||||||
mod servers;
|
mod servers;
|
||||||
|
mod update;
|
||||||
mod upstreams;
|
mod upstreams;
|
||||||
|
|
||||||
use crate::config::ConfigV1;
|
use crate::config::ConfigV1;
|
||||||
use crate::servers::Server;
|
use crate::servers::Server;
|
||||||
|
|
||||||
use log::{debug, error, info};
|
use log::{debug, error, info};
|
||||||
|
use pico_args::Arguments;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn main() {
|
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() {
|
let config_path = match find_config() {
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
Err(paths) => {
|
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(_) => (),
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user