Update following original kymsu
This commit is contained in:
2019-08-10 09:03:04 +02:00
parent 754076dd3d
commit e29dbb808d
15 changed files with 210 additions and 64 deletions

6
plugins.d/00-kymsu.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
echo "🦄 KYMSU self update"
pushd "$(cat ~/.kymsu/path)" > /dev/null
git pull
popd > /dev/null
echo ""

272
plugins.d/_wp.sh Executable file
View File

@@ -0,0 +1,272 @@
#!/usr/bin/env bash
# wp-cli plugin for KYMSU
# https://github.com/welcoMattic/kymsu
# https://make.wordpress.org/cli/handbook/
test=false
# Répertoire WordPress
rep_wordpress=/Users/bruno/Sites/wordpress
# No distract mode
no_distract=false
# Maintenance
maint=true
# Nombre de révisions à conserver:
# Package trepmal/wp-revisions-cli requis !
revisions=3
# Effacer Pingback et Trackback
back=true
# Effacer les spams
removespam=true
# Effacer les révisions
rev=true
# Vider la corbeille
emptytrash=true
# Sauvegarde de la base
backup=true
# Maintenance de la base (optimize & repair)
database=false
# Effacer les transients expirés
transient=true
# Ouvrir la page d'aministration
admin=false
#add module to do_not_update array
declare -a do_not_update=()
if [[ $1 == "--nodistract" ]] || [[ $no_distract == true ]]; then
no_distract=true
prompt=
elif [[ $no_distract == false ]]; then
no_distract=false
prompt="-p"
fi
if ! [ -x "$(command -v wp)" ]; then
echo "Error: wp-cli https://wp-cli.org/fr/ is not installed." >&2
exit 1
fi
echo -e "\033[1mWP wp-cli \033[0m"
echo ""
cd $rep_wordpress
#echo $(pwd)
# *** plugins ***
if [ "$test" = true ]; then
# *** core update ***
echo "Search for core update..."
core_cu=$(wp core check-update)
if ! [[ $core_cu = *"latest version"* ]]; then
echo "New version available!"
z=$(echo -e "Do you wanna \033[1m upgrade WordPress\033[0m? (y/n)")
read -p "$z" choice
case "$choice" in
y|Y ) wp core update && wp core update-db ;;
n|N ) echo "Ok, let's continue";;
* ) echo "invalid";;
esac
else
echo "WordPress is up to date!"
fi
echo ""
# *** plugins ***
echo "Search for all plugins update..."
plugin_cu_all=$(wp plugin update --all --dry-run)
plugins_outdated=$(echo "$plugin_cu_all" | sed '1,2d' | awk '{print $1}')
if [ -z "$plugins_outdated" ]; then
echo "No plugins update available !"
else
for i in "$plugins_outdated"
do
echo "$i" | xargs $prompt -n 1 wp plugin update
done
fi
echo ""
# *** themes ***
echo "Search for all themes update..."
theme_cu_all=$(wp theme update --all --dry-run)
themes_outdated=$(echo "$theme_cu_all" | sed '1,2d' | awk '{print $1}')
if [ -z "$themes_outdated" ]; then
echo "No themes update available !"
else
for i in "$themes_outdated"
do
echo "$i" | xargs -p -n 1 wp theme update
done
fi
echo ""
# *** languages core ***
echo "Search for languages core update..."
list_lang_core_upd=$(wp language core list --update=available --all --format=csv)
lang_core_outdated=$(echo "$list_lang_core_upd" | sed '1d' | awk '{print $1}')
if [ -z "$lang_core_outdated" ]; then
echo "No languages core update available !"
else
for i in "$lang_core_outdated"
do
echo "$i" | xargs -p -n 1 wp language core update
done
fi
echo ""
# *** languages plugin ***
echo "Search for languages plugins update..."
list_lang_plugin_upd=$(wp language plugin list --update=available --all --format=csv)
lang_plugin_outdated=$(echo "$list_lang_plugin_upd" | sed '1d' | awk '{print $1}')
if [ -z "$lang_plugin_outdated" ]; then
echo "No languages plugins update available !"
else
for i in "$lang_plugin_outdated"
do
echo "$i" | xargs -p -n 1 wp language plugin update
done
fi
echo ""
# *** languages theme ***
echo "Search for languages themes update..."
list_lang_theme_upd=$(wp language theme list --update=available --all --format=csv)
lang_theme_outdated=$(echo "$list_lang_theme_upd" | sed '1d' | awk '{print $1}')
if [ -z "$lang_theme_outdated" ]; then
echo "No languages themes update available !"
else
for i in "$lang_theme_outdated"
do
echo "$i" | xargs -p -n 1 wp language theme update
done
fi
fi
echo ""
# *** Maintenance ***
if [ "$maint" = true ]; then
echo -e "\n"
echo -e "\n\033[1;31mMaintenance...\033[0m"
#On récupère la liste des packages installés
packages_list=$(wp package list | sed -n '1!p' | awk '{print $1'})
echo "$packages_list"
if [ "$transient" = true ]; then
echo -e "\n\033[1mRemove expired transients...\033[0m"
wp transient delete --expired --path=$path
fi
if [ "$database" = true ]; then
echo -e "\n\033[1mDatabase maintenance...\033[0m"
wp db optimize --quiet --path=$path
#wp db repair --quiet --path=$path
fi
if [ "$backup" = true ]; then
echo -e "\n\033[1mDatabase backup...\033[0m"
DATE=`date +%Y-%m-%d_%H:%M:%S`
file="wp-$blogname-$DATE.sql"
wp db export "$file" --add-drop-table --path=$path
mv "$file" "../$file"
fi
if [ "$removespam" = true ]; then
echo -e "\n\033[1mRemove spam comments...\033[0m"
#spam=$($wp_exec comment list --status=spam --format=ids --path=$path)
echo "$spam"
if [ -n "$spam" ]; then
echo "$spam"
#wp comment delete "$spam" --path=$path
wp comment delete $($wp_exec comment list --status=spam --format=ids --path=$path) --path=$path --dry-run
else
echo "No SPAM"
fi
fi
if [ "$emptytrash" = true ]; then
echo -e "\n\033[1mRemove comments in trash and comment from deleted posts...\033[0m"
trashed=$(wp comment list --status=trash,post-trashed --format=ids --path=$path)
if [ -n "$trashed" ]; then
wp comment delete "$trashed" --path=$path
echo $?
else
echo "No trashed post"
fi
fi
#if [[ "$($wp_exec cli has-command 'revisions' --path=$path && echo $?)" -eq 0 ]] && [[ "$rev" = true ]]; then
if [[ -n "$(echo "$packages_list" | awk '$1 ~ /trepmal\/wp-revisions-cli/')" ]] && [[ "$rev" = true ]]; then
echo -e "\n\033[1mKeep only $revisions revisions...\033[0m"
wp revisions clean $revisions --path=$path --dry-run
elif [ "$rev" = true ]; then
printf "Voulez-vous installer wp-revisions-cli ? (y/n)"
read choice
case "$choice" in
y|Y|o) wp package install trepmal/wp-revisions-cli || exit 1
;;
n|N) echo "Ok, on continue"
;;
*) echo "invalide"
;;
esac
fi
if [ "$back" = true ]; then
echo -e "\n\033[1mTrackback list...\033[0m"
trackback=$(wp comment list --type=trackback --format=ids --path=$path)
if [ -n "$trackback" ]; then
wp comment delete "$trackback" --path=$path --dry-run
else
echo "No trackback post"
fi
echo -e "\n\033[1mPingback list...\033[0m"
pingback=$(wp comment list --type=pingback --format=ids --path=$path)
if [ -n "$pingback" ]; then
wp comment delete "$pingback" --path=$path --dry-run
else
echo "No pingback post"
fi
fi
# Ouvrir le tableau de bord dans un navigateur:
# Nécéssite le paquet admin-command (sera installé si nécessaire)
if [[ -n "$(echo "$packages_list" | awk '$1 ~ /wp-cli\/admin-command/')" ]] && [[ "$admin" = true ]]; then
echo -e "\n\033[1mOpen wp-admin/ page in browser...\033[0m"
wp admin --path=$path
elif [ "$admin" = true ]; then
wp package install wp-cli/admin-command
echo ""
echo -e "\n\033[1mOpen wp-admin/ page in browser...\033[0m"
wp admin --path=$path
fi
fi

