From 74b2375cb17cc2c21d91d7477b0dba33f196a51e Mon Sep 17 00:00:00 2001 From: pika Date: Sat, 24 May 2025 12:19:44 +0200 Subject: [PATCH] addet check-and-remove function --- dream.sh | 95 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 42 deletions(-) diff --git a/dream.sh b/dream.sh index 400ef07..16cb980 100644 --- a/dream.sh +++ b/dream.sh @@ -124,40 +124,23 @@ run-silent() { check-and-install() { local pkglength="${#@}" local accum=0 + local err out pen grey "Packages to install: $(pen green bold $pkglength)" - # pkg-eval() { - # for arg in "$@"; do - # case "$arg" in - # check) - # check "$@" - # ;; - # err) - # throw "$@" - # ;; - # spin) - # spin bold "$@" - # ;; - # esac - # done - # } - # if ! pen grey "Packages to install: $(pen green bold $pkglength)"; then - # exit 1 - # fi - # for a in "$@"; do - # pen red bold "DEBUG: $a" - # done line for pkg in "$@"; do + # add one to the accum var to display the [$accum/$pkglenght] like [2/8] ((accum++)) local count="[${accum}/${pkglength}]" + if ! command-exists $pkg; then spin bold "$(pen bold yellow Installing) $pkg $(pen bold grey $count)" - if run --err err pkg-install $pkg; then + if run --err err --out out pkg-install $pkg; then upclear check "$(pen bold green Installed) $pkg $(pen bold grey $count)" else upclear throw "Something went wrong! Could not install $(pen bold red $pkg) $(pen bold yellow $count)" + pen bold yellow "OUTPUT: ${out:-}" echo-error "${err:-}" fi else @@ -167,6 +150,36 @@ check-and-install() { fi done } +# check and removes items inside an array +check-and-remove() { + local pkglength="${#@}" + local accum=0 + local err out + pen grey "Packages to remove: $(pen bold red $pkglength)" + line + for pkg in "$@"; do + # add one to the accum var to display the [$accum/$pkglenght] like [2/8] + ((accum++)) + local count="[${accum}/${pkglength}]" + + if command-exists $pkg; then + spin bold "$(pen bold yellow Removing) $pkg $(pen bold grey $count)" + if run --err err --out out pkg-remove $pkg; then + upclear + check "$(pen bold red Removed) $pkg $(pen bold grey $count)" + else + upclear + throw "Something went wrong! Could not remove $(pen bold yellow $pkg) $(pen bold grey $count)" + pen bold yellow "OUTPUT: ${out:-}" + echo-error "${err:-}" + fi + else + upclear + check bold "$pkg $(pen grey bold 'was already removed') $(pen bold grey $count)" + sleep 0.3 + fi + done +} # ─< Check if the user is root and set sudo variable if necessary >─────────────────────── check_env() { @@ -174,8 +187,8 @@ check_env() { if command-exists sudo; then _sudo="sudo -E" pen blue "Testing your access.." - line $_sudo echo "${GREEN}${BOLD}Aye, it works!${NC}" + line else echo-error "No sudo found and you're not root! Can't install packages." return 69 @@ -233,13 +246,13 @@ _setup() { fedora) pkg-install() { pkger=dnf - $_sudo dnf -y install "$@" + $_sudo dnf --assumeyes install "$@" } # CAUTION: pkg-remove() { pkger=dnf - $_sudo dnf -y remove "$@" + $_sudo dnf --assumeyes remove "$@" } ;; arch) @@ -429,12 +442,12 @@ dist_setup() { # Codename support if [ -n $VERSION_CODENAME ]; then export $VERSION_CODENAME=$VERSION_CODENAME - # case "$VERSION_CODENAME" in + # exports the version codename as a variable like.. # trixie) trixie=true ;; # bookworm) bookworm=true ;; # bullseye) bullseye=true ;; # buster) buster=true ;; - # esac + # ... fi ;; ubuntu) @@ -443,12 +456,12 @@ dist_setup() { # Codename support if [ -n $VERSION_CODENAME ]; then export $VERSION_CODENAME=$VERSION_CODENAME - # case "$VERSION_CODENAME" in + # exports the version codename as a variable like.. # noble) noble=true ;; # jammy) jammy=true ;; # focal) focal=true ;; # bionic) bionic=true ;; - # esac + # ... fi ;; fedora) @@ -466,6 +479,8 @@ dist_setup() { else aur=false fi + pen bold grey "Arch without the $(pen bold red AUR).." + pen bold green "No worries, gonna fix this later.." ;; alpine) repen bold "Found $(pen blue bold $distro)" @@ -481,11 +496,6 @@ dist_setup() { update-package-list() { local USER="${USER:-$(whoami)}" - repo::check() { - check "${distro}-repositories up to date" || upclear - throw "Error while updating $distro repositories.." - } - case "$distro" in ubuntu | debian) spin bold red "Refreshing $distro sources.." @@ -499,14 +509,15 @@ update-package-list() { fi ;; fedora) - spin blue bold "Refreshing $distro repositories.." - if run $_sudo dnf update; then - upclear - check "Refreshed $distro sources.." - else - upclear - throw "Error while updating $distro repositories.." - fi + spin blue bold "Skip refreshing fedora repos, since it auto updates every time.." + # spin blue bold "Refreshing $distro repositories.." + # if run $_sudo dnf update; then + # upclear + # check "Refreshed $distro sources.." + # else + # upclear + # throw "Error while updating $distro repositories.." + # fi ;; arch) if command-exists pacman; then