11-10-2021

This commit is contained in:
2021-10-11 06:32:21 +02:00
parent 61cdb0e44b
commit e8fc598082
6 changed files with 111 additions and 401 deletions

View File

@@ -1,357 +0,0 @@
#!/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 ""

View File

@@ -146,31 +146,42 @@ echo ""
# Local packages #
##################
# 1. Create package.json file with 'npm init'
# or copy packagejson in $local_path
# 2. Install node modules with 'npm install' in $local_path\node_modules
# Local folder exist and not empty (modules installed)
#if [ -d "$local_path/node_modules" ] && [ -n "$(ls -A "$local_path/node_modules")" ]; then
if find "$local_path/node_modules" -mindepth 1 -maxdepth 1 | read; then
echo -e "${underline}🌿 Local installed scripts:${reset}"
cd "$local_path" || return
if [ "$display_info" = true ]; then
ll=$(npm ls --long | grep -v 'git$')
x=
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}"
#echo -e "${bold}${line}${reset}"
info_pkg=$(npm view "$local_pkg" | sed -n '3,4p')
q=$(echo "$info_pkg" | sed "s/^/| /")
echo -e "$q"
#echo -e "$q"
x+="${bold}${line}${reset}\n"
x+="$q\n"
else
echo -e "${line}"
#echo -e "${line}"
x+="${line}\n"
fi
done <<< "$ll"
else
npm ls
fi
echo -e "$x"
echo -e "\n${underline}🌿 Search for local packages update...${reset}\n"
outdated=$(npm outdated --long | sed '1d')
@@ -226,19 +237,31 @@ echo -e "${underline}🌿 Global installed scripts:${reset}"
if [ "$display_info" = true ]; then
lg=$(npm list -g --depth=0 --long | grep -v 'git$')
x=""
q=""
while IFS= read -r line
do
if [[ "${line}" =~ "──" ]]; then
echo -e "${bold}${line}${reset}"
else
echo -e "${line}"
#echo -e "${bold}${line}${reset}"
global_pkg=$(echo "${line}" | awk '{print $2}' | awk -F"@" '{print $1}')
#echo -e "${bold}${line}${reset}"
info_pkg=$(npm view "$global_pkg" | sed -n '4p')
q=$(echo "$info_pkg" | sed "s/^/| /")
#echo "$q"
x+="${bold}${line}${reset}\n"
elif [[ ${#line} > 2 ]]; then
#echo -e "${line}"
x+="${line}\n"
x+="$q\n"
fi
done <<< "$lg"
else
npm list -g --depth=0
fi
echo -e "$x"
#Packages update
echo -e "\n${underline}🌿 Search for global packages update...${reset}\n"
@@ -295,7 +318,8 @@ echo ""
if [ "$doctor" = true ]; then
echo -e "${underline}🌿 The Doc is checking that everything is ok.${reset}\n"
#npm doctor
doc=$(npm doctor)
#doc=$(npm doctor)
doc=$(cd "$local_path" && npm doctor)
while IFS= read -r line
do

View File

@@ -24,6 +24,7 @@ underline="\033[4m"
ita_under="\033[3;4m"
bgd="\033[1;4;31m"
red="\033[1;31m"
blue="\033[34m"
bold="\033[1m"
box="\033[1;41m"
reset="\033[0m"
@@ -76,21 +77,27 @@ echo ""
version=$(php --info | grep 'PHP Version' | sed -n '1p' | awk -F" " '{print $NF}')
v=${version:0:3}
echo -e "Current PHP version: ${bold}$version${reset}\n"
echo -e "${ita_under}${blue}Current PHP version:${reset} ${bold}$version${reset}\n"
if [ "$v" = "7.3" ]; then
php_path=$(brew --prefix)/opt/php@7.3/bin
elif [ "$v" = "7.2" ]; then
php_path=$(brew --prefix)/opt/php@7.2/bin
elif [ "$v" = "7.4" ]; then
php_path=$(brew --prefix)/opt/php@7.4/bin
elif [ "$v" = "8.0" ]; then
latest="8.0"
versions=("7.2" "7.3" "7.4" "8.1" "$latest")
php_installed=$(ls -1 $(brew --prefix)/opt/ | grep php@)
echo -e "${ita_under}${blue}Installed PHP versions:${reset}"
echo -e "$php_installed\n"
if [ "$v" == "$latest" ] ; then
php_path=$(brew --prefix)/opt/php/bin
else
php_path=$(brew --prefix)/opt/php@$v/bin
fi
#echo "$php_path"
pecl version
# Note that all public channels can be synced using "update-channels"
echo -e "${underline}Updating all channels...${reset}"
$php_path/pecl update-channels
echo -e "\n${ita_under}${blue}Updating all channels...${reset}"
pecl update-channels
#pecl channel-update pecl.php.net
#pecl channel-update pear.php.net
@@ -99,7 +106,7 @@ $php_path/pecl update-channels
# List Installed Packages In The Default Channel
#pecl_list=$($php_path/pecl list)
# List installed packages from all channels
pecl_list=$($php_path/pecl list -a)
pecl_list=$(pecl list -a)
echo -e "\n$pecl_list\n"
# Installation imagick:
@@ -111,12 +118,12 @@ echo -e "\n$pecl_list\n"
#make install
pecl_upgrade=$($php_path/pecl list-upgrades)
pecl_upgrade=$(pecl list-upgrades)
if [ -n "$pecl_upgrade" ]; then
echo -e "${underline}Extensions update:${reset}"
echo -e "${ita_under}${blue}Extensions update:${reset}"
echo ""
echo "$pecl_upgrade"
@@ -135,7 +142,7 @@ if [ -n "$pecl_upgrade" ]; then
#echo "a: $a"
if [ -n "$a" ]; then
#pecl channel-update pear.php.net
$php_path/pecl channel-update pear.php.net
pecl channel-update pear.php.net
fi
# Channel pecl.php.net
@@ -143,20 +150,20 @@ if [ -n "$pecl_upgrade" ]; then
#echo "b: $b"
if [ -n "$b" ]; then
#pecl channel-update pecl.php.net
$php_path/pecl channel-update pecl.php.net
pecl channel-update pecl.php.net
#(pecl or doc) update available
b=$(echo "$ligne" | awk '{print $2}')
#pecl info "$b"
$php_path/pecl info "$b"
pecl info "$b"
echo ""
if [ "$no_distract" = false ]; then
#echo "$b" | xargs -p -n 1 pecl upgrade
echo "$b" | xargs -p -n 1 $php_path/pecl upgrade
echo "$b" | xargs -p -n 1 pecl upgrade
php_info=true
else
#echo "$b" | xargs -n 1 pecl upgrade
echo "$b" | xargs -n 1 $php_path/pecl upgrade
echo "$b" | xargs -n 1 pecl upgrade
php_info=true
fi
fi
@@ -166,7 +173,6 @@ if [ -n "$pecl_upgrade" ]; then
fi
fi
echo "php_info: $php_info"
# si modif des extensions, les .ini dans conf.d/ ne sont pas modifiés, juste le php.ini
@@ -180,13 +186,19 @@ name=$(basename "$conf_php")
notif2="$conf_php was modified in the last 5 minutes"
if [ "$display_info" = true ]; then
echo -e "${ita_under}${blue}PHP ini files:${reset}"
echo -e "php.ini path: ${bold}$conf_php${reset}"
echo -e "Additionnals ini files:\n$(ls $dir/conf.d/*.ini)"
echo -e "\nTo change php version: ${italic}$ sphp 7.4${reset}"
echo -e "${italic}https://gist.github.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2${reset}\n"
echo -e "\n${ita_under}${blue}To change php version:${reset} ${italic}$ sphp 7.4${reset}"
echo -e " ${italic}•mod-php: https://gist.github.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2${reset}"
echo -e " ${italic}•php-fpm: https://gist.github.com/rozsival/10289d1e2006c68009ace0478306ecd2${reset}\n"
host=$(hostname)
[ "$php_info" = true ] && echo -e "Opening PHP info in Safari..." && open "https://$host.local/info.php"
#[ "$php_info" = true ] && echo -e "Opening PHP info in Safari..." && open "https://$host.local/info.php"
if [ "$php_info" = true ]; then
#host=$(hostname)
echo -e "Some extensions have been updated. Let's opening PHP info in Safari..."
open "https://$(hostname).local/info.php"
fi
fi
test=$(find "$dir" -maxdepth 1 -name "$name" -mmin -5)

View File

@@ -89,7 +89,7 @@ if [ -n "$upd" ]; then
nb=$(echo "$upd" | wc -w | xargs)
echo -e "${redbox} $nb ${reset} ${underline}availables updates:${reset}"
echo -e "${redbox} $nb ${reset} availables updates:"
echo -e "\n$pip_outdated"
echo ""
@@ -180,7 +180,7 @@ if [ -n "$upd" ]; then
done
else
echo -e "${underline}No availables updates.${reset}"
echo -e "No availables updates."
fi

31
plugins.d/pipx.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# pip plugin for KYMSU
# https://github.com/welcoMattic/kymsu
list=$(pipx list --include-injected --json)
#echo "$list"
pipx-outdated() {
echo "OUTDATED PACKAGES:"
while read -sr pyPkgName pyPkyVersion; do
local pypi_latest="$(curl -sS https://pypi.org/simple/${pyPkgName}/ | grep -o '>.*</' | tail -n 1 | grep -o -E '[0-9]([0-9]|[-._])*[0-9]')"
[ "$pyPkyVersion" != "$pypi_latest" ] && printf "%s\n\tCurrent: %s\tLatest: %s\n" "$pyPkgName" "$pyPkyVersion" "$pypi_latest"
done < <( pipx list | grep -o 'package.*,' | tr -d ',' | cut -d ' ' -f 2- )
}
pipx-outdated
#echo "----------"
packages=$(echo "$list" | jq '{venvs} | .[]')
#echo "$packages"
for row in $(jq -c '.[] | .[]' <<< "$packages");
do
inj=$(echo "$row" | jq -j '.injected_packages')
echo "$inj"
#echo "$row"
done

View File

@@ -1,8 +1,17 @@
#!/usr/bin/env bash
# Perl plugin for KYMSU
# Venv plugin for KYMSU
# https://github.com/welcoMattic/kymsu
italic="\033[3m"
underline="\033[4m"
ita_under="\033[3;4m"
bgd="\033[1;4;31m"
red="\033[1;31m"
bold="\033[1m"
box="\033[1;41m"
reset="\033[0m"
###############################################################################################
#
# Settings:
@@ -34,15 +43,6 @@ fi
#
###############################################################################################
italic="\033[3m"
underline="\033[4m"
ita_under="\033[3;4m"
bgd="\033[1;4;31m"
red="\033[1;31m"
bold="\033[1m"
box="\033[1;41m"
reset="\033[0m"
for app in ${apps[*]}
do
echo -e "${bold}Update $app${reset}";