11
plugins.d/atom.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
echo -e "\033[1m⚛ Atom editor will be shiny when you'll be back from your coffee/tea break! \033[0m"
if hash apm-beta 2>/dev/null; then
apm-beta upgrade -c false
fi
if hash apm 2>/dev/null; then
apm upgrade -c false
fi
echo ""

173
plugins.d/homebrew.sh Executable file
View File

@@ -0,0 +1,173 @@
#!/usr/bin/env bash
# Homebrew plugin for KYMSU
# https://github.com/welcoMattic/kymsu
# Error: Cask 'onyx' definition is invalid: invalid 'depends_on macos' value: :snow_leopard
# Supprimer manuellement onyx de /Applications
# rm -rvf "$(brew --prefix)/Caskroom/onyx"
# ou
# /usr/bin/find "$(brew --prefix)/Caskroom/"*'/.metadata' -type f -name '*.rb' -print0 | /usr/bin/xargs -0 /usr/bin/perl -i -0pe 's/depends_on macos: \[.*?\]//gsm;s/depends_on macos: .*//g'
# Display info on updated pakages
display_info=true
#add module to do_not_update array
declare -a do_not_update=('virtualbox,virtualbox-extension-pack')
# No distract mode (no user interaction)(Casks with 'latest' version number won't be updated)
no_distract=false
if [[ $1 == "--nodistract" ]]; then
no_distract=true
fi
echo -e "\033[1m🍺 Homebrew \033[0m"
brew update
echo ""
brew_outdated=$(brew outdated)
upd3=$(echo "$brew_outdated" | awk '{print $1}')
#nb=$(echo $upd3 | wc -w)
if [ -n "$upd3" ]; then
if [ "$display_info" = true ]; then
echo -e "\033[4mInfo on updated packages:\033[0m"
for pkg in $upd3
do
# if jq (https://stedolan.github.io/jq/) is installed
if [ -x "$(command -v jq)" ]; then
info_pkg=$(brew info --json=v1 "$pkg")
current=$(echo "$info_pkg" | jq -r .[].installed[].version | tail -n 1 | awk '{print $1}')
stable=$(echo "$info_pkg" | jq -r .[].versions.stable)
homepage=$(echo "$info_pkg" | jq -r .[].homepage)
desc=$(echo "$info_pkg" | jq -r .[].desc)
echo -e "\033[1m$pkg:\033[0m current: $current last: $stable"
echo "$desc"
echo "$homepage"
else
info=$(brew info $pkg | head -n 4)
ligne1=$(echo "$info" | head -n 1)
echo -e "\033[1m$ligne1\033[0m"
echo "$info" | sed -n -e '2,3p'
fi
echo ""
done
fi
if [ "$no_distract" = false ]; then
a=$(echo -e "Do you wanna run \033[1mbrew upgrade "$upd3"\033[0m? (y/n)")
read -p "$a" choice
#case "$choice" in
# y|Y ) echo "$brew_outdated" | awk '{print $1}' | xargs -p -n 1 brew upgrade ;;
# n|N ) echo "Ok, let's continue";;
# * ) echo "invalid";;
#esac
if [ "$choice" == "y" ]; then
for i in $upd3
do
FOUND=`echo ${do_not_update[*]} | grep "$i"`
if [ "${FOUND}" = "" ]; then
echo "$i" | awk '{print $1}' | xargs -p -n 1 brew upgrade
fi
done
else
echo "Ok, let's continue"
fi
else
echo "$brew_outdated" | awk '{print $1}' | xargs -n 1 brew upgrade
fi
echo ""
fi
echo "🍺 Casks upgrade."
cask_outdated=$(brew cask outdated --greedy --verbose)
outdated=$(echo "$cask_outdated" | grep -v '(latest)')
if [ -n "$outdated" ]; then
# don't stop multiples updates if one block (bad checksum, not compatible with OS version (Onyx))
sea=$(echo "$outdated" | awk '{print $1}')
for i in $sea
do
FOUND=`echo ${do_not_update[*]} | grep "$i"`
if [ "${FOUND}" == "" ]; then
echo "$i" | xargs brew cask reinstall
fi
done
else
echo -e "\033[4mNo availables Cask updates.\033[0m"
fi
echo ""
latest=$(echo "$cask_outdated" | grep '(latest)')
if [ -n "$latest" ] && [ "$no_distract" = false ]; then
echo -e "\033[4mCasks (latest):\033[0m"
echo "$latest" | cut -d " " -f1,2
echo ""
read -p "Do you wanna run Cask (latest) upgrade? (y/n)" choice
if [ "$choice" == "y" ]; then
for i in "$latest"
do
echo "$i" | awk '{print $1}' | xargs -p -n 1 brew cask upgrade --greedy
echo $?
done
else
echo "Ok, let's continue"
fi
fi
echo ""
echo "🍺 The Doc is checking that everything is ok."
brew doctor
brew missing
echo ""
# Test if Apache conf file has been modified by Homebrew (Apache, PHP or Python updates)
v_apa=$(httpd -V | grep 'SERVER_CONFIG_FILE')
conf_apa=$(echo "$v_apa" | awk -F "\"" '{print $2}')
dir=$(dirname $conf_apa)
name=$(basename $conf_apa)
test=$(find $dir -name "$name" -mmin -5 -maxdepth 1)
[ ! -z $test ] && echo -e "\033[1;31m❗ $name was modified in the last 5 minutes\033[0m"
# Homebrew 2.0.0+ run a cleanup every 30 days
if [[ $1 == "--cleanup" ]]; then
echo "🍺 Cleaning brewery"
##brew cleanup -s
# keep 30 days
brew cleanup --prune=30
##brew cask cleanup: deprecated - merged with brew cleanup
#brew cask cleanup --outdated
echo ""
fi
echo ""

