-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix makemysql so that easywp might work #154
Conversation
Remember to close #103 also after merging this (if this works) |
lets see if not running |
makeservices/makemysql
Outdated
wp config set DB_PASSWORD "$PASS" > /dev/null 2>&1 | ||
fi | ||
# Added for backward compatibility - the last line will be | ||
# extracted by "tail -n 1" and the mysterious "grep" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may wish to mention which script is running these commands.
makeservices/makemysql
Outdated
# extracted by "tail -n 1" and the mysterious "grep" | ||
# will extract the password after the colon | ||
# So that it simulate the same behaviour as the original makemysql | ||
# which output the same thing as in makemysql-real |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# So that it simulate the same behaviour as the original makemysql
# which output the same thing as in makemysql-real
I would remove these comments; the comments in the previous lines about easywp already tell me everything I need to know.
I feel like it would make more sense to update the whole stack here in one swipe:
|
will do |
Do u mean 2. here or PR #2...? |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking pretty good so far
makeservices/easywp
Outdated
@@ -57,7 +57,7 @@ fi | |||
|
|||
# Get SQL password | |||
echo "Resetting database password..." | |||
sqlpass=$(echo "yes" | makemysql | tail -n 1 | grep -Po '(?<=: )([0-9a-zA-Z]){24,}$') | |||
sqlpass=$(makemysql --unreadable-output --silent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like you should have --ignore-wp
here too, since there won't be any wordpress installation yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--ignore-wp
is for those who installed WordPress but don't want to change their pw, here the thing will be done by wp-cli
in makemysql
imo
makeservices/makemysql
Outdated
YES="--silent" | ||
shift | ||
;; | ||
# I've seen -*|--*=), but idk what does the = serve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's for options like --key=value probably, but i wouldn't worry about it
makeservices/makemysql
Outdated
esac | ||
done | ||
|
||
PASS=$(sudo -u mysql /opt/share/utils/makeservices/makemysql-real $SILENT | tail -n 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what's the point of --silent, since we're always only going to see the last line (because of tail). Maybe we could make it so that makemysql-real prints its messages to stderr so they aren't affected but the subshell and tail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is what I was expecting (only printing the password), but I do not know if other calls in makemysql-real
print anything to stdout
, so tail
was added to make sure.
That being said, I was considering about what if makemysql-real
failed, without grep
PASS
would be some weird stuffs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we should be adding the same option to control makemysql-real
's output that we are adding to makemysql
then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've actually done that, but I didn't test makemysql-real
and the things it call might output some other mysterious stuff ig
makeservices/makemysql
Outdated
if (wp core is-installed --quiet --path="$HOME/public_html" > /dev/null 2>&1) && | ||
([ $# -ne 1 ] || ( [ $# -eq 1 ] && [ ! "$1" = '--ignore-wp' ])); then | ||
echo "WordPress installation detected, changing WordPress mysql password for you." | ||
if (wp core is-installed --quiet --path="$HOME/public_html" > /dev/null 2>&1) && ! $IGNORE_WP ; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is kind of weird, it is literally running the commands true
or false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lemme do some research, my shell script sucks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I'd check
IGNORE_WP
first before running a command. - Nit: beware that putting parentheses around a command runs it in a subshell (which is not necessary in this case). Up to you if you want to keep them around or not, though; I don't think it makes too much of a practical difference in this case either.
- https://stackoverflow.com/questions/2953646/how-can-i-declare-and-use-boolean-variables-in-a-shell-script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this. I've left a couple comments.
makeservices/makemysql
Outdated
esac | ||
done | ||
|
||
PASS=$(sudo -u mysql /opt/share/utils/makeservices/makemysql-real $SILENT | tail -n 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we should be adding the same option to control makemysql-real
's output that we are adding to makemysql
then.
makeservices/makemysql
Outdated
if (wp core is-installed --quiet --path="$HOME/public_html" > /dev/null 2>&1) && | ||
([ $# -ne 1 ] || ( [ $# -eq 1 ] && [ ! "$1" = '--ignore-wp' ])); then | ||
echo "WordPress installation detected, changing WordPress mysql password for you." | ||
if (wp core is-installed --quiet --path="$HOME/public_html" > /dev/null 2>&1) && ! $IGNORE_WP ; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I'd check
IGNORE_WP
first before running a command. - Nit: beware that putting parentheses around a command runs it in a subshell (which is not necessary in this case). Up to you if you want to keep them around or not, though; I don't think it makes too much of a practical difference in this case either.
- https://stackoverflow.com/questions/2953646/how-can-i-declare-and-use-boolean-variables-in-a-shell-script
makeservices/makemysql-real
Outdated
@@ -78,43 +80,50 @@ def main(): | |||
# Read config file. | |||
mysql_host, mysql_root_pw = read_config() | |||
|
|||
# Added a simple and stupid argument parsing so that other scripts can use it without tunneling in yes. | |||
if len(sys.argv) > 1 and sys.argv[1] in ['-s', '--silent']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'd use argparse
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's only one possible argument which I don't want to utilize a heavy parser
makeservices/makemysql-real
Outdated
|
||
# Check if the database already exists. | ||
try: | ||
print(">>> Checking if database '{}' already exists...".format(username)) | ||
if not silent: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not silent:
print(
Probably worth creating a wrapper for this...
makeservices/easywp
Outdated
@@ -57,7 +57,7 @@ fi | |||
|
|||
# Get SQL password | |||
echo "Resetting database password..." | |||
sqlpass=$(echo "yes" | makemysql | tail -n 1 | grep -Po '(?<=: )([0-9a-zA-Z]){24,}$') | |||
sqlpass=$(makemysql --unreadable-output --silent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe --machine-readable
or similar?
Idk what happened to my local repo, but there seems to be a screwup Updates:
Can't believe I procrastinated on this for almost 1 year! |
makeservices/easywp
Outdated
if [ $? -ne 0 ] || [[ -z "$sqlpass" ]]; then | ||
echo -e "\033[31mError:\033[00m Could not retrieve database password. Run makemysql to see the issue." | ||
exit 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it stands, this code is not going to be executed at all if makemysql
exits with a non-zero status due to the set -e
at the top of the script.
To avoid this...I guess we can add a set +e
right before the makemysql
call and a set -e
after the if
block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
makeservices/makemysql-real
Outdated
@@ -78,43 +83,45 @@ def main(): | |||
# Read config file. | |||
mysql_host, mysql_root_pw = read_config() | |||
|
|||
# Added a simple and stupid argument parsing so that other scripts can use it without tunneling in yes. | |||
if len(sys.argv) > 1 and sys.argv[1] in ['-s', '--silent']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call it --quiet
if I were you. --silent
sounds like no output would be printed at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed names
makeservices/makemysql
Outdated
|
||
# Check if wp is installed with wp-cli | ||
# And change password if installed with easywp | ||
# But change password only if installed with easywp is a wrong statement | ||
# Use --ignore-wp flag to skip this process | ||
if (wp core is-installed --quiet --path="$HOME/public_html" > /dev/null 2>&1) && ! $IGNORE_WP ; then | ||
if $IGNORE_WP && ! wp core is-installed --quiet --path="$HOME/public_html" > /dev/null 2>&1 ; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be ! $IGNORE_WP
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was stupid!
makeservices/makemysql
Outdated
# Added for backward compatibility - the last line will be | ||
# extracted by "tail -n 1" and the mysterious "grep" | ||
# will extract the password after the colon in legacy codes | ||
# So that it simulate the same behaviour as the original makemysql | ||
# which output the same thing as in makemysql-real |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is out of date?
redirected some stuff to stderr fix stupid mistakes for makemysql-real
…and make things fancy but they might not work as I didn't test it
…did not run pre commit yet
1. Changed --silent to --quiet 2. Disable `set -e` at places where error-handling exists 3. Added some more instructions 4. Removed some redundant stuff, but idk if this will blow stuff up
ed928b3
to
2798e6b
Compare
oh no, i decided to rebase and force-push, seems like a very bad decision Anyway, @kpengboy 's valuable suggestions are applied, and the only thing remaining is pre-commit and style check... Which I need to do on |
Would you be interested in reviving this PR? |
Yes, I think it's good tho? |
It appears CI is failing, could you look into that? Also wasn't sure if there were any review comments left to do |
It seems that you'll need to fix some shellcheck issues? Otherwise LGTM, assuming that you have tested this. |
Remember to SQUASH if you reviewed and decided to merge please 😴 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, assuming you have tested these changes thoroughly.
As |
# last line. The --quiet will also make sure it only output the password... | ||
PASS=$(sudo -u mysql /opt/share/utils/makeservices/makemysql-real --quiet) | ||
|
||
if [ $? ] ; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should these be if [[ $? -ne 0 ]]
? Since we are checking if the return code was abnormal (0 is success)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you inverted this in 051e0387350c67f0fd6cf976da25ad8511ad46bb
to make precommit pass. What was the issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why but pre-commit say I should use if [ $? ]
instead of if [[ $? -ne 0 ]]
so I accepted this recommendation
This commit consists 18 commits in total, earliest one dating back to May 2020, intended to fix chain reactions caused by #129. This commit: 1. Changed `makemysql-real`, allowing it to output only the password and nothing else if a specific argument is given 2. Changed `makemysql`, allowing it to correctly fetch password printed by `makemysql-real`, allowing it to be silent if no wordpress installation is found, allowing it to not change wordpress password if a specific argument is given, and allowing it to output only the password and nothing else if a specific argument is given. 3. Changed `easywp` so that it is compatible with the updated `makemysql`. Hopefully, this will not break ocf infra. 18 commits: * rewrote so that it might work * idk wat autopep8 changed/suggested i followed its advice * forgot to add the messages * Added argument parsing and non-human-friendly output * Squashed two commits redirected some stuff to stderr fix stupid mistakes for makemysql-real * updated all three scripts so that they support some silent arguments and make things fancy but they might not work as I didn't test it * fix stupid bugs made in 3cac9d4 * fix pre-commit problem made in 3cac9d4 * Wrapper for if silent * Fixed a stupid logical mistake and added some stuff in bash scripts; did not run pre commit yet * Applied @kpengboy's suggestions 1. Changed --silent to --quiet 2. Disable `set -e` at places where error-handling exists 3. Added some more instructions 4. Removed some redundant stuff, but idk if this will blow stuff up * Bug: if quite is specified, do not ask if user wants to proceed. * Indentation Errors * Fix, silent should be global variable * Fixed some bugs in easywp * fix comment * fix so precommit pass * more to squash
Why kuroko? bc the committer is shirai kuroko (use
git log
)Judgement desu no
idk if i have access on this repo so i'll just use mine
#137
Problem is it used to just output
sudo -u mysql /opt/share/utils/makeservices/makemysql-real
, and after #129 it's nothing, #138 sometimes give a string so this will screw up, as easywp rely on some stuff extracted fromtail -n 1
that look likeYour MySQL database password is: aioeuwhgviujashfuiasb
This one just simulate if we were running
sudo -u mysql /opt/share/utils/makeservices/makemysql-real
and output the stuff in the last line so there are probably backwards compatibilityAnother feature: use argument --ignore-wp to not reset in case you don't want to, and this shall remain a secret so that it is not abused
Potential problems:
wp core is-installed --quiet --path=$HOME/public_html > /dev/null 2>&1
return true if wp exists and false otherwise2.5 i didn't run make test for style check - ok i screwed up, wait oneNow it worked