addet check-and-remove function
This commit is contained in:
parent
75ef83891e
commit
74b2375cb1
1 changed files with 53 additions and 42 deletions
95
dream.sh
95
dream.sh
|
@ -124,40 +124,23 @@ run-silent() {
|
||||||
check-and-install() {
|
check-and-install() {
|
||||||
local pkglength="${#@}"
|
local pkglength="${#@}"
|
||||||
local accum=0
|
local accum=0
|
||||||
|
local err out
|
||||||
pen grey "Packages to install: $(pen green bold $pkglength)"
|
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
|
line
|
||||||
for pkg in "$@"; do
|
for pkg in "$@"; do
|
||||||
|
# add one to the accum var to display the [$accum/$pkglenght] like [2/8]
|
||||||
((accum++))
|
((accum++))
|
||||||
local count="[${accum}/${pkglength}]"
|
local count="[${accum}/${pkglength}]"
|
||||||
|
|
||||||
if ! command-exists $pkg; then
|
if ! command-exists $pkg; then
|
||||||
spin bold "$(pen bold yellow Installing) $pkg $(pen bold grey $count)"
|
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
|
upclear
|
||||||
check "$(pen bold green Installed) $pkg $(pen bold grey $count)"
|
check "$(pen bold green Installed) $pkg $(pen bold grey $count)"
|
||||||
else
|
else
|
||||||
upclear
|
upclear
|
||||||
throw "Something went wrong! Could not install $(pen bold red $pkg) $(pen bold yellow $count)"
|
throw "Something went wrong! Could not install $(pen bold red $pkg) $(pen bold yellow $count)"
|
||||||
|
pen bold yellow "OUTPUT: ${out:-}"
|
||||||
echo-error "${err:-}"
|
echo-error "${err:-}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
@ -167,6 +150,36 @@ check-and-install() {
|
||||||
fi
|
fi
|
||||||
done
|
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 if the user is root and set sudo variable if necessary >───────────────────────
|
||||||
check_env() {
|
check_env() {
|
||||||
|
@ -174,8 +187,8 @@ check_env() {
|
||||||
if command-exists sudo; then
|
if command-exists sudo; then
|
||||||
_sudo="sudo -E"
|
_sudo="sudo -E"
|
||||||
pen blue "Testing your access.."
|
pen blue "Testing your access.."
|
||||||
line
|
|
||||||
$_sudo echo "${GREEN}${BOLD}Aye, it works!${NC}"
|
$_sudo echo "${GREEN}${BOLD}Aye, it works!${NC}"
|
||||||
|
line
|
||||||
else
|
else
|
||||||
echo-error "No sudo found and you're not root! Can't install packages."
|
echo-error "No sudo found and you're not root! Can't install packages."
|
||||||
return 69
|
return 69
|
||||||
|
@ -233,13 +246,13 @@ _setup() {
|
||||||
fedora)
|
fedora)
|
||||||
pkg-install() {
|
pkg-install() {
|
||||||
pkger=dnf
|
pkger=dnf
|
||||||
$_sudo dnf -y install "$@"
|
$_sudo dnf --assumeyes install "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# CAUTION:
|
# CAUTION:
|
||||||
pkg-remove() {
|
pkg-remove() {
|
||||||
pkger=dnf
|
pkger=dnf
|
||||||
$_sudo dnf -y remove "$@"
|
$_sudo dnf --assumeyes remove "$@"
|
||||||
}
|
}
|
||||||
;;
|
;;
|
||||||
arch)
|
arch)
|
||||||
|
@ -429,12 +442,12 @@ dist_setup() {
|
||||||
# Codename support
|
# Codename support
|
||||||
if [ -n $VERSION_CODENAME ]; then
|
if [ -n $VERSION_CODENAME ]; then
|
||||||
export $VERSION_CODENAME=$VERSION_CODENAME
|
export $VERSION_CODENAME=$VERSION_CODENAME
|
||||||
# case "$VERSION_CODENAME" in
|
# exports the version codename as a variable like..
|
||||||
# trixie) trixie=true ;;
|
# trixie) trixie=true ;;
|
||||||
# bookworm) bookworm=true ;;
|
# bookworm) bookworm=true ;;
|
||||||
# bullseye) bullseye=true ;;
|
# bullseye) bullseye=true ;;
|
||||||
# buster) buster=true ;;
|
# buster) buster=true ;;
|
||||||
# esac
|
# ...
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
ubuntu)
|
ubuntu)
|
||||||
|
@ -443,12 +456,12 @@ dist_setup() {
|
||||||
# Codename support
|
# Codename support
|
||||||
if [ -n $VERSION_CODENAME ]; then
|
if [ -n $VERSION_CODENAME ]; then
|
||||||
export $VERSION_CODENAME=$VERSION_CODENAME
|
export $VERSION_CODENAME=$VERSION_CODENAME
|
||||||
# case "$VERSION_CODENAME" in
|
# exports the version codename as a variable like..
|
||||||
# noble) noble=true ;;
|
# noble) noble=true ;;
|
||||||
# jammy) jammy=true ;;
|
# jammy) jammy=true ;;
|
||||||
# focal) focal=true ;;
|
# focal) focal=true ;;
|
||||||
# bionic) bionic=true ;;
|
# bionic) bionic=true ;;
|
||||||
# esac
|
# ...
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
fedora)
|
fedora)
|
||||||
|
@ -466,6 +479,8 @@ dist_setup() {
|
||||||
else
|
else
|
||||||
aur=false
|
aur=false
|
||||||
fi
|
fi
|
||||||
|
pen bold grey "Arch without the $(pen bold red AUR).."
|
||||||
|
pen bold green "No worries, gonna fix this later.."
|
||||||
;;
|
;;
|
||||||
alpine)
|
alpine)
|
||||||
repen bold "Found $(pen blue bold $distro)"
|
repen bold "Found $(pen blue bold $distro)"
|
||||||
|
@ -481,11 +496,6 @@ dist_setup() {
|
||||||
update-package-list() {
|
update-package-list() {
|
||||||
local USER="${USER:-$(whoami)}"
|
local USER="${USER:-$(whoami)}"
|
||||||
|
|
||||||
repo::check() {
|
|
||||||
check "${distro}-repositories up to date" || upclear
|
|
||||||
throw "Error while updating $distro repositories.."
|
|
||||||
}
|
|
||||||
|
|
||||||
case "$distro" in
|
case "$distro" in
|
||||||
ubuntu | debian)
|
ubuntu | debian)
|
||||||
spin bold red "Refreshing $distro sources.."
|
spin bold red "Refreshing $distro sources.."
|
||||||
|
@ -499,14 +509,15 @@ update-package-list() {
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
fedora)
|
fedora)
|
||||||
spin blue bold "Refreshing $distro repositories.."
|
spin blue bold "Skip refreshing fedora repos, since it auto updates every time.."
|
||||||
if run $_sudo dnf update; then
|
# spin blue bold "Refreshing $distro repositories.."
|
||||||
upclear
|
# if run $_sudo dnf update; then
|
||||||
check "Refreshed $distro sources.."
|
# upclear
|
||||||
else
|
# check "Refreshed $distro sources.."
|
||||||
upclear
|
# else
|
||||||
throw "Error while updating $distro repositories.."
|
# upclear
|
||||||
fi
|
# throw "Error while updating $distro repositories.."
|
||||||
|
# fi
|
||||||
;;
|
;;
|
||||||
arch)
|
arch)
|
||||||
if command-exists pacman; then
|
if command-exists pacman; then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue