Make zypper dist-upgrade opt-in on SLE/Leap (#417)
Make zypper dist-upgrade opt-in on SLE/Leap
- Create a `suse_dup` config option
- Create a new `Distribution::OpenSuseTumbleweed` object along with `upgrade_opensuse_tumbleweed()`
* The purpose of it is to ignore the config option on Tumblweed as
zypper `dup` is the only way to update a Tumbleweed
This commit is contained in:
@@ -101,6 +101,7 @@
|
||||
#emerge_sync_flags = "-q"
|
||||
#emerge_update_flags = "-uDNa --with-bdeps=y world"
|
||||
#redhat_distro_sync = false
|
||||
#suse_dup = false
|
||||
#rpm_ostree = false
|
||||
#nix_arguments = "--flake"
|
||||
|
||||
|
||||
@@ -275,6 +275,7 @@ pub struct Linux {
|
||||
apt_arguments: Option<String>,
|
||||
enable_tlmgr: Option<bool>,
|
||||
redhat_distro_sync: Option<bool>,
|
||||
suse_dup: Option<bool>,
|
||||
rpm_ostree: Option<bool>,
|
||||
emerge_sync_flags: Option<String>,
|
||||
emerge_update_flags: Option<String>,
|
||||
@@ -996,6 +997,15 @@ impl Config {
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Use zypper dist-upgrade (same as distro-sync on RH) instead of update (default: false on SLE/Leap, ignored on Tumbleweed (dup is always ran))
|
||||
pub fn suse_dup(&self) -> bool {
|
||||
self.config_file
|
||||
.linux
|
||||
.as_ref()
|
||||
.and_then(|linux| linux.suse_dup)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Use rpm-ostree in *when rpm-ostree is detected* (default: true)
|
||||
pub fn rpm_ostree(&self) -> bool {
|
||||
self.config_file
|
||||
|
||||
@@ -30,6 +30,7 @@ pub enum Distribution {
|
||||
Debian,
|
||||
Gentoo,
|
||||
OpenMandriva,
|
||||
OpenSuseTumbleweed,
|
||||
PCLinuxOS,
|
||||
Suse,
|
||||
SuseMicro,
|
||||
@@ -81,7 +82,12 @@ impl Distribution {
|
||||
} else if id_like.contains(&"centos") {
|
||||
return Ok(Distribution::CentOS);
|
||||
} else if id_like.contains(&"suse") {
|
||||
return Ok(Distribution::Suse);
|
||||
let id_variant = id.unwrap_or_default();
|
||||
if id_variant.contains("tumbleweed") {
|
||||
return Ok(Distribution::OpenSuseTumbleweed);
|
||||
} else {
|
||||
return Ok(Distribution::Suse);
|
||||
}
|
||||
} else if id_like.contains(&"arch") || id_like.contains(&"archlinux") {
|
||||
return Ok(Distribution::Arch);
|
||||
} else if id_like.contains(&"alpine") {
|
||||
@@ -122,6 +128,7 @@ impl Distribution {
|
||||
Distribution::Gentoo => upgrade_gentoo(ctx),
|
||||
Distribution::Suse => upgrade_suse(ctx),
|
||||
Distribution::SuseMicro => upgrade_suse_micro(ctx),
|
||||
Distribution::OpenSuseTumbleweed => upgrade_opensuse_tumbleweed(ctx),
|
||||
Distribution::Void => upgrade_void(ctx),
|
||||
Distribution::Solus => upgrade_solus(ctx),
|
||||
Distribution::Exherbo => upgrade_exherbo(ctx),
|
||||
@@ -243,7 +250,12 @@ fn upgrade_suse(ctx: &ExecutionContext) -> Result<()> {
|
||||
|
||||
ctx.run_type()
|
||||
.execute(sudo)
|
||||
.args(["zypper", "dist-upgrade"])
|
||||
.arg("zypper")
|
||||
.arg(if ctx.config().suse_dup() {
|
||||
"dist-upgrade"
|
||||
} else {
|
||||
"update"
|
||||
})
|
||||
.status_checked()?;
|
||||
} else {
|
||||
print_warning("No sudo detected. Skipping system upgrade");
|
||||
@@ -251,6 +263,26 @@ fn upgrade_suse(ctx: &ExecutionContext) -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn upgrade_opensuse_tumbleweed(ctx: &ExecutionContext) -> Result<()> {
|
||||
if let Some(sudo) = ctx.sudo() {
|
||||
ctx.run_type()
|
||||
.execute(sudo)
|
||||
.args(["zypper", "refresh"])
|
||||
.status_checked()?;
|
||||
|
||||
ctx.run_type()
|
||||
.execute(sudo)
|
||||
.arg("zypper")
|
||||
.arg("dist-upgrade")
|
||||
.status_checked()?;
|
||||
} else {
|
||||
print_warning("No sudo detected. Skipping system upgrade");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn upgrade_suse_micro(ctx: &ExecutionContext) -> Result<()> {
|
||||
if let Some(sudo) = ctx.sudo() {
|
||||
ctx.run_type()
|
||||
|
||||
Reference in New Issue
Block a user