From 3928f759bf29eb4631a03cc7c00c458b7cc363a9 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 6 May 2022 11:14:09 +0200 Subject: [PATCH] updated the update() function to support macOS/brew --- zsh-david.plugin.zsh | 79 ++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 29 deletions(-) diff --git a/zsh-david.plugin.zsh b/zsh-david.plugin.zsh index f21cfff..18a356b 100644 --- a/zsh-david.plugin.zsh +++ b/zsh-david.plugin.zsh @@ -54,13 +54,14 @@ alias {dc,compose}="docker-compose" alias d="docker" alias p="podman" alias vanity="docker run --rm -it socialnerds/wg-vanity-address:latest --in 6" - +alias mp="multipass" #alias {p,pass}="gopass" alias {a,apt}="sudo apt" alias {u,ufw}="sudo ufw" alias LG_ultrafine_brightness="sudo LG_ultrafine_brightness" + # **** function definitions **** ## output handling @@ -99,39 +100,59 @@ log() { sleep 0.5; echo -e "[$level] ${@:2}" } -## OS upgrade for various systems -update-os() { - systems="ubuntu arch solus raspbian antergos elementary" - issue="$(cat /etc/issue)" - for item in $systems; do - echo $issue | grep -i $item >> /dev/null +## Update systems packages +update() { + bold=$(tput bold) + normal=$(tput sgr0) + if [ "$(uname)" = "Darwin" ]; then + log info "macOS detected. Using ${bold}brew${normal} to update packages." + brew update && brew upgrade if [ $? -eq 0 ]; then - system=$item + log success "All packages up-to-date." + else + log error "Something went wrong while running brew." fi - done + else + #if not Darwin then its probably Linux + systems="ubuntu arch raspbian antergos elementary" + issue="$(cat /etc/issue)" + for item in $systems; do + echo $issue | grep -i $item >> /dev/null + if [ $? -eq 0 ]; then + system=$item + fi + done + case $system in + ubuntu|debian|raspbian|elementary) + log info "Debian based system detected. Using ${bold}apt${normal} to update packages." + sudo apt update && sudo apt dist-upgrade -y && sudo apt autoremove -y && sudo apt autoclean -y + if [ $? -eq 0 ]; then + log success "All packages up-to-date." + else + log error "Something went wrong while running ${bold}apt${normal}." + fi + ;; + arch|antergos) + log info "Arch Linux detected. Using ${bold}pacman${normal} to update packages." + sudo pacman -Syu --noconfirm + if [ $? -eq 0 ]; then + log success "All packages up-to-date." + else + log error "Something went wrong while running ${bold}pacman${normal}." + fi - case $system in - ubuntu|debian|raspbian|elementary) - log info "Updating Debian based system.." - sudo apt update && sudo apt dist-upgrade -y && sudo apt autoremove -y && sudo apt autoclean -y - ;; - arch|antergos) - log info "Updating Arch Linux.." - sudo pacman -Syu - ;; - solus) - log info "Updating Solus OS.." - sudo eopkg update-repo && sudo eopkg upgrade - ;; - ?) - log error "error: unknown system." + ;; + ?) + log error "Unknown system. Aborting." + return 1 + ;; + esac + + if [ $? -ne 0 ]; then + echo "error: something went wrong." return 1 - ;; - esac + fi - if [ $? -ne 0 ]; then - echo "error: something went wrong." - return 1 fi }