From c2e950d8195e16237db47a5b8aba8c99752ceaec Mon Sep 17 00:00:00 2001 From: Bruno21 Date: Wed, 28 Jul 2021 14:30:23 +0200 Subject: [PATCH] 28-07-2021 --- install.sh | 4 +- plugins.d/homebrew.sh | 5 +- plugins.d/mas.sh | 3 + plugins.d/{node.sh => node.sh.bak} | 1 + plugins.d/nodejs.sh | 357 +++++++++++++++++++++++++++++ plugins.d/pip.sh | 2 +- 6 files changed, 368 insertions(+), 4 deletions(-) rename plugins.d/{node.sh => node.sh.bak} (99%) create mode 100755 plugins.d/nodejs.sh diff --git a/install.sh b/install.sh index ce155f7..308ef31 100755 --- a/install.sh +++ b/install.sh @@ -9,7 +9,7 @@ KYMSU_PATH=`pwd` # Make Kymsu accessible in PATH echo -e "\nInstalling ${bold}kymsu2${reset} in ${bold}/usr/local/bin${reset} ..." -ln -fs "${KYMSU_PATH}"/kymsu2.sh /usr/local/bin/kymsu2 +sudo ln -fs "${KYMSU_PATH}"/kymsu2.sh /usr/local/bin/kymsu2 # Store Kymsu stuff in home directory mkdir -p $HOME/.kymsu && echo "${KYMSU_PATH}" > $HOME/.kymsu/path @@ -67,4 +67,4 @@ if [ "$new_install" = true ]; then done fi -fi \ No newline at end of file +fi diff --git a/plugins.d/homebrew.sh b/plugins.d/homebrew.sh index 27e4537..97346ba 100755 --- a/plugins.d/homebrew.sh +++ b/plugins.d/homebrew.sh @@ -458,7 +458,10 @@ echo "$test" # Test if PHP.ini file has been modified by Homebrew (PECL) -php_versions=$(ls /usr/local/etc/php/) +# Fichier php.ini courant +# php -i | grep 'Loaded Configuration File' | awk '{print $NF}' + +php_versions=$(ls /usr/local/etc/php/ 2>/dev/null) for php in $php_versions do if [ -n "$upd_pkg" ]; then diff --git a/plugins.d/mas.sh b/plugins.d/mas.sh index a7a11ae..b149b10 100755 --- a/plugins.d/mas.sh +++ b/plugins.d/mas.sh @@ -25,9 +25,12 @@ echo -e "${bold}๐Ÿ Mac App Store updates come fast as lightning ${reset}" echo "" echo -e "mas : https://github.com/mas-cli/mas" +command -v mas >/dev/null 2>&1 || { echo -e "\n${bold}mas${reset} is not installed.\n\nRun ${italic}'brew install mas'${reset} for install." && exit 1; } + latest_v=$(curl -s https://api.github.com/repos/mas-cli/mas/releases/latest | jq -j '.tag_name') current_v=$(mas version) + echo -e "Current version: $current_v" echo -e "Latest version: $latest_v" diff --git a/plugins.d/node.sh b/plugins.d/node.sh.bak similarity index 99% rename from plugins.d/node.sh rename to plugins.d/node.sh.bak index 5915df8..89b1ec9 100755 --- a/plugins.d/node.sh +++ b/plugins.d/node.sh.bak @@ -2,6 +2,7 @@ # npm plugin for KYMSU (install local package) # https://github.com/welcoMattic/kymsu +# ######################################### # diff --git a/plugins.d/nodejs.sh b/plugins.d/nodejs.sh new file mode 100755 index 0000000..89b1ec9 --- /dev/null +++ b/plugins.d/nodejs.sh @@ -0,0 +1,357 @@ +#!/usr/bin/env bash + +# npm plugin for KYMSU (install local package) +# https://github.com/welcoMattic/kymsu +# + +######################################### +# +# Settings: + +# Display info on updated pakages / casks +display_info=true + +# No distract mode (no user interaction) + +[[ $@ =~ "--nodistract" ]] && no_distract=true || no_distract=false + +# Set ls_color to '' for output nvm list in default colors, else '--no-colors' +# ls_color='--no-colors' +# ls_color='BrGcm' for custom colors +# export NVM_COLORS='BrGcm' in .zshrc for persistant custom colors + +# Set doctor=true to run 'npm doctor' and 'npm cache verify' each time +doctor=true + +# Set update_node to true to update node. +update_node=false + +# Local install: +# run 'npm init' in local_path to create package.json +local_path=$HOME/Sites/ + +######################################### + +: <<'END_COMMENT' +blabla +END_COMMENT + +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" +reset="\033[0m" + +upd_nvm() {( + cd "$NVM_DIR" + git fetch --tags origin + git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)` +) && \. "$NVM_DIR/nvm.sh" +} + +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm +[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion + + +echo -e "${bold}๐ŸŒฟ npm ${reset}" +echo "" + +# version courante de node.js +node_v=$(node -v) +node_ins=$(which node) +echo -e "${underline}๐ŸŒฟ node.js:${reset}" +echo -e " - current version: ${italic}$node_v${reset}" +echo -e " - install path: ${italic}$node_ins${reset}" + +# version courante de npm +npm_v=$(npm -v) +npm_ins=$(which npm) +echo -e "\n${underline}๐ŸŒฟ npm:${reset}" +echo -e " - current version: ${italic}$npm_v${reset}" +echo -e " - install path: ${italic}$npm_ins${reset}" + +# version installรฉe de nvm par Homebrew +# nvm_installed=$(brew info nvm | grep Cellar) + +# version actuelle de nvm sur GitHub +version_nvm=$(git ls-remote --tags --refs --sort="v:refname" git://github.com/nvm-sh/nvm.git | tail -n1 | sed 's/.*\///' | sed 's/v//') + +# nvm from github +if [ -f "$NVM_DIR/nvm.sh" ]; then + source $NVM_DIR/nvm.sh + + # version courante de nvm + nvm_v=$(nvm --version) + + echo -e "\n${underline}๐ŸŒฟ nvm install is:${reset} $NVM_DIR/nvm.sh" + echo " - nvm $nvm_v is installed from https://github.com/nvm-sh/nvm" + + if [ -n "$version_nvm" ]; then + if [ "$nvm_v" != "$version_nvm" ]; then + echo "Current nvm version on GitHub: $version_nvm" + echo "Current nvm installed version: $nvm_v" + + read -p "Do you want to update nvm from GitHub repo? (y/n)" choice + + if [ "$choice" == "y" ]; then + echo "Updating nvm from GitHub..." + #curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v"$version_nvm"/install.sh | bash + + upd_nvm + #curl: native on Catalina, wget installed by homebrew + #wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash + #curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash + fi + fi + fi + + node_install=$(nvm list "$ls_color") + echo -e "\n${underline}๐ŸŒฟ node.js${reset} (installed versions): \n$node_install" + +# nvm from homebrew +elif [ -f "/usr/local/opt/nvm/nvm.sh" ]; then + source $(brew --prefix nvm)/nvm.sh + + # version courante de nvm + nvm_v=$(nvm --version) + + echo -e "\n${underline}๐ŸŒฟ nvm install is:${reset} /usr/local/opt/nvm/nvm.sh" + echo "nvm $nvm_v is installed from homebrew" + + if [ "$nvm_v" != "$version_nvm" ]; then + echo "Current nvm version on GitHub: $version_nvm" + echo "Current nvm installed version: $nvm_v" + + echo -e "nvm is outdated ! You should run \033[1;3mbrew update && brew upgrade nvm\033[0m" + echo -e "or run \033[1;3mKymsu's homebrew.sh script.${reset}" + fi + + node_install=$(nvm list "$ls_color") + echo -e "\n${underline}๐ŸŒฟ node.js${reset} (installed versions): \n$node_install" + +fi + +echo -e "${italic}Note:" +echo -e "N/A: version \"10.18.0 -> N/A\" is not yet installed." +echo -e "You need to run \"nvm install 10.18.0\" to install it before using it.${reset}" + +echo "" + +################## +# Local packages # +################## + +if [ -d "$local_path" ]; then + cd "$local_path" || return + echo -e "${underline}๐ŸŒฟ Local installed scripts:${reset}" + + if [ "$display_info" = true ]; then + ll=$(npm ls --long | grep -v 'git$') + + while IFS= read -r line + do + if [[ "${line}" =~ "โ”€โ”€" ]] || [[ "${line}" =~ "โ”€โ”ฌ" ]]; then + local_pkg=$(echo "${line}" | awk '{print $2}' | awk -F"@" '{print $1}') + echo -e "${bold}${line}${reset}" + info_pkg=$(npm view "$local_pkg" | sed -n '3,4p') + q=$(echo "$info_pkg" | sed "s/^/| /") + echo -e "$q" + else + echo -e "${line}" + fi + done <<< "$ll" + else + npm ls + fi + + + echo -e "\n${underline}๐ŸŒฟ Search for local packages update...${reset}\n" + outdated=$(npm outdated --long | sed '1d') + if [ -n "$outdated" ]; then + nb_update=$(echo "outdated" | wc -l | xargs) + a="available package update" + array=($a) + [ "$nb_update" -gt 1 ] && echo -e "${box} $nb_update ${reset} ${array[@]/%/s}:\n" || echo -e "${box} $nb_update ${reset} ${array[@]}:\n" + + echo -e "\n${underline}๐ŸŒฟ Updating local packages...${reset}\n" + + while IFS= read -r i + do + package=$(echo "$i" | awk '{print $1}') + current=$(echo "$i" | awk '{print $2}') + wanted=$(echo "$i" | awk '{print $3}') + latest=$(echo "$i" | awk '{print $4}') + + j=$(echo "$current" | awk -F "." '{print $1}') + k=$(echo "$latest" | awk -F "." '{print $1}') + + # Update major version 1.x.y to 2.x.y + if [ $current = $wanted ] && [ "$j" -lt "$k" ]; then + if [ "$no_distract" = false ]; then + echo "$package@latest" | xargs -p npm install + else + echo "$package@latest" | xargs npm install + #npm install "$package@latest" + fi + # Update minor or patch version + else + if [ "$no_distract" = false ]; then + echo "$package" | xargs -p npm update + else + echo "$package" | xargs npm update + fi + fi + + done <<< "$outdated" + + else + echo -e "${italic}No local packages updates.${reset}" + fi +fi + +echo "" + +################### +# Global packages # +################### + +echo -e "${underline}๐ŸŒฟ Global installed scripts:${reset}" + +if [ "$display_info" = true ]; then + lg=$(npm list -g --depth=0 --long | grep -v 'git$') + + while IFS= read -r line + do + if [[ "${line}" =~ "โ”€โ”€" ]]; then + echo -e "${bold}${line}${reset}" + else + echo -e "${line}" + fi + done <<< "$lg" +else + npm list -g --depth=0 +fi + + +#Packages update +echo -e "\n${underline}๐ŸŒฟ Search for global packages update...${reset}\n" + +glong_outdated=$(npm outdated -g --long | sed '1d') + +if [ -n "$glong_outdated" ]; then + nb_update_global=$(echo "$glong_outdated" | wc -l | xargs) + a="available package update" + array=($a) + [ "$nb_update_global" -gt 1 ] && echo -e "${box} $nb_update_global ${reset} ${array[@]/%/s}:\n" || echo -e "${box} $nb_update_global ${reset} ${array[@]}:\n" + + echo -e "$glong_outdated\n" + echo -e "\n${underline}๐ŸŒฟ Updating global packages...${reset}\n" + + # Disable: Would you like to share anonymous usage data with the Angular Team at Google ? + if [[ " $glong_outdated " =~ "angular" ]]; then + export NG_CLI_ANALYTICS="false" + fi + # 15 packages are looking for funding + + + while IFS= read -r line + do + pkg=$(echo "$line" | awk '{print $1}') + vers=$(echo "$line" | awk '{print $4}') + outdated="$pkg@$vers" + + # TEST + #version=$(echo "$line" | awk '{print $1 "@" $4}') + #echo "$version" + # /test + + if [ "$no_distract" = false ]; then + echo "$outdated" | xargs -p -n 1 npm -g install + echo "" + else + echo "$outdated" | xargs -n 1 npm -g install + echo "" + fi + + done <<< "$glong_outdated" + +else + echo -e "${italic}No global packages updates.${reset}" +fi + +echo "" + +############### +# Maintenance # +############### + +if [ "$doctor" = true ]; then + echo -e "${underline}๐ŸŒฟ The Doc is checking that everything is ok.${reset}\n" + #npm doctor + doc=$(npm doctor) + + while IFS= read -r line + do + if [[ "${line}" =~ "not ok" ]]; then + echo -e "${red}${line}${reset}" + else + echo -e "${line}" + fi + done <<< "$doc" + + #echo -e "$doc\n" + + # search not ok => red + + npm_v=$(echo "$doc" | grep 'npm -v') + node_v=$(echo "$doc" | grep 'node -v') + + if [[ " $node_v " =~ " not ok " ]]; then + no=$(grep -o -E "v([0-9]{1,2}\.){2}[0-9]{1,2}" <<< "$node_v") + new_node=$(echo "${no:1}" | sed -n '1p') + old_node=$(echo "${no:1}" | sed -n '$p') + + #if [ "$new_node" != "$old_node" ]; then + if [ "$new_node" != "$old_node" ] && [ "$update_node" = true ]; then + #if [ "$update_node" = true ]; then + + b=$(echo -e "\nCurrent node: $old_node. Update ${bold}node${reset} to ${bold}$new_node${reset} [y/n] ? ") + read -e -p "$b" rep2 + if [ "$rep2" == "y" ] || [ "$rep2" == "Y" ]; then + . $HOME/.nvm/nvm.sh + echo -e "\n${bold}Updating node to v$new_node...${reset}" + nvm install $new_node + echo -e "\n${bold}Updating npm...${reset}" + npm -g install npm + # + nvm use $new_node + echo -e "\n${bold}Reinstall packages from $old_node...${reset}" + nvm reinstall-packages $old_node + fi + fi + fi + + if [[ " $npm_v " =~ " not ok " ]]; then + np=$(grep -o -E "v([0-9]{1,2}\.){2}[0-9]{1,2}" <<< "$npm_v") + new_npm=$(echo "${np:1}" | sed -n '1p') + old_npm=$(echo "${np:1}" | sed -n '$p') + + if [ "$new_npm" != "$old_npm" ]; then + echo -e "${underline}Udpate available for npm.${reset} You should run:" + echo -e " - ${bold}nnpm -g install npm${reset}" + fi + fi + + echo "" + + echo -e "๐Ÿ” Verifying npm cache\n" + npm cache verify + echo "" +fi + +echo "" diff --git a/plugins.d/pip.sh b/plugins.d/pip.sh index 3b2b2c9..c70b35b 100755 --- a/plugins.d/pip.sh +++ b/plugins.d/pip.sh @@ -33,7 +33,7 @@ user="" # Add module to the do_not_update array for prevent to update. #declare -a do_not_update=() #declare -a do_not_update=("parso" "asgiref") -declare -a do_not_update=("idna" "starlette") +declare -a do_not_update=() # #########################################