Skip to content
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

Additions, Improvements & Fixes #366

Merged
merged 4 commits into from
Nov 26, 2024

Conversation

Martinski4GitHub
Copy link
Collaborator

@Martinski4GitHub Martinski4GitHub commented Nov 25, 2024

Made significant changes in the menu option to set the cron schedule for automatic F/W Updates.

  1. There are now 2 modes of operation to set the cron schedule: Guided & Custom.

    a) The "Menu-Guided Entry" is intended to help users select the MINUTES, HOUR, and DAYS for the cron schedule. Useful for users who are not familiar with the cron scheduling syntax.

    b) The "Custom Input/Entry" is intended for users who already know the cron scheduling syntax and can enter the full "raw" schedule string without much help.

  2. Added code to synchronize the cron schedule for automatic script updates with the schedule for automatic F/W updates. Currently, the check for automatic script updates will be performed daily but 15 minutes before the time when the cron for automatic F/W updates is scheduled. This ensures that the script is always updated first before proceeding to check for automatic F/W updates.

  3. Fixed code in the cron schedule that allowed setting a cron job to run every minute and/or every hour of the day. Technically, this should not be allowed for the purposes of doing automatic F/W updates.

  4. Various code improvements & fine-tuning.

Made significant changes in the menu option to set the cron schedule for automatic F/W Updates.

1) There are now 2 modes of operation to set the cron schedule: Guided & Custom.

   a) The "Menu-Guided Entry" is intended to help users select the MINUTES, HOUR and DAYS for the cron schedule. Useful for users who are not familiar with the cron syntax.

   b) The "Custom Input/Entry" is intended for users who already know the cron syntax and can enter the full "raw" schedule string without much help.

2) Added code to synchronize the cron schedule for automatic script updates with the schedule for automatic F/W updates. Currently, the check for automatic script updates will be performed daily but 15 minutes before the time when the cron for automatic F/W updates is scheduled. This ensures that the script is always be updated first before proceeding to check for automatic F/W updates.

3) Fixed code in the cron schedule that was allowing setting a cron job to run every minute and/or every hour of the day. Technically, this should not be allowed for the purposes of doing automatic F/W updates.

4) Various code improvements & fine-tuning.
@Martinski4GitHub
Copy link
Collaborator Author

@ExtremeFiretop,

Whenever you have a chance, please review and test the changes in this PR.
I tested as much as I could but, as always, a 2nd pair of eyes is always helpful for validation.
There are a couple of minor improvements I'd still like to make but essentially the code is 99% there and ready for testing, especially the area of setting the cron job for F/W updates which is then used to create the separate cron job for automatic script updates.

Take care & have a good night, bud.

Some minor code improvements & fine-tuning:

- Modified the messaging when selecting to ENABLE the option for automatic script updates so that it does not appear as if it's a dangerous feature to activate. It's good to display a NOTICE about the option, but I think presenting it as a WARNING sends a misleading message that "bad" things can happen with updating the script automatically. Also, now the user is prompted to confirm the daily cron schedule on display to check for new versions.

- Modified the color for ENABLED setting from red to magenta, for the same reasons stated above.

- When ENABLED, the cron schedule setting for automatic script updates is shown below the menu option. This allows users to visually check & confirm when checks for new updates are made.
@Martinski4GitHub
Copy link
Collaborator Author

@ExtremeFiretop,

I had some time this morning while I waited for a firm decision from upper management about a few options I presented to implement for our final release of 2024 (deadline: Dec 18th). So I took the time to make the minor improvements that I previously mentioned I wanted to make.

  1. Modified the messaging when choosing to ENABLE the option for automatic script updates so that it does not appear as if it's a dangerous feature to activate. It's good to display a NOTICE about the option, but I think presenting it as a WARNING sends a misleading message that "bad" things can happen with updating the script automatically. Also, now the user is prompted to confirm the daily cron schedule on display to check for new versions.

  2. Modified the color for the "ENABLED" setting from red to magenta, for the same reasons stated above.

  3. When ENABLED, the cron schedule setting for automatic script updates is shown below the menu option. This allows users to visually check & confirm when checks for new updates are made.

MerlinAU_AutoScriptUpdates

Have a good day, bud. Talk to you in the evening.

@ExtremeFiretop
Copy link
Owner

ExtremeFiretop commented Nov 26, 2024

@Martinski4GitHub

