wp-cli / extension-command

Manages plugins and themes, including installs, activations, and updates.
MIT License
90 stars 79 forks source link

Weird format when image created, when using wp plugin update #295

Closed neural-oD closed 3 years ago

neural-oD commented 3 years ago

I've been doing some updates using scripts, and further to this, I create reports that give me an overview. This used to work at some point, but on an update a while back, I'm getting a situation where my image created, is coming out in a weird format -hex by the appearance of it. Here's the scenario: If I run the command wp plugin list ...... I get the expected results in both stdout and the image created. However, if I run the command `wp plugin update ....' I get different results on stdout and the image. The image created isn't correct. Due to this I surmise that the error is in the wp plugin update command rather than in the other parts of the script, as mentioned - list works well.

Here's a script:

#!/bin/bash
faketty() {
   # 0</dev/null script --quiet --flush --return --command "$(printf "%q " "$@")" /dev/null
    script -qfec "$(printf "%q " "$@")" /dev/null
}

read -p  'What is the url: ' url 
echo
shopt -s extglob
echo
hdir=$(virtualmin list-domains --domain $url --home-only)
usr=$(virtualmin list-domains --domain $url --user-only)
htmldir="$(virtualmin list-domains --domain $url --simple-multiline | grep -e "HTML directory: " | sed -e 's/    HTML directory: //')"

#Temp Directory to save files before moving them off 
tmpdir=/home/ant/tmp-staging/
#Final saving directory
savdir=/home/ant/backups/Backups_Security_Checks/

echo 
echo 'The Linux Username is: '$usr
echo 'The Home Directory is: '$hdir
echo 'The HTML Directory is: '$htmldir
echo
echo
echo 'The tmp Directory is: '$tmpdir
echo 'The Final Save Directory is: '$savdir
echo 

read -p 'Is the above correct? ' -n 1 -r

if [[ $REPLY =~ ^[Yy]+$ ]]; then
        echo

        faketty sudo -u $usr /usr/local/bin/wp --path="${htmldir}"/ plugin update --all |awk '/Disabling\ Maintenance/,EOF'|tee >(convert -font Courier -pointsize 18 label:@- "${savdir}${url}_${
curr_date}.plugins_test.png")
#       faketty sudo -u $usr /usr/local/bin/wp --path="${htmldir}"/ plugin list |awk '/name/,EOF'|tee >(convert -font Courier -pointsize 18 label:@- "${savdir}${url}_${curr_date}.plugins_list_test.png")
fi

Ok, so a quick rundown: faketty is just there, else the formatting will be weird when using tee. If you want to reproduce, you'll need imagemagick.

So when I run and test this, I usually comment out either the last or second last command in the script.

Results from test:

List

This is created from the convert image magick script, and it resembles stdout. equi-silhouette co za_ plugins_list_test

Update

This is what stdout looks like - from a screen capture.

2021-08-11_13-58


This is the image produced from convert script. This is what is not correct, almost like there's some other encoding?

equi-silhouette co za_ plugins_test


I really would appreciate any help that would get to the bottom of this.

For further reading or info, I posted something similar a while ago in the image magick forum: https://github.com/ImageMagick/ImageMagick/discussions/3553


thanks in advance

neural-oD commented 3 years ago

Just a bump on this issue. Has no one come across this issue atm?

schlessera commented 3 years ago

@neural-oD The characters you're seeing in the image are from the colorized output in the wp plugin update command. Your shell should normally signify that it is not compatible with color escape codes, so it should work correctly automatically. It doesn't for you, but this should be an issue of shell configuration or a tool misrepresenting what it can accept.

Either way, you should be able to get the correct output by adding the --no-color parameter to your commands.

neural-oD commented 3 years ago

Thanks @schlessera for the input. I've tried the --no-color, but unfortunately it didn't work. Still the same results. I suspect it's something still with the update command, as everything else is correct, and works correctly with the list command, but not the update.