DomT4 / homebrew-autoupdate

:tropical_drink: An easy, convenient way to automatically update Homebrew.
BSD 2-Clause "Simplified" License
1.01k stars 55 forks source link

Enable scheduling of autoupdate with a cron like syntax `brew autoupdate subcommand [schedule/interval] [options]` #119

Open swissbuechi opened 10 months ago

swissbuechi commented 10 months ago

Solves issue: https://github.com/Homebrew/homebrew-autoupdate/issues/59

You know have the option to pass a cron like schedule definition to the start command instead of an interval. The main goal was to provide a fix for skipped executions when the computer is asleep during the time an interval should be triggered. This can result in skipped updates and therefore vulnerable devices.

Usage

output from --help:

... A schedule is a string of five hyphen-separated digits in a cron like format. Minute(0-59)-Hour(0-23)-Day(1-31)-Weekday(0-7)-Month(1-12) Missing values are considered wildcards. For example: brew autoupdate start 0-12--- would run autoupdate every day at noon (12:00). For more information on StartCalendarInterval, see man launchd.plist.

A interval has to be passed in seconds, so 12 hours would be brew autoupdate start 43200. The exact time of execution depends on the last system boot. If the computer is asleep at the scheduled time, the interval will be skipped. This could lead to skipped intervals and is therefor not a recommended option. Use a schedule instead. ...

Error handling

Invalid character

~ » brew autoupdate start 0-12-T--
Error: Error: Schedule (Minute:0, Hour:12, Day:T, Weekday:any, Month:any) contains invalid character 'T' in Day at position 3. Must be a digit or empty.

Invalid value

~ » brew autoupdate start 0-25---
Error: Error: Schedule (Minute:0, Hour:25, Day:any, Weekday:any, Month:any) is outside the allowed range '25' in Hour at position 2. Allowed range Hour: 0-23.

Invalid pattern If the pattern is not recognized (missing one hyphen, for example), it will show the output of --help followed by this line:

Error: Invalid usage: This subcommand only accepts a schedule pattern or interval integer as argument.

Additional infos

Please refer to this comment for a more in depth explanation of the solved problem. You will also find a sample of how StartInterval is different from StartCalendarInterval regarding the plist XML definition.

The interval option is still supported and can be used like before. When the user does not specify a custom interval or custom schedule, it will fall back to 0-12---:

This script will run brew update in the background every day at noon (12:00) (by default) until explicitly told to stop, utilizing launchd. If the computer is asleep at the scheduled time, it will start as soon the computer is awake.

github-actions[bot] commented 9 months ago

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

swissbuechi commented 9 months ago

not stale

github-actions[bot] commented 8 months ago

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

swissbuechi commented 8 months ago

not stale

github-actions[bot] commented 7 months ago

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

swissbuechi commented 7 months ago

not stale