From 7f54b3a921bc10823c46132af99b9b956e465022 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 9 Jan 2019 11:02:32 +0100 Subject: [PATCH] Fixed bug in update --- zsh/update.zsh | 77 +++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/zsh/update.zsh b/zsh/update.zsh index 37b9caa..43d4507 100644 --- a/zsh/update.zsh +++ b/zsh/update.zsh @@ -59,60 +59,61 @@ update-rust() { # Update rust if installed command -v rustup > /dev/null 2>&1 - if [ $? -eq 0 ]; then + if [ $? -ne 0 ]; then + return + fi - start_rust_update=`date +%s` - echo "\033[32;1m=== Updating rustup ===\033[0m" - rustup self update + start_rust_update=`date +%s` + echo "\033[32;1m=== Updating rustup ===\033[0m" + rustup self update - echo "\033[32;1m=== Updating rust ===\033[0m" - rustup update + echo "\033[32;1m=== Updating rust ===\033[0m" + rustup update - cargo install-update --help > /dev/null 2>&1 + cargo install-update --help > /dev/null 2>&1 + if [ $? -ne 0 ]; then + + pkg-config --libs --cflags openssl > /dev/null 2>&1 + + # We need to install openssl if [ $? -ne 0 ]; then - pkg-config --libs --cflags openssl > /dev/null 2>&1 - - # We need to install openssl - if [ $? -ne 0 ]; then - - # Ask for sudo right now - sudoresult=$(sudo -nv 2>&1) + # Ask for sudo right now + sudoresult=$(sudo -nv 2>&1) + if [ $? -eq 0 ]; then + command -v apt > /dev/null 2>&1 if [ $? -eq 0 ]; then - 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 + 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 - echo "\033[32;1m=== Installing rust packages updater ===\033[0m" - cargo install cargo-update fi - echo "\033[32;1m=== Updating rust packages ===\033[0m" - cargo install-update -ag + echo "\033[32;1m=== Installing rust packages updater ===\033[0m" + cargo install cargo-update fi + echo "\033[32;1m=== Updating rust packages ===\033[0m" + cargo install-update -ag + seconds=$((`date +%s` - $start_rust_update )) formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` echo "\033[32;1m=== Rust updated in $formatted ===\033[0m"