50
plugins.d/mas.sh Executable file
View File

@@ -0,0 +1,50 @@
#!/usr/bin/env bash
# Mac Appstore plugin for KYMSU
# https://github.com/welcoMattic/kymsu
echo -e "\033[1m🍏 Mac App Store updates come fast as lightning \033[0m"
# No distract mode (no user interaction)
no_distract=false
if [[ $1 == "--nodistract" ]]; then
no_distract=true
fi
# On teste si mas est installé
if hash mas 2>/dev/null; then
massy=$(mas outdated)
echo ""
echo "$massy"
#if [ -n "$massy" ]; then
if [ ! -z "$(mas outdated)" ]; then
echo -e "\033[4mAvailables updates:\033[0m"
echo "$massy" | cut -d " " -f2-5
echo ""
if [ "$no_distract" = false ]; then
a=$(echo -e "Do you wanna run \033[1mmas upgrade\033[0m ? (y/n)")
read -p "$a" choice
case "$choice" in
y|Y|o ) mas upgrade;;
n|N ) echo "Ok, let's continue";;
* ) echo "invalid";;
esac
else
mas upgrade
fi
else
echo -e "\033[4mNo availables mas updates.\033[0m"
fi
else
echo "Please install mas: brew install mas"
fi
echo ""
echo ""