Wow you've been busy! Sorry for the delay it was a crazy day for me today between work and then I took a nap and then had to head out to get some groceries and errands done.

All that to say I'm here! This all looks fantastic. I already have some ideas on things I want to test and validate with this solution. I'll test and report back.

Also wanted to mention I'm testing and addressing some bugs and feature requests as well and will be submitting my own PR shortly. But I'll only submit it after this is merged to avoid conflicts.

@Martinski4GitHub
Copy link
Collaborator Author

@Martinski4GitHub

Wow you've been busy! Sorry for the delay it was a crazy day for me today between work and then I took a nap and then had to head out to get some groceries and errands done.

All that to say I'm here! This all looks fantastic. I already have some ideas on things I want to test and validate with this solution. I'll test and report back.

Also wanted to mention I'm testing and addressing some bugs and feature requests as well and will be submitting my own PR shortly. But I'll only submit it after this is merged to avoid conflicts.

Yeah, I got 99% of the implementation & testing done yesterday, and I believe I put the final touches and fine-tuning today. Good thing I had some free time this morning at work before getting very busy for the next 10 days or so to finalize the library components I'm working on for our final release of the year by Dec-18th. That's why I wanted to get this PR done as soon as I could. Hopefully, the latest code will work well for your own testing.

BTW, I just found a couple of bugs during my own testing this evening, and I'm able to duplicate them consistently. I'll write another message shortly with the details I'm gathering.

@ExtremeFiretop
Copy link
Owner

@Martinski4GitHub
Wow you've been busy! Sorry for the delay it was a crazy day for me today between work and then I took a nap and then had to head out to get some groceries and errands done.
All that to say I'm here! This all looks fantastic. I already have some ideas on things I want to test and validate with this solution. I'll test and report back.
Also wanted to mention I'm testing and addressing some bugs and feature requests as well and will be submitting my own PR shortly. But I'll only submit it after this is merged to avoid conflicts.

Yeah, I got 99% of the implementation & testing done yesterday, and I believe I put the final touches and fine-tuning today. Good thing I had some free time this morning at work before getting very busy for the next 10 days or so to finalize the library components I'm working on for our final release of the year by Dec-18th. That's why I wanted to get this PR done as soon as I could. Hopefully, the latest code will work well for your own testing.

BTW, I just found a couple of bugs during my own testing this evening, and I'm able to duplicate them consistently. I'll write another message shortly with the details I'm gathering.

Don't be stealing my bugs!!! :D ;)

@ExtremeFiretop
Copy link
Owner

So far the testing is going well, will merge now and do final quick round of tests. Very nice work buddy around following the primary cron job!! I know we already did some work to calculate the next upcoming cron job, but decoding it to follow it slightly is a different bear I think :P

@ExtremeFiretop
Copy link
Owner

One thing I noticed is these cron entries aren't detected as valid anymore when they were before:

image

Per per question 22 of our Wiki:

https://github.com/ExtremeFiretop/MerlinAutoUpdate-Router/wiki#question-22-why-is-my-scheduled-cron-job-not-triggering-at-the-expected-times-are-there-limitations-to-the-cron-job-schedules

MerlinAU.sh Outdated
printf "\nCurrent Schedule: ${GRNct}${scriptUpdateCronSched}${NOct}\n"
printf "[${GRNct}${cronSchedStrHR}${NOct}]\n"

if _WaitForYESorNO_ "\nConfirm daily check for automatic script updates?"
Copy link
Owner

@ExtremeFiretop ExtremeFiretop Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change the wording to this. I wasn't sure what it was asking me at first.

image

The "Proceed to enable" to me means it's being enabled, but really it seems to be the "Confirm daily check for automatic script updates?" that enables it. But it's asking that when it's showing the update schedule.

I would have it say: "Please confirm the above schedule for script updates looks correct"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change the wording to this. I wasn't sure what it was asking me at first.
...

The "Proceed to enable" to me means it's being enabled, but really it seems to be the "Confirm daily check for automatic script updates?" that enables it. But it's asking that when it's showing the update schedule.

I would have it say: "Please confirm the above schedule for script updates looks correct"

The intent of the 2nd prompt is for users to confirm that they want to enable the feature with a daily check using the cron schedule being displayed, giving them further context so they are more informed of the choice they're making. If they answer "NO" to the confirmation, it means they are canceling their initial request to enable.

