diff --git a/zsh/update.zsh b/zsh/update.zsh index c2eb81c..37b9caa 100644 --- a/zsh/update.zsh +++ b/zsh/update.zsh @@ -1,4 +1,22 @@ update-system() { + + # Ask for sudo right now + sudoresult=$(sudo -nv 2>&1) + + if [ $? -eq 0 ]; then + # Nothing to do + elif echo $sudoresult | grep -q '^sudo:'; then + echo "\033[32;1m=== Starting system update, please enter your password ===\033[0m" + sudo true + if [ $? -ne 0 ]; then + echo "Could not get sudo..." + return 1 + fi + else + echo "\033[33;1m=== You are not a sudoer, skipping system update... ===\033[0m" + return 1 + fi + echo "\033[32;1m=== Updating system ===\033[0m" start_system_update=`date +%s` @@ -55,18 +73,34 @@ update-rust() { if [ $? -ne 0 ]; then pkg-config --libs --cflags openssl > /dev/null 2>&1 + + # We need to install openssl if [ $? -ne 0 ]; then - # We need to install openssl - command -v apt > /dev/null 2>&1 - if [ $? -eq 0 ]; then - sudo apt install -y libssl-dev - fi + # Ask for sudo right now + sudoresult=$(sudo -nv 2>&1) - # For fedora - command -v dnf > /dev/null 2>&1 if [ $? -eq 0 ]; then - sudo dnf install openssl-devel + command -v apt > /dev/null 2>&1 + if [ $? -eq 0 ]; then + sudo apt install -y libssl-dev + fi + + # For fedora + command -v dnf > /dev/null 2>&1 + if [ $? -eq 0 ]; then + sudo dnf install openssl-devel + fi + elif echo $sudoresult | grep -q '^sudo:'; then + echo "\033[32;1m=== libssl-dev is needed to update rust packages, please enter your password ===\033[0m" + sudo true + if [ $? -ne 0 ]; then + echo "Could not get sudo..." + return 1 + fi + else + echo "\033[33;1m=== You are not a sudoer, cannot install cargo-update... ===\033[0m" + return 1 fi fi @@ -111,15 +145,7 @@ update-dotfiles() { update() { start=`date +%s` - echo "\033[32;1m=== Starting the update, please enter your password ===\033[0m" - - # Ask for sudo right now - sudo true - - if [ $? -ne 0 ]; then - echo "Could not get sudo..." - return 1 - fi + echo "\033[32;1m=== Starting update ===\033[0m" # Update the system update-system