137
plugins.d/npm.sh Executable file
View File

@@ -0,0 +1,137 @@
#!/usr/bin/env bash
# npm plugin for KYMSU (install local package)
# https://github.com/welcoMattic/kymsu
# Fixing npm On Mac OS X for Homebrew Users
# https://gist.github.com/rcugut/c7abd2a425bb65da3c61d8341cd4b02d
# https://gist.github.com/DanHerbert/9520689
# brew install node
# node -v => 9.11.1
# npm -v => 5.6.0
# npm install -g npm
# npm -v => 5.8.0
# https://github.com/npm/npm/issues/17744
# No distract mode
no_distract=false
doctor=false
# Local install
local_path=$HOME/Sites/node_modules/
echo -e "\033[1m🌿 npm \033[0m"
echo ""
# version courante de node.js
node_v=$(node -v)
echo -e "\033[4m🌿 node.js\033[0m (current version): $node_v"
# version courante de npm
npm_v=$(npm -v)
echo -e "\033[4m🌿 npm\033[0m (current version): $npm_v"
# versions installées de node.js
nvm_installed=$(brew info nvm | grep Cellar)
if [ -f "$NVM_DIR/nvm.sh" ]; then
source $NVM_DIR/nvm.sh
# version courante de nvm
nvm_v=$(nvm --version)
echo -e "\033[4m🌿 nvm install is:\033[0m $NVM_DIR/nvm.sh"
echo "nvm $nvm_v is installed from https://github.com/nvm-sh/nvm"
node_install=$(nvm list)
echo -e "\033[4m🌿 node.js\033[0m (installed versions): \n$node_install"
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 "\033[4m🌿 nvm install is:\033[0m /usr/local/opt/nvm/nvm.sh"
echo "nvm $nvm_v is installed from homebrew"
node_install=$(nvm list)
echo -e "\033[4m🌿 node.js\033[0m (installed versions): \n$node_install"
fi
echo
# Local packages
if [ -d "$local_path" ]; then
cd $local_path
echo -e "\033[4m🌿 Local installed scripts:\033[0m"
npm ls
outdated=$(npm outdated)
if [ -n "$outdated" ]; then
echo "$outdated"
echo "$outdated" | awk '{print $1}' | xargs npm update
else
echo -e "\033[4mNo local packages updates.\033[0m"
fi
fi
echo ""
# Global packages
echo -e "\033[4m🌿 Global installed scripts:\033[0m"
npm list -g --depth=0
g_outdated=$(npm outdated -g)
# => npm ERR! Cannot read property 'length' of undefined -> https://stackoverflow.com/questions/55172700/npm-outdated-g-error-cannot-read-property-length-of-undefined
# /Users/bruno/.nvm/versions/node/v10.16.2/lib/node_modules/npm/lib/outdated.js
# /usr/local/lib/node_modules/npm/lib/outdated.js
# update -> wanted ; install -> latest
if [ -n "$g_outdated" ]; then
if [ "$no_distract" = false ]; then
echo "$g_outdated"
#echo "$g_outdated" | sed '1d' | awk '{print $1}' | xargs -p -n 1 npm install -g
echo "$g_outdated" | sed '1d' | awk '{print $1}' | xargs -p -n 1 npm update -g
else
#echo "$g_outdated" | sed '1d' | awk '{print $1}' | xargs -n 1 npm install -g
echo "$g_outdated" | sed '1d' | awk '{print $1}' | xargs -n 1 npm update -g
fi
else
echo -e "\033[4mNo global packages updates.\033[0m"
fi
echo ""
# Maintenance
if [ "$doctor" = true ]; then
echo "🌿 The Doc is checking that everything is ok."
npm doctor
echo ""
echo "🔍 Verifying npm cache"
npm cache verify
echo ""
fi
if [[ $1 == "--npm_cleanup" ]]; then
# As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid.
# If you want to make sure everything is consistent, use 'npm cache verify' instead.
# On the other hand, if you're debugging an issue with the installer, you can use `npm install --cache /tmp/empty-cache` to use a temporary cache instead of nuking the actual one.
# If you're sure you want to delete the entire cache, rerun this command with --force.
if printf '%s\n%s\n' "$(npm --version)" 5.0.0 | sort --version-sort --check=silent; then
echo "🌿 Cleaning npm cache"
npm cache clean
fi
echo ""
fi
echo ""

