From b76e72a1efac925ad8b5a07e240b128983c6770d Mon Sep 17 00:00:00 2001 From: Bruno21 Date: Thu, 16 Nov 2023 15:00:35 +0100 Subject: [PATCH] Test internet connection -run scripts only if internet is ok --- plugins.d/homebrew.sh | 7 +++++++ plugins.d/nodejs.sh | 8 ++++++++ plugins.d/pecl.sh | 10 ++++++++-- plugins.d/perl.sh | 25 +++++++++++++++++++++++-- plugins.d/pip.sh | 7 +++++++ plugins.d/pipx.sh | 7 +++++++ plugins.d/rustup.sh | 7 +++++++ plugins.d/venv.sh | 11 +++++++++-- 8 files changed, 76 insertions(+), 6 deletions(-) diff --git a/plugins.d/homebrew.sh b/plugins.d/homebrew.sh index 2e3afa3..4dce3dc 100755 --- a/plugins.d/homebrew.sh +++ b/plugins.d/homebrew.sh @@ -152,6 +152,13 @@ get_info_pkg() { echo -e "${bold}🍺 Homebrew ${reset}" +curl -Is http://www.google.com | head -1 | grep 200 1>/dev/null +if [[ $? -eq 1 ]]; then + echo -e "\n${red}No Internet connection !${reset}" + echo -e "Exit !" + exit 1 +fi + echo -e "\n🍺 ${underline}Updating brew...${reset}\n" brew update diff --git a/plugins.d/nodejs.sh b/plugins.d/nodejs.sh index e5c6f6b..7a36d6f 100755 --- a/plugins.d/nodejs.sh +++ b/plugins.d/nodejs.sh @@ -82,6 +82,14 @@ echo -e "\n${underline}🌿 npm:${reset}" echo -e " - current version: ${italic}$npm_v${reset}" echo -e " - install path: ${italic}$npm_ins${reset}" + +curl -Is http://www.google.com | head -1 | grep 200 1>/dev/null +if [[ $? -eq 1 ]]; then + echo -e "\n${red}No Internet connection !${reset}" + echo -e "Exit !" + exit 1 +fi + # version installée de nvm par Homebrew # nvm_installed=$(brew info nvm | grep Cellar) diff --git a/plugins.d/pecl.sh b/plugins.d/pecl.sh index 57f9efa..df746b7 100755 --- a/plugins.d/pecl.sh +++ b/plugins.d/pecl.sh @@ -79,8 +79,8 @@ version=$(php --info | grep 'PHP Version' | sed -n '1p' | awk -F" " '{print $NF} v=${version:0:3} echo -e "${ita_under}${blue}Current PHP version:${reset} ${bold}$version${reset}\n" -latest="8.0" -versions=("7.2" "7.3" "7.4" "8.1" "$latest") +latest="8.2" +versions=("7.4" "8.0" "8.1" "8.3" "$latest") php_installed=$(ls -1 $(brew --prefix)/opt/ | grep php@) echo -e "${ita_under}${blue}Installed PHP versions:${reset}" echo -e "$php_installed\n" @@ -94,6 +94,12 @@ fi pecl version +curl -Is http://www.google.com | head -1 | grep 200 +if [[ $? -eq 1 ]]; then + echo -e "\n${red}No Internet connection !${reset}" + echo -e "Exit !" + exit 1 +fi # Note that all public channels can be synced using "update-channels" echo -e "\n${ita_under}${blue}Updating all channels...${reset}" diff --git a/plugins.d/perl.sh b/plugins.d/perl.sh index 719e1aa..870b031 100755 --- a/plugins.d/perl.sh +++ b/plugins.d/perl.sh @@ -16,6 +16,20 @@ display_info=true # Also add module for prevent to update it. declare -a do_not_update=('') +italic="\033[3m" +underline="\033[4m" +ita_under="\033[3;4m" +bgd="\033[1;4;31m" +red="\033[1;31m" +bold="\033[1m" +bold_ita="\033[1;3m" +box="\033[1;41m" +redbold="\033[1;31m" +redbox="\033[1;41m" +reset="\033[0m" + +echo -e "${bold}🐪 Perl ${reset}" +echo perl_app=$(which perl) perl_v=$(perl -v | sed -n '2p') @@ -42,10 +56,17 @@ else install_ok=true fi + +curl -Is http://www.google.com | head -1 | grep 200 1>/dev/null +if [[ $? -eq 1 ]]; then + echo -e "\n${red}No Internet connection !${reset}" + echo -e "Exit !" + exit 1 +fi + if [ "$install_ok" == "true" ]; then - echo "$module installed" - # install with cpan + # install with cpan # % cpan-outdated | xargs cpan -i # install with cpanm diff --git a/plugins.d/pip.sh b/plugins.d/pip.sh index 54314da..20a363f 100755 --- a/plugins.d/pip.sh +++ b/plugins.d/pip.sh @@ -78,6 +78,13 @@ if (( ${#do_not_update[@]} )); then fi +curl -Is http://www.google.com | head -1 | grep 200 1>/dev/null +if [[ $? -eq 1 ]]; then + echo -e "\n${red}No Internet connection !${reset}" + echo -e "Exit !" + exit 1 +fi + #Packages update echo -e "🐍 ${underline}Search for packages update...${reset}\n" diff --git a/plugins.d/pipx.sh b/plugins.d/pipx.sh index 3096980..a001ab3 100755 --- a/plugins.d/pipx.sh +++ b/plugins.d/pipx.sh @@ -40,6 +40,13 @@ list=$(pipx list --include-injected) echo -e "\n${underline}List installed packages:${reset}" echo "$list" +curl -Is http://www.google.com | head -1 | grep 200 1>/dev/null +if [[ $? -eq 1 ]]; then + echo -e "\n${red}No Internet connection !${reset}" + echo -e "Exit !" + exit 1 +fi + pipx-outdated() { echo -e "\n${underline}Outdated Packages:${reset}" while read -sr pyPkgName pyPkyVersion; do diff --git a/plugins.d/rustup.sh b/plugins.d/rustup.sh index af9ef56..b6bcb63 100755 --- a/plugins.d/rustup.sh +++ b/plugins.d/rustup.sh @@ -11,6 +11,13 @@ reset="\033[0m" echo -e "\n${bold}🦀 Rust${reset}\n" +curl -Is http://www.google.com | head -1 | grep 200 1>/dev/null +if [[ $? -eq 1 ]]; then + echo -e "\n${red}No Internet connection !${reset}" + echo -e "Exit !" + exit 1 +fi + if hash rustup 2>/dev/null; then echo -e "🦀 ${underline}rustup check${reset}\n" diff --git a/plugins.d/venv.sh b/plugins.d/venv.sh index e39abfc..1890637 100755 --- a/plugins.d/venv.sh +++ b/plugins.d/venv.sh @@ -40,8 +40,15 @@ elif [[ "$OSTYPE" == "linux_gnu" ]]; then elif [[ "$OSTYPE" == "linux_gnueabihf" ]]; then v=$HOME/venv fi -# -############################################################################################### + +curl -Is http://www.google.com | head -1 | grep 200 1>/dev/null +if [[ $? -eq 1 ]]; then + echo -e "\n${red}No Internet connection !${reset}" + echo -e "Exit !" + exit 1 +fi + +################################################################################################ for app in ${apps[*]} do