From 4b7c1404ab10d92441416b64dc72c80b4b2ce4c1 Mon Sep 17 00:00:00 2001 From: Bruno 21 Date: Sat, 25 Aug 2018 19:05:06 +0200 Subject: [PATCH] 3 scripts wp-cli pour OVH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * _wp_ovh.sh: le script principal de m-à-j (à copier sir OVH) * wp-cli_ovh.sh: script pour lancer _wp_ovh.sh * update_wp-cli_ovh.sh: met à jour wp-cli sur OVH --- wp-cli/_wp_ovh.sh | 281 ++++++++++++++++++++++++++++++++++++ wp-cli/update_wp-cli_ovh.sh | 6 + wp-cli/wp-cli_ovh.sh | 16 ++ 3 files changed, 303 insertions(+) create mode 100644 wp-cli/_wp_ovh.sh create mode 100755 wp-cli/update_wp-cli_ovh.sh create mode 100755 wp-cli/wp-cli_ovh.sh diff --git a/wp-cli/_wp_ovh.sh b/wp-cli/_wp_ovh.sh new file mode 100644 index 0000000..5269d6c --- /dev/null +++ b/wp-cli/_wp_ovh.sh @@ -0,0 +1,281 @@ +#!/usr/bin/env bash + +# NOTE: This requires GNU getopt. +# On Mac OS X : brew install gnu-getopt + +vers=$(getopt -V | grep 'util-linux') +if [ -n "$vers" ]; then + TEMP=`getopt -o p:hmr: --long path:,help,maint,root: -- "$@"` +else + TEMP=`/usr/local/opt/gnu-getopt/bin/getopt -o p:hmr: --long path:,help,maint,root: -- "$@"` +fi + +#TEMP=`getopt -o p:dm: --long path:,debug,memory:,debugfile: -- "$@"` + +if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi + +# Note the quotes around `$TEMP': they are essential! +eval set -- "$TEMP" + + +# nom du répertoire d'installation +path=wordpress +# chemin où est installé WordPress (wordpress_path) +document_root="/Users/bruno/Sites/" + +wp_exec="/usr/local/php7.2/bin/php /home/funnymac/opt/bin/wp" + +# 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 + + +help() { + echo -e "\033[93mupdate_wp.sh\033[0m" + echo + echo "Mise à jour et maintenance de WordPress" + echo + echo "Requiert:" + echo " - wp-cli (https://wp-cli.org/)" + echo + echo "Configuration:" + echo -e " - \033[4m\$path\033[0m est le nom du répertoire d'installation (wordpress par défaut)." + echo -e " - \033[4m\$wordpress_path\033[0m est le chemin où est installé WordPress." + echo -e " - \033[4m\$maint\033[0m : mettre sur \033[4mfalse\033[0m pour ne pas exécuter les opérations de maintenance (idem pour toutes les autres options)." + echo + echo "USAGE: update_wp" + echo + echo " --help display this help" + echo " --path chemin où est installé WordPress" + echo " --maint exécuter les opérations de maintenance" + echo + exit 0 +} + +while true; do + case "$1" in + -p | --path ) path="$2"; shift 2 ;; + -h | --help ) help; shift ;; + -m | --maint ) maint=true; shift ;; + -r | --root ) document_root="$2"; shift 2 ;; + -- ) shift; break ;; + * ) break ;; + esac +done + +cd $document_root + +$wp_exec cli info + +siteurl=$($wp_exec option get siteurl --quiet --path=$path) +blogname=$($wp_exec option get blogname --path=$path) +admin_email=$($wp_exec option get admin_email --path=$path) +echo -e "\n\033[1mMise-à-jour et maintenance du site $blogname\033[0m" +echo "$siteurl" +echo "Pour toutes questions et problèmes, contacter l'administrateur $admin_email" + + +echo -e "\n\033[1;31mUpdates...\033[0m" + +echo -e "\n\033[1mCore update...\033[0m" + +# Vérifier si des MAJ sont disponibles ? +$wp_exec core check-update --path=$path + +echo -e "\n" +# Mettre à jour WordPress: +$wp_exec core update --path=$path + +# Mettre à jour la bdd: +$wp_exec core update-db --path=$path + + +echo -e "\n\033[1mPlugins update...\033[0m" + +# Vérifier si des MAJ de plugins sont disponibles ? +$wp_exec plugin update --all --dry-run --path=$path + +echo -e "\n" + +# Mettre à jour tous les plugins: +$wp_exec plugin update --all --path=$path + + +echo -e "\n\033[1mThemes update...\033[0m" + +# Vérifier si des MAJ de themes sont disponibles ? +$wp_exec theme update --all --dry-run --path=$path + +echo -e "\n" + +# Mettre à jour tous les themes: +$wp_exec theme update --all --path=$path + + +echo -e "\n\033[1mLanguage update...\033[0m" + +# Mettre à jour les traductions de WordPress: +$wp_exec language core update --path=$path + +# Mettre à jour les traductions de tous les plugins: +$wp_exec language plugin update --all --path=$path + +# Mettre à jour les traductions de tous les themes: +$wp_exec language theme update --all --path=$path + +# status + +echo -e "\n\033[1mPlugins and themes status...\033[0m" + +$wp_exec plugin status --path=$path + +echo + +$wp_exec theme status --path=$path + + +# 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_exec package list | sed -n '1!p' | awk '{print $1'}) + + + if [ "$transient" = true ]; then + #echo -e "\n\033[1mSupprimer les transients expirés...\033[0m" + echo -e "\n\033[1mRemove expired transients...\033[0m" + + $wp_exec transient delete --expired --path=$path + fi + + if [ "$database" = true ]; then + #echo -e "\n\033[1mMaintenance bdd...\033[0m" + echo -e "\n\033[1mDatabase maintenance...\033[0m" + + $wp_exec db optimize --quiet --path=$path + + #wp db repair --quiet --path=$path + fi + + if [ "$backup" = true ]; then + #echo -e "\n\033[1mSauvegarde bdd...\033[0m" + echo -e "\n\033[1mDatabase backup...\033[0m" + + DATE=`date +%Y-%m-%d_%H:%M:%S` + file="wp-$blogname-$DATE.sql" + + $wp_exec db export "$file" --add-drop-table --path=$path + mv "$file" "../$file" + fi + + if [ "$removespam" = true ]; then + #echo -e "\n\033[1mEffacer le SPAM...\033[0m" + 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_exec comment delete "$spam" --path=$path + $wp_exec comment delete $($wp_exec comment list --status=spam --format=ids --path=$path) --path=$path + else + echo "No SPAM" + fi + fi + + if [ "$emptytrash" = true ]; then + #echo -e "\n\033[1mEffacer les commentaires supprimés et post supprimés...\033[0m" + echo -e "\n\033[1mRemove comments in trash and comment from deleted posts...\033[0m" + + trashed=$($wp_exec comment list --status=trash,post-trashed --format=ids --path=$path) + if [ -n "$trashed" ]; then + $wp_exec 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[1mGarder seulement $revisions révisions...\033[0m" + echo -e "\n\033[1mKeep only $revisions revisions...\033[0m" + $wp_exec revisions clean $revisions --path=$path + + elif [ "$rev" = true ]; then + printf "Voulez-vous installer wp-revisions-cli ? (y/n)" + read choice + case "$choice" in + y|Y|o) $wp_exec 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[1mListe des trackback...\033[0m" + echo -e "\n\033[1mTrackback list...\033[0m" + + trackback=$($wp_exec comment list --type=trackback --format=ids --path=$path) + if [ -n "$trackback" ]; then + $wp_exec comment delete "$trackback" --path=$path + else + echo "No trackback post" + fi + + #echo -e "\n\033[1mListe des pingback...\033[0m" + echo -e "\n\033[1mPingback list...\033[0m" + + pingback=$($wp_exec comment list --type=pingback --format=ids --path=$path) + if [ -n "$pingback" ]; then + $wp_exec comment delete "$pingback" --path=$path + 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_exec admin --path=$path + elif [ "$admin" = true ]; then + $wp_exec package install wp-cli/admin-command + echo "" + echo -e "\n\033[1mOpen wp-admin/ page in browser...\033[0m" + $wp_exec admin --path=$path + fi + + +fi + +echo -e "\n" diff --git a/wp-cli/update_wp-cli_ovh.sh b/wp-cli/update_wp-cli_ovh.sh new file mode 100755 index 0000000..db930ea --- /dev/null +++ b/wp-cli/update_wp-cli_ovh.sh @@ -0,0 +1,6 @@ +# !/usr/bin/env bash + +# Télécharger +curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar + +scp wp-cli.phar funnymac@ftp.cluster011.ovh.net:opt/bin/wp-cli.phar diff --git a/wp-cli/wp-cli_ovh.sh b/wp-cli/wp-cli_ovh.sh new file mode 100755 index 0000000..5db89f2 --- /dev/null +++ b/wp-cli/wp-cli_ovh.sh @@ -0,0 +1,16 @@ +# !/usr/bin/env bash + +# 1. copier _wp_ovh.sh à la racine d'OVH +# 2. lancer wp-cli_ovh.sh en local + +path=wordpress +document_root=www +wp="/usr/local/php7.2/bin/php /homez.65/funnymac/opt/bin/wp" +param="--root=www" + +# Vérifier si des MAJ sont disponibles ? +#ssh funnymac@ftp.cluster011.ovh.net 'cd www/wordpress && /usr/local/php7.2/bin/php /homez.65/funnymac/opt/bin/wp core check-update' +#ssh funnymac@ftp.cluster011.ovh.net "cd $document_root/$path && $wp core check-update" + + +ssh funnymac@ftp.cluster011.ovh.net "cd;./_wp_ovh.sh --root=www"