65
plugins.d/pecl.sh Executable file
View File

@@ -0,0 +1,65 @@
#!/usr/bin/env bash
# pecl plugin for KYMSU
# https://github.com/welcoMattic/kymsu
# https://pecl.php.net
# No distract mode (no user interaction)
no_distract=false
echo -e "\033[1m🐘 pecl \033[0m"
echo ""
echo -e "\033[1m❗ plugin en test (beta) \033[0m"
echo ""
pecl_upgrade=$(pecl list-upgrades)
if [ -n "$pecl_upgrade" ]; then
echo -e "\033[4mExtensions update:\033[0m"
echo ""
echo "$pecl_upgrade"
echo ""
available=$(echo "$pecl_upgrade" | grep -v 'No upgrades available' | grep 'kB')
if [ -n "$available" ]; then
while read ligne
do
#echo "$ligne"
a=$(echo "$ligne" | grep "pear")
if [ -n "$a" ]; then
pecl channel-update pear.php.net
else
#(pecl or doc) update available
b=$(echo "$ligne" | awk '{print $2}')
pecl info "$b"
echo ""
if [ "$no_distract" = false ]; then
echo "$b" | xargs -p -n 1 pecl upgrade
else
echo "$b" | xargs -n 1 pecl upgrade
fi
fi
done <<< "$available"
fi
fi
# php.ini a été modifié il y a moins de 5mn
v_php=$(php --info | grep -E 'usr.*ini')
conf_php=$(echo "$v_php" | grep 'Loaded Configuration File' | awk '{print $NF}')
dir=$(dirname $conf_php)
name=$(basename $conf_php)
test=$(find $dir -name "$name" -mmin -5 -maxdepth 1)
[ ! -z $test ] && echo -e "\033[1;31m❗ $name was modified in the last 5 minutes\033[0m"
echo ""
echo ""
# WARNING: channel "pear.php.net" has updated its protocols,
# use "pecl channel-update pear.php.net" to update

