diff --git a/.gitignore b/.gitignore index e2c517d..2020be3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .gitignore.swp -osupdater/debug*/ -osupdater/target*/ -osupdater/release*/ +debug*/ +target*/ +release*/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 285d254..7de0690 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,27 @@ +# 0.9.1 +## FIXES +* Updated the firmware portion to force the db update + +# 0.9 +## FEATURES +* Added firmware updating via fwupdmgr + # 0.8.0 Cumulative update of all the enhancements that are now in the rust version, but never made it into the bash/python3 version: +## FEATURES +* Added proper cli handling via clap * Specify which updater(s) to use * Smart binary search and execution -* Public git repo +* Made git repository public * Proper documentation * Testing on alternate platforms, and the documentation on how to do so -* All components of the code are now functions, which means a bit more flexibility and reliability.d +* All components of the code are now functions, which means a bit more flexibility and reliability +* Added various other updating tools. Now includes apt, dnf, pacman, zypper, flatpak (user and system), snap, podman (user and system), distrobox (user and system), python (user only) +## FIXES +* Fixed dnf handling to not state dnf was found but using dnf5 instead. Fixed for f41, as dn5 is the only version, and dnf3 no longer is there but dnf is a symlink to dnf5 +* Cleaned up cli output. Not a permanent style, per se. However I am looking to simplify the code's requirements, meaning anything fancy will be removed. Cleaner output will be reworked a final time once logging is implemented. # 0.1.0 -Initial conversion from the python version. +Initial conversion from the python version. No new functionality, no lost functionality. diff --git a/osupdater/Cargo.lock b/Cargo.lock similarity index 61% rename from osupdater/Cargo.lock rename to Cargo.lock index 1b17ca1..8f7ad5d 100644 --- a/osupdater/Cargo.lock +++ b/Cargo.lock @@ -1,12 +1,12 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "anstream" -version = "0.6.15" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" dependencies = [ "anstyle", "anstyle-parse", @@ -19,33 +19,33 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" [[package]] name = "anstyle-parse" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" dependencies = [ "windows-sys", ] [[package]] name = "anstyle-wincon" -version = "3.0.4" +version = "3.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" dependencies = [ "anstyle", "windows-sys", @@ -53,9 +53,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.19" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7be5744db7978a28d9df86a214130d106a89ce49644cbc4e3f0c22c3fba30615" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" dependencies = [ "clap_builder", "clap_derive", @@ -63,9 +63,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.19" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5fbc17d3ef8278f55b282b2a2e75ae6f6c7d4bb70ed3d0382375104bfafdb4b" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" dependencies = [ "anstream", "anstyle", @@ -87,24 +87,24 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "color-print" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee543c60ff3888934877a5671f45494dd27ed4ba25c6670b9a7576b7ed7a8c0" +checksum = "3aa954171903797d5623e047d9ab69d91b493657917bdfb8c2c80ecaf9cdb6f4" dependencies = [ "color-print-proc-macro", ] [[package]] name = "color-print-proc-macro" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ff1a80c5f3cb1ca7c06ffdd71b6a6dd6d8f896c42141fbd43f50ed28dcdb93" +checksum = "692186b5ebe54007e45a59aea47ece9eb4108e141326c304cdc91699a7118a22" dependencies = [ "nom", "proc-macro2", @@ -114,9 +114,21 @@ dependencies = [ [[package]] name = "colorchoice" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" [[package]] name = "heck" @@ -124,6 +136,16 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "indexmap" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" +dependencies = [ + "equivalent", + "hashbrown", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -154,17 +176,19 @@ dependencies = [ [[package]] name = "osupdater" -version = "0.8.0" +version = "0.9.1" dependencies = [ "clap", "color-print", + "serde", + "toml", ] [[package]] name = "proc-macro2" -version = "1.0.87" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -178,6 +202,35 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "serde" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", +] + [[package]] name = "strsim" version = "0.11.1" @@ -186,9 +239,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.79" +version = "2.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035" dependencies = [ "proc-macro2", "quote", @@ -196,10 +249,44 @@ dependencies = [ ] [[package]] -name = "unicode-ident" -version = "1.0.13" +name = "toml" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "unicode-ident" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "utf8parse" @@ -209,9 +296,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "windows-sys" -version = "0.52.0" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ "windows-targets", ] @@ -279,3 +366,12 @@ name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6f5bb5257f2407a5425c6e749bfd9692192a73e70a6060516ac04f889087d68" +dependencies = [ + "memchr", +] diff --git a/osupdater/Cargo.toml b/Cargo.toml similarity index 82% rename from osupdater/Cargo.toml rename to Cargo.toml index 1396548..4ff39e0 100644 --- a/osupdater/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "osupdater" -version = "0.8.0" +version = "0.9.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -8,3 +8,5 @@ edition = "2021" [dependencies] clap = { version = "4.5.18", features = ["cargo", "derive"] } color-print = "0.3.5" +serde = "1.0.217" +toml = "0.8.19" diff --git a/README.md b/README.md index 16481c9..71c42d1 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,7 @@ Prior to releasing a v1.0, I will need the following features for the CLI versio | File | Function | | :--| :-- | -| ./antiquated/ | bash & python source | -| ./osupdater/ | rust source | +| ./src | rust source | | ./rust_build_osupdater.sh | bash script to build the source | ## **TESTED ENVIRONMENTS** @@ -57,7 +56,7 @@ Trusted contributors will count as a passed/failed contributor test. |OTHER TOOLS|PERSONALLY TESTED|CONTRIBUTOR TESTED| | :-- | :-- | :-- | |Python via pip-review|yes|no| - +|Firmware via fwupdmgr|yes|no| ## **COMPILATION** In the repo there is a build script that will build things for you. To do so follow the instructions below to setup your build environment. You can also use __**cargo**__ to build and install as well, but again, the build environment will need to be setup. @@ -192,6 +191,8 @@ or * distrobox * podman +* **Firmware** + * firmware (via fwupdmgr) ## **NOTES** During testing via distrobox, pip-review will fail if the host python version is not the same as the container. The tool will find the pip-review package, but be unable to execute due to a version mismatch. diff --git a/antiquated/assets/arch.png b/antiquated/assets/arch.png deleted file mode 100644 index e8c4c25..0000000 Binary files a/antiquated/assets/arch.png and /dev/null differ diff --git a/antiquated/assets/deb.png b/antiquated/assets/deb.png deleted file mode 100644 index 0890c21..0000000 Binary files a/antiquated/assets/deb.png and /dev/null differ diff --git a/antiquated/assets/flatpak.png b/antiquated/assets/flatpak.png deleted file mode 100644 index 775bacc..0000000 Binary files a/antiquated/assets/flatpak.png and /dev/null differ diff --git a/antiquated/assets/rpm.png b/antiquated/assets/rpm.png deleted file mode 100644 index 28e1faf..0000000 Binary files a/antiquated/assets/rpm.png and /dev/null differ diff --git a/antiquated/assets/snap.png b/antiquated/assets/snap.png deleted file mode 100644 index 9b1b42d..0000000 Binary files a/antiquated/assets/snap.png and /dev/null differ diff --git a/antiquated/bash/osupdater.sh b/antiquated/bash/osupdater.sh deleted file mode 100755 index 77b85f1..0000000 --- a/antiquated/bash/osupdater.sh +++ /dev/null @@ -1,116 +0,0 @@ -#!/bin/bash - -# Universal updater by Andrew Schott andrew@schotty.com -# Will detect and update via various packaging formats for distros I currently use. - -# Globals -# edit as needed to set colors and soforth -# presuming echo thus tput is chosen here as default\ - -# tput text formatting -# bold=bold dim=dimmed -# rev=reverse bel=bell sound -# smul=underline on rmul=underline off -# setaf=foreground setab=background -# sgr0=clear -# -# Colors -# 0 Black 1 Red 2 Green 3 Yellow -# 4 Blue 5 Magenta 6 Cyan 7 White -# -# Default is -# * green for a true finding -# * yellow for a false finding -# * clear at the end to resume normal output for said command's output - -CMD_NOTIFY="tput rev bold setaf 7 setab 0" -CMD_TRUE="tput rev bold setaf 2 setab 0" -CMD_FALSE="tput rev bold setaf 1 setab 7" -CMD_CLEAR="tput sgr0" - -echo $($CMD_NOTIFY)"Looking for native package managers"$($CMD_CLEAR) - -# apt -- Debian and derivatives -if `which apt &> /dev/null 2>&1` -then - echo $($CMD_TRUE)"Found apt. Updating: ($(which apt))"$($CMD_CLEAR) - sudo apt udate -y - sudo apt upgrade -y -else - echo $($CMD_FALSE)"apt not found/needed"$($CMD_CLEAR) -fi - -# dnf -- RHEL 8+, Fedora, Openmandriva, and derivatives -if `which dnf &> /dev/null 2>&1` -then - echo $($CMD_TRUE)"Found dnf. Updating: ($(which dnf))"$($CMD_CLEAR) - sudo dnf --refresh --skip-broken --nobest -y update -else - echo $($CMD_FALSE)"dnf not found/needed"$($CMD_CLEAR) -fi - -# pacman -- arch & arch derivatives -if `which pacman &> /dev/null 2>&1` -then - echo $($CMD_TRUE)"Found pacman. Updating: ($(which pacman))"$($CMD_CLEAR) - sudo pacman -Syu -else - echo $($CMD_FALSE)"pacman not found/needed"$($CMD_CLEAR) -fi - -# yum -- RHEL 7 > (Ignored if dnf is present) -if `which yum &> /dev/null 2>&1` && ! `which dnf &> /dev/null 2>&1` -then - echo $($CMD_TRUE)"Found yum. Updating: ($(which yum))"$($CMD_CLEAR) - sudo yum --refresh --skip-broken --nobest -y update -else - echo $($CMD_FALSE)"yum not found/needed"$($CMD_CLEAR) -fi - -# urpmi -- Mageia -if `which urpmi &> /dev/null 2>&1` && ! `which dnf &> /dev/null 2>&1` -then - echo $($CMD_TRUE)"Found urpmi. Updating: ($(which urpmi))"$($CMD_CLEAR) - sudo urpmi --auto-update -y -else - echo $($CMD_FALSE)"urpmi not found/needed"$($CMD_CLEAR) -fi - -# zypper -- SuSE products -if `which zypper &> /dev/null 2>&1` -then - echo $($CMD_TRUE)"Found zypper. Updating: ($(which zypper))"$($CMD_CLEAR) - sudo zypper in -y -else - echo $($CMD_FALSE)"zypper not found/needed"$($CMD_CLEAR) -fi - -echo $($CMD_NOTIFY)"Looking for sandboxed package managers"$($CMD_CLEAR) - -# flatpak -if `which flatpak &> /dev/null 2>&1` -then - echo $($CMD_TRUE)"Found flatpak. Updating: ($(which flatpak))"$($CMD_CLEAR) - flatpak update --user -y - sudo flatpak update -y -else - echo $($CMD_FALSE)"flatpak not found/needed"$($CMD_CLEAR) -fi - -# snap -if `which snap &> /dev/null 2>&1` -then - echo $($CMD_TRUE)"Found snap. Updating: ($(which snap))"$($CMD_CLEAR) - sudo snap refresh -y -else - echo $($CMD_FALSE)"snap not found/needed"$($CMD_CLEAR) -fi - -# pip -if `which pip-review &> /dev/null 2>&1` -then - echo $($CMD_TRUE)"Found pip-review. Updating: ($(pip-review))"$($CMD_CLEAR) - pip-review --auto --local --user -else - echo $($CMD_FALSE)"pip-review not found/needed"$($CMD_CLEAR) -fi diff --git a/antiquated/python/osupdater.py b/antiquated/python/osupdater.py deleted file mode 100755 index 8c0efee..0000000 --- a/antiquated/python/osupdater.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python - -import wx -import subprocess - - -class Example(wx.Frame): - def __init__(self, *args, **kwargs): - super(Example, self).__init__(*args, **kwargs) - - self.initui() - - def initui(self): - - menubar = wx.MenuBar() - filemenu = wx.Menu() - fileitem = filemenu.Append(wx.ID_EXIT, 'Quit', 'Quit application') - menubar.Append(filemenu, '&File') - self.SetMenuBar(menubar) - - self.Bind(wx.EVT_MENU, self.onquit, fileitem) - - self.SetSize((300, 200)) - self.SetTitle('OS Updater') - self.Centre() - - pnl = wx.Panel(self) - updateflatpakbutton = wx.Button(pnl, label='Update Flatpaks', pos=(20, 20)) - updateflatpakbutton.Bind(wx.EVT_BUTTON, self.onflatpakupdate) - updaterpmbutton = wx.Button(pnl, label='Update RPMs', pos=(20, 60)) - updaterpmbutton.Bind(wx.EVT_BUTTON, self.onrpmupdate) - - def onflatpakupdate(self, e): - subprocess.run(["flatpak", "update", "-y"]) - - def onrpmupdate(self, e): - subprocess.run(["sudo", "dnf", "update", "-y"]) - - def onquit(self, e): - self.Close() - - -def main(): - - app = wx.App(0) - ex = Example(None) - ex.Show() - app.MainLoop() - - -if __name__ == '__main__': - main() diff --git a/config.template b/config.template new file mode 100644 index 0000000..9d9693d --- /dev/null +++ b/config.template @@ -0,0 +1,17 @@ +[PackageManagers] +apt = n +dnf = y +pacman = n +python = n +urpmi = n +zypper = n + +[Firmware] +firmware = y + +[Containers] +distrobox = y +flatpak = y +podman = y +snap = n + diff --git a/osupdater.d b/osupdater.d deleted file mode 100644 index d755618..0000000 --- a/osupdater.d +++ /dev/null @@ -1 +0,0 @@ -/home/andrew/workspace/git_repos/osupdater/in_development/rust/osupdater/target/release/osupdater: /home/andrew/workspace/git_repos/osupdater/in_development/rust/osupdater/src/main.rs diff --git a/rust_build_osupdater.sh b/rust_build_osupdater.sh index 8f3fe2d..6c574e4 100755 --- a/rust_build_osupdater.sh +++ b/rust_build_osupdater.sh @@ -1,8 +1,6 @@ #!/bin/sh echo -e "Cleaning up build environment" -rm -rf osupdater/target -echo -e "Entering build directory\n" -cd osupdater/ +rm -rf target/ echo -e "Building osupdater\n" cargo build -r --jobs $(nproc) #echo -e "Copying binary to git root\n" diff --git a/osupdater/src/main.rs b/src/main.rs similarity index 85% rename from osupdater/src/main.rs rename to src/main.rs index 6a47738..791170d 100644 --- a/osupdater/src/main.rs +++ b/src/main.rs @@ -3,7 +3,13 @@ use std::path::{Path}; use color_print::{cprintln}; use clap::{command, Arg, ArgAction}; -const VERSION: &'static str = "0.8"; +//use std::fs::File; +//use std::io::Write; +//use serde::Serialize; +//use toml::to_string; + + +const VERSION: &'static str = "0.9.1"; fn trim_newline(s: &mut String) { if s.ends_with('\n') { @@ -14,6 +20,35 @@ fn trim_newline(s: &mut String) { } } +/*fn toml_create_default () { + #[derive(Serialize)] + struct toml_data { + config: PackageManagers, + config: Firmware, + config: Containers, + } + + struct PackageMangers { + apt: bool, + dnf: bool, + pacman: bool, + python: bool, + urppmi: bool, + zypper: bool, + } + + struct Firmware { + firmware: bool + } + + struct Containers { + distrobox: bool, + flatpak: bool, + podman: bool, + snap: bool, + } +}*/ + fn update_apt() { let find_sudo = Command::new("which") .arg("sudo").stdout(Stdio::piped()).output().unwrap(); @@ -106,11 +141,6 @@ fn update_flatpak() { let mut sudo_bin = String::from_utf8(find_sudo.stdout).unwrap(); trim_newline(&mut sudo_bin); - let find_sudo = Command::new("which") - .arg("sudo").stdout(Stdio::piped()).output().unwrap(); - let mut sudo_bin = String::from_utf8(find_sudo.stdout).unwrap(); - trim_newline(&mut sudo_bin); - let find_flatpak = Command::new("which") .arg("flatpak").stdout(Stdio::piped()).output().unwrap(); let mut flatpak_bin = String::from_utf8(find_flatpak.stdout).unwrap(); @@ -138,6 +168,37 @@ fn update_flatpak() { } } +fn update_firmware() { + let find_sudo = Command::new("which") + .arg("sudo").stdout(Stdio::piped()).output().unwrap(); + let mut sudo_bin = String::from_utf8(find_sudo.stdout).unwrap(); + trim_newline(&mut sudo_bin); + + let find_fwupdmgr = Command::new("which") + .arg("fwupdmgr").stdout(Stdio::piped()).output().unwrap(); + let mut fwupdmgr_bin = String::from_utf8(find_fwupdmgr.stdout).unwrap(); + trim_newline(&mut fwupdmgr_bin); + + let path = Path::new(&fwupdmgr_bin); + if path.exists(){ + cprintln!("osupdater: Updating firware db"); + let mut cmd = + Command::new(&sudo_bin) + .arg(&fwupdmgr_bin).arg("refresh").arg("-y").arg("--force") + .stdout(Stdio::inherit()).stderr(Stdio::inherit()) + .spawn().unwrap(); + let _output = cmd.wait(); + cprintln!("osupdater: Updating firware"); + let mut cmd = + Command::new(&sudo_bin) + .arg(&fwupdmgr_bin).arg("get-updates").arg("-y") + .stdout(Stdio::inherit()).stderr(Stdio::inherit()) + .spawn().unwrap(); + let _output = cmd.wait(); + } + +} + fn update_pacman() { let find_sudo = Command::new("which") .arg("sudo").stdout(Stdio::piped()).output().unwrap(); @@ -331,6 +392,10 @@ fn update_all() { cprintln!("osupdater: Checking containers"); update_distrobox(); update_podman(); + + // Update firmware + cprintln!("osupdater: Checking firmware"); + update_firmware(); } fn main() { @@ -338,6 +403,20 @@ fn main() { // Clear terminal, and move cursor to 1,1 inside the terminal // print!("{esc}[2J{esc}[1;1H", esc = 27 as char); + // Check for default ini file's existence and + // create new one if file does not exist + + // let toml_exists = Path::new("~/.config/osupdater.toml").exists(); + // if toml_exists == false { + // println!("No config file found"); + // println!("Creating new config at : ~/.config/osupdater.toml"); + // //toml_create_default (); + //} else if toml_exists == true { + // println!("Config file found at ~/.config/osupater.toml"); + //} + + // Parse ini + // Find sudo let find_sudo = Command::new("which") .arg("sudo").stdout(Stdio::piped()).output().unwrap(); @@ -349,7 +428,7 @@ fn main() { .arg( Arg::new("UPDATE_TOOL") .help("What updater to run") - .value_parser(["all", "apt", "distrobox", "dnf", "flatpak", "pacman","podman", "python","snap", "urpmi", "zypper"]) + .value_parser(["all", "apt", "distrobox", "dnf", "flatpak", "firmware", "pacman","podman", "python","snap", "urpmi", "zypper"]) .required(false) .default_value("all") .action(ArgAction::Append) @@ -387,6 +466,10 @@ fn main() { update_flatpak() } + if args.contains(&"firmware") { + update_firmware() + } + if args.contains(&"pacman") { update_pacman() }