I'll see if I can re-word the message to make it clearer.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Martinski4GitHub

Another choice is remove my original "proceed to enable?" So it goes straight to your validation of the schedule to be enabled then, would help cause less confusion I think?

Any suggestions? A reword could work too, or we could remove one of the "confirm, double confirm" prompts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Martinski4GitHub

Another choice is remove my original "proceed to enable?" So it goes straight to your validation of the schedule to be enabled then, would help cause less confusion I think?

Any suggestions? A reword could work too, or we could remove one of the "confirm, double confirm" prompts.

Last night, I focused primarily on improving the validation error messages and moved them around to a single place for each case so any function calling for validation gets the same error messages. WRT to this message prompt, I decided to reword it for now. I suspect most users who are interested in having automatic script updates will simply set it once and then forget about it. I honestly like the prompt asking for confirmation based on the cron schedule that's displayed - it provides users with more info before committing to the decision. I suspect not everyone will want to have yet another cron job to update the script automatically.

@Martinski4GitHub
Copy link
Collaborator Author

@ExtremeFiretop,

While doing more testing around the latest cron schedule changes for F/W Updates, I found 2 bugs.
Here's how to duplicate the problem consistently.

Prerequisite:
The "F/W Auto Updates" menu option must be ENABLED first before going to change the cron job schedule in the Advanced Options menu.

  1. Setting the 'DAY of MONTH' to any intervals (e.g. "*/5") produces errors.
    For example, set the cron schedule as "0 0 */5 * *" and save the new entry. When going back to the previous menu, a bunch of error messages ("[: */5: bad number") are displayed.

FW_UpdateCronScheduleErrors1

And the same bunch of errors are repeated when going back to the Main Menu, before the menu header is displayed.

FW_UpdateCronScheduleErrors2

  1. Setting the 'DAY of WEEK' to any intervals (e.g. "*/2") produces errors.
    For example, set the cron schedule as "15 0 * * */2" and save the new entry. When going back to the previous menu, a bunch of error messages ("[: */2: bad number") are displayed. The same symptoms as shown in the previous error scenario.

AFAICT, it looks like the current functions that calculate the next job run time don't handle any day intervals correctly. I'm not very familiar with that code so I'll let you take a look. You'll likely find the problem faster than I would.

I'm going offline in about 5 minutes to have dinner so we'll talk later.

@ExtremeFiretop
Copy link
Owner

@ExtremeFiretop,

While doing more testing around the latest cron schedule changes for F/W Updates, I found 2 bugs. Here's how to duplicate the problem consistently.

Prerequisite: The "F/W Auto Updates" menu option must be ENABLED first before going to change the cron job schedule in the Advanced Options menu.

  1. Setting the 'DAY of MONTH' to any intervals (e.g. "*/5") produces errors.
    For example, set the cron schedule as "0 0 */5 * *" and save the new entry. When going back to the previous menu, a bunch of error messages ("[: */5: bad number") are displayed.

FW_UpdateCronScheduleErrors1

And the same bunch of errors are repeated when going back to the Main Menu, before the menu header is displayed.

FW_UpdateCronScheduleErrors2

  1. Setting the 'DAY of WEEK' to any intervals (e.g. "*/2") produces errors.
    For example, set the cron schedule as "15 0 * * */2" and save the new entry. When going back to the previous menu, a bunch of error messages ("[: */2: bad number") are displayed. The same symptoms as shown in the previous error scenario.

AFAICT, it looks like the current functions that calculate the next job run time don't handle any day intervals correctly. I'm not very familiar with that code so I'll let you take a look. You'll likely find the problem faster than I would.

I'm going offline in about 5 minutes to have dinner so we'll talk later.

Okay good, not the bugs I was looking at LOL!
I'll take a quick look myself but I'm also about to have dinner. May be a bit of a late night for me tonight it seems :P

@ExtremeFiretop
Copy link
Owner

ExtremeFiretop commented Nov 26, 2024

@Martinski4GitHub

Just so your aware, the 2 bugs I found were again related to the post update emails detecting Gnuton versions as not flashed correctly. The reason is we remove the suffix specifically for thing like "ROG" or "tuf" but Gnuton always has a suffix in its version number "3004.388.8.2-Gnuton1"

So the obvious fix is remove all suffixes, don't be picky that fix is lined up.

And second bug is with the changelog verification, the regex is always failing to detect the current version in the changelog and it's a pretty simply fix I got already lined up.