112
plugins.d/pip.sh Executable file
View File

@@ -0,0 +1,112 @@
#!/usr/bin/env bash
# pip plugin for KYMSU
# https://github.com/welcoMattic/kymsu
#version: pip ou pip3
version=pip3
#user: "" or "--user"
user=""
# No distract mode
no_distract=false
#add module to do_not_update array
declare -a do_not_update=()
if [[ $1 == "--nodistract" ]]; then
no_distract=true
fi
if ! [ -x "$(command -v $version)" ]; then
echo "Error: $version is not installed." >&2
exit 1
fi
echo -e "\033[1m🐍 $version (Python 3) \033[0m"
echo ""
$version install --upgrade pip
echo ""
pip_outdated=$($version list --outdated --format columns)
upd=$(echo "$pip_outdated" | sed '1,2d' | awk '{print $1}')
if [ -n "$upd" ]; then
echo -e "\033[4mAvailables updates:\033[0m"
#echo $pip3_outdated_freeze | tr [:space:] '\n'
echo "$pip_outdated"
echo ""
for i in $upd
do
info=$($version show $i)
#info=$($version show $i | sed -n 4q)
#info=$($version show $i | head -5)
#info=$($version show $i | tail -n +5)
echo "$info" | head -4
echo ''
#echo "$i"
done
if [ -x "$(command -v pipdeptree)" ]; then
echo -e "\033[4mCheck dependancies:\033[0m"
echo "Be carefull!! This updates can be a dependancie for some modules. Check for any incompatible version."
fi
echo ""
for i in $upd
do
if [ -x "$(command -v pipdeptree)" ]; then
dependencies=$(echo "$i" | xargs pipdeptree -r -p | grep "$upd")
z=0
while read -r line; do
if [[ $line = *"<"* ]]; then
echo -e "\033[31m$line\033[0m"
else
if [ "$z" -eq 0 ]; then
echo -e "\033[3m$line\033[0m"
else
echo "$line"
fi
z=$((z+1))
fi
done <<< "$dependencies"
else
c=$(echo -e "Do you want to install pipdeptree to check dependancies ? (y/n)")
read -p "$c" choice
case "$choice" in
y|Y|o ) $version install $user pipdeptree ;;
n|N ) echo "Ok, let's continue";;
* ) echo "invalid";;
esac
fi
# If the update is not in the do_not_update array, we install it.
FOUND=`echo ${do_not_update[*]} | grep "$i"`
if [ "${FOUND}" = "" ] && [ "$no_distract" = false ]; then
b=$(echo -e "Do you wanna run \033[1m$version install $user --upgrade "$i"\033[0m ? (y/n)")
read -p "$b" choice
case "$choice" in
y|Y|o ) echo $i | xargs $version install $user --upgrade ;;
n|N ) echo "Ok, let's continue";;
* ) echo "invalid";;
esac
echo ""
elif [ "${FOUND}" = "" ]; then
echo $i | xargs $version install $user --upgrade
fi
done
else
echo -e "\033[4mNo availables updates.\033[0m"
fi
echo ""
echo ""