diff --git a/config.example.toml b/config.example.toml index 0530a50b..87bbd71a 100644 --- a/config.example.toml +++ b/config.example.toml @@ -50,6 +50,9 @@ # Skip the preamble displayed when topgrade is run #display_preamble = false +# Whether to self update (this is ignored if the binary has been built without self update support, available also via setting the environment variable TOPGRADE_NO_SELF_UPGRADE) +#no_self_update = true + [git] #max_concurrency = 5 # Additional git repositories to pull diff --git a/src/config.rs b/src/config.rs index de2879f8..f3c075be 100644 --- a/src/config.rs +++ b/src/config.rs @@ -336,6 +336,7 @@ pub struct ConfigFile { vagrant: Option, flatpak: Option, distrobox: Option, + no_self_update: Option, } fn config_directory(base_dirs: &BaseDirs) -> PathBuf { @@ -522,6 +523,10 @@ pub struct CommandLineArgs { /// Print roff manpage and exit #[clap(long, hide = true)] pub gen_manpage: bool, + + /// Don't update Topgrade + #[clap(long = "no-self-update")] + pub no_self_update: bool, } impl CommandLineArgs { @@ -645,6 +650,11 @@ impl Config { enabled_steps } + /// Tell whether we should run a self update. + pub fn no_self_update(&self) -> bool { + self.opt.no_self_update || self.config_file.no_self_update.unwrap_or(false) + } + /// Tell whether we should run in tmux. pub fn run_in_tmux(&self) -> bool { self.opt.run_in_tmux || self.config_file.run_in_tmux.unwrap_or(false) diff --git a/src/main.rs b/src/main.rs index 26394893..0d16b617 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,7 +116,9 @@ For more information about this issue see https://askubuntu.com/questions/110969 #[cfg(feature = "self-update")] { - if !run_type.dry() && env::var("TOPGRADE_NO_SELF_UPGRADE").is_err() { + let config_self_upgrade = env::var("TOPGRADE_NO_SELF_UPGRADE").is_err() && !config.no_self_update(); + + if !run_type.dry() && config_self_upgrade { let result = self_update::self_update(); if let Err(e) = &result {