@Martinski4GitHub
Copy link
Collaborator Author

One thing I noticed is these cron entries aren't detected as valid anymore when they were before:

Yes, that's intentional. The new code does not allow any intervals for the minutes. They must be full numbers only. This prevents novice users from setting up cron schedules that are technically & syntactically correct in general but are not really valid for doing F/W Updates. Do people really want to check every 20 or 30 minutes all day long?

P.S. The "boss" is calling me :>) We'll talk later...

@ExtremeFiretop
Copy link
Owner

One thing I noticed is these cron entries aren't detected as valid anymore when they were before:

Yes, that's intentional. The new code does not allow any intervals for the minutes. They must be full numbers only. This prevents novice users from setting up cron schedules that are technically & syntactically correct in general but are not really valid for doing F/W Updates. Do people really want to check every 20 or 30 minutes all day long?

P.S. The "boss" is calling me :>) We'll talk later...

I think the use-case was mostly for remote users. That used to be how we recommended they update the router (schedule for 15 minutes ahead and logout of SSH so the terminal didn't close early and terminal the script)

We can change the wiki, I think it still says that for the question 25

@ExtremeFiretop
Copy link
Owner

Also what does the code do if it's already set to let's say.. every half hour when this version is loaded? I'll review closer when I'm back from dinner.

MerlinAU.sh Outdated
cronSchedStr="$(echo "$1" | awk -F ' ' '{print $1}')"
if ! _ValidateCronScheduleMINS_ "$cronSchedStr"
then
printf "${REDct}INVALID cron value for 'MINUTE' [$cronSchedStr].${NOct}\n"
Copy link
Owner

@ExtremeFiretop ExtremeFiretop Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would clarify this, make the requirement clear that it needs to be a full minute value now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would clarify this, make the requirement clear that it needs to be a full minute value now

Good point. I'll review the messaging and modify it for more clarity.

Copy link
Owner

@ExtremeFiretop ExtremeFiretop Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Martinski4GitHub

This is a change in behavior and if one thing my job as a workstation engineer taught me (even though it wasn't for long) is changes in behaviors need to be clearly communicated to users else they just go based on memory and get confused when it doesn't work like it used too. LOOL

I'm fine with documenting the changes to the cron behavior in the Wiki, but for users trying to set it live we should give them a bit of context here I think

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Martinski4GitHub

This is a change in behavior and if one thing my job as a workstation engineer taught me (even though it wasn't for long) is changes in behaviors need to be clearly communicated to users else they just go based on memory and get confused when it doesn't work like it used too. LOOL

I'm fine with documenting the changes to the cron behavior in the Wiki, but for users trying to set it live we should give them a bit of context here I think

When you get a chance, take a look at the new error messages getting generated when validation fails. They're more verbose and provide more details about the new restrictions on the cron schedule parameters.

Remember that the cron is intended for a very specific purpose so we don't want users to be able to set up a schedule that is counter-productive to do F/W Updates. For example, before we were allowing users to set a cron job to run "every minute in every hour" which would be the wrong thing to do. The intention now is to "guide" the users to make more reasonable choices, especially with MINUTE & HOUR parameters.

@ExtremeFiretop
Copy link
Owner

  1. Setting the 'DAY of MONTH' to any intervals (e.g. "*/5") produces errors.
    For example, set the cron schedule as "0 0 */5 * *" and save the new entry. When going back to the previous menu, a bunch of error messages ("[: */5: bad number") are displayed.

I think I got the fix.

@ExtremeFiretop
Copy link
Owner

@Martinski4GitHub

image

image

@Martinski4GitHub
Copy link
Collaborator Author

Martinski4GitHub commented Nov 26, 2024

One thing I noticed is these cron entries aren't detected as valid anymore when they were before:

Yes, that's intentional. The new code does not allow any intervals for the minutes. They must be full numbers only. This prevents novice users from setting up cron schedules that are technically & syntactically correct in general but are not really valid for doing F/W Updates. Do people really want to check every 20 or 30 minutes all day long?
P.S. The "boss" is calling me :>) We'll talk later...

I think the use-case was mostly for remote users. That used to be how we recommended they update the router (schedule for 15 minutes ahead and logout of SSH so the terminal didn't close early and terminal the script)

AFAIK, that scenario was resolved by adding the option to keep Tailscale & ZeroTier active when stopping all Entware services and by adding code to ignore the SIGHUP signal so that the script process can continue after the SSH session window is terminated.

An alternative method would be to set the cron schedule with the HOUR & MINUTE parameters set to 15-20 minutes into the future. For example, if the current hour is 10:50 PM one can set the cron schedule to "10 23 * * *" and then exit. No need to use intervals for the MINUTE parameter.

We can change the wiki, I think it still says that for the question 25

Yes, we'll need to document all these changes in the WIKI as well.

@Martinski4GitHub
Copy link
Collaborator Author

Also what does the code do if it's already set to let's say.. every half hour when this version is loaded? I'll review closer when I'm back from dinner.

Good question. Currently, upon initialization, the code simply creates the cron job using whatever schedule is stored in the configuration file - no validation is made. However, once users go to the CLI menu to change or simply check the cron job setting, the validation code will be triggered, checking for the new restrictions.

@ExtremeFiretop
Copy link
Owner

AFAIK, that scenario was resolved by adding the option to keep Tailscale & ZeroTier active when stopping all Entware services and by adding code to ignore the SIGHUP signal so that the script process can continue after the SSH session window is terminated.

Very true, it should technically be solved with that change! although I'm not sure how validated or tested that situation is, I think we had one user test, and ourselves. How successful it is in the wild hasn't been vetted much, that's why it's still mentioned in the Wiki.

An alternative method would be to set the cron schedule with the HOUR & MINUTE parameters set to 15-20 minutes into the future. For example, if the current hour is 10:50 PM one can set the cron schedule to "10 23 * * *" and then exit. No need to use intervals for the MINUTE parameter.

I think this is an acceptable solution, again I'll document this in the Wiki and try to be clear around the new requirements and behaviors. I'll give an example similar to how you did here.

Reworked the error messages when validating the cron schedule to provide users more information of the new restrictions to explain why some parameters fail to pass the check.

Reworded confirmation prompt when enabling automatic script updates. The idea is to provide the user the schedule details of when the checks will be performed so they are more informed when making the choice. Some people may not want to enable if they don't agree with having a daily check.
@Martinski4GitHub
Copy link
Collaborator Author

@ExtremeFiretop,

Apologies for coming back online rather late yesterday. After dinner, my wife & I sat down to watch a TV show but I fell asleep in about 10 minutes and didn't wake up until about 1 hour later.

Anyway, I just woke up to prepare for an early meeting this morning, but I wanted to submit my latest changes to the PR.

Last night, I focused primarily on reworking the error messages generated when validating the cron schedule to provide users with as much information as possible on the screen and explain the new restrictions that may explain why some parameters are failing to pass the validation checks.

When you get a chance, please take another look at the new error messages getting generated. These messages will likely be useful when documenting the changes on the Wiki page.

@ExtremeFiretop
Copy link
Owner

@Martinski4GitHub

Thanks Martinski! Will do a final review this morning after my work meeting and merge, then submit my PR with the requested fixes :)

@Martinski4GitHub
Copy link
Collaborator Author

@Martinski4GitHub

Thanks Martinski! Will do a final review this morning after my work meeting and merge, then submit my PR with the requested fixes :)

Take your time. I don't think the bugs found & fixed are very critical to the functionality. In fact, the 2 bugs I found have been there for quite a while, but I suspect users don't set up the cron schedule with any kind of day intervals; otherwise, we would heard about them by now on the SNBForums.

Going offline now... Talk to you in the evening.

@ExtremeFiretop
Copy link
Owner

@Martinski4GitHub
Thanks Martinski! Will do a final review this morning after my work meeting and merge, then submit my PR with the requested fixes :)

Take your time. I don't think the bugs found & fixed are very critical to the functionality. In fact, the 2 bugs I found have been there for quite a while, but I suspect users don't set up the cron schedule with any kind of day intervals; otherwise, we would heard about them by now on the SNBForums.

Going offline now... Talk to you in the evening.

I'll be online most of the day, meeting is just wrapped up. I'll review this and chat with you when you return buddy. Enjoy the day!

@ExtremeFiretop ExtremeFiretop merged commit b7c1b50 into ExtremeFiretop:dev Nov 26, 2024
1 check passed
@ExtremeFiretop
Copy link
Owner

Really liking this solution Martinski!
And nice job on the additional touches this morning! :) Messaging is much more clear now for someone new!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants