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

Non-zero exit code when updates are available #3

Closed
issrec opened this issue Jul 22, 2024 · 6 comments · Fixed by #4
Closed

Non-zero exit code when updates are available #3

issrec opened this issue Jul 22, 2024 · 6 comments · Fixed by #4
Assignees
Labels
enhancement New feature or request

Comments

@issrec
Copy link

issrec commented Jul 22, 2024

Hi, I did three sessions with the routeros-upgrader tool:

$ echo N |./routeros-upgrader -l MikroTik; echo $?
2024/07/22 08:27:42 checking installed packages
|UP> MikroTik: dude-7.13.4-arm => dude-7.15.2-arm
|UP> MikroTik: container-7.13.4-arm => container-7.15.2-arm
|UP> MikroTik: routeros-7.13.4-arm => routeros-7.15.2-arm
|UP> MikroTik: wireless-7.13.4-arm => wireless-7.15.2-arm
Install? [y/N]: 0
$ echo Y |./routeros-upgrader -l MikroTik; echo $?
2024/07/22 08:40:12 checking installed packages
|UP> MikroTik: dude-7.13.4-arm => dude-7.15.2-arm
|UP> MikroTik: container-7.13.4-arm => container-7.15.2-arm
|UP> MikroTik: routeros-7.13.4-arm => routeros-7.15.2-arm
|UP> MikroTik: wireless-7.13.4-arm => wireless-7.15.2-arm
Install? [y/N]: 2024/07/22 08:40:13 downloading "dude-7.15.2-arm.npk"
2024/07/22 08:40:13 downloaded "dude-7.15.2-arm.npk" (1319057 bytes)
2024/07/22 08:40:14 MikroTik: uploaded dude-7.15.2-arm.npk
2024/07/22 08:40:14 downloading "container-7.15.2-arm.npk"
2024/07/22 08:40:14 downloaded "container-7.15.2-arm.npk" (98449 bytes)
2024/07/22 08:40:14 MikroTik: uploaded container-7.15.2-arm.npk
2024/07/22 08:40:14 downloading "routeros-7.15.2-arm.npk"
2024/07/22 08:40:15 downloaded "routeros-7.15.2-arm.npk" (11557096 bytes)
2024/07/22 08:40:21 MikroTik: uploaded routeros-7.15.2-arm.npk
2024/07/22 08:40:21 downloading "wireless-7.15.2-arm.npk"
2024/07/22 08:40:31 downloaded "wireless-7.15.2-arm.npk" (2003089 bytes)
2024/07/22 08:40:33 MikroTik: uploaded wireless-7.15.2-arm.npk
Execute synchronized reboot? [y/N]: 2024/07/22 08:40:33 EOF
1
$ ./routeros-upgrader -y -l MikroTik; echo $?
2024/07/22 08:41:48 checking installed packages
|UP> MikroTik: dude-7.13.4-arm => dude-7.15.2-arm
|UP> MikroTik: container-7.13.4-arm => container-7.15.2-arm
|UP> MikroTik: routeros-7.13.4-arm => routeros-7.15.2-arm
|UP> MikroTik: wireless-7.13.4-arm => wireless-7.15.2-arm
2024/07/22 08:41:48 downloading "dude-7.15.2-arm.npk"
2024/07/22 08:41:52 downloaded "dude-7.15.2-arm.npk" (1319057 bytes)
2024/07/22 08:41:53 MikroTik: uploaded dude-7.15.2-arm.npk
2024/07/22 08:41:53 downloading "container-7.15.2-arm.npk"
2024/07/22 08:41:53 downloaded "container-7.15.2-arm.npk" (98449 bytes)
2024/07/22 08:41:54 MikroTik: uploaded container-7.15.2-arm.npk
2024/07/22 08:41:54 downloading "routeros-7.15.2-arm.npk"
2024/07/22 08:42:38 downloaded "routeros-7.15.2-arm.npk" (11557096 bytes)
2024/07/22 08:42:45 MikroTik: uploaded routeros-7.15.2-arm.npk
2024/07/22 08:42:45 downloading "wireless-7.15.2-arm.npk"
2024/07/22 08:42:45 downloaded "wireless-7.15.2-arm.npk" (2003089 bytes)
2024/07/22 08:42:46 MikroTik: uploaded wireless-7.15.2-arm.npk
2024/07/22 08:42:46 MikroTik: rebooting in 10s
0

If the tool returned a non-zero exit code when updates were available, it could be used to monitor/automate mass upgrade.
However, it would be worth taking care of standard input processing ;) and perhaps introducing the -n (force no) option.

@Marco98 Marco98 self-assigned this Jul 22, 2024
@Marco98 Marco98 added the enhancement New feature or request label Jul 22, 2024
@Marco98 Marco98 linked a pull request Jul 26, 2024 that will close this issue
@Marco98
Copy link
Owner

Marco98 commented Jul 26, 2024

Hi @issrec

many thanks for your interest in this project!
Please check out this prerelease

I've added a -n flag and added the exit-code 2 when:

  • Updates are pending and no is set via "N" in the first interactive prompt
  • Updates are pending and no is forced via -n

Does this solve your use case?

@issrec
Copy link
Author

issrec commented Jul 26, 2024

Hi @Marco98,
this is a great change and it works:

$ ./routeros-upgrader -n; echo $?
2024/07/26 11:35:28 checking installed packages
|UP> MikroTik1: routeros-7.15.2-powerpc => routeros-7.15.3-powerpc
|UP> MikroTik1: wireless-7.15.2-powerpc => wireless-7.15.3-powerpc
|UP> MikroTik2: dude-7.15.2-arm => dude-7.15.3-arm
|UP> MikroTik2: container-7.15.2-arm => container-7.15.3-arm
|UP> MikroTik2: routeros-7.15.2-arm => routeros-7.15.3-arm
|UP> MikroTik2: wireless-7.15.2-arm => wireless-7.15.3-arm
2
$ echo N |./routeros-upgrader; echo $?
2024/07/26 11:37:55 checking installed packages
|UP> MikroTik1: routeros-7.15.2-powerpc => routeros-7.15.3-powerpc
|UP> MikroTik1: wireless-7.15.2-powerpc => wireless-7.15.3-powerpc
|UP> MikroTik2: dude-7.15.2-arm => dude-7.15.3-arm
|UP> MikroTik2: container-7.15.2-arm => container-7.15.3-arm
|UP> MikroTik2: routeros-7.15.2-arm => routeros-7.15.3-arm
|UP> MikroTik2: wireless-7.15.2-arm => wireless-7.15.3-arm
Install? [y/N]: 2

A small digression.
My routers are set to knock. When they are not reachable, the error code returned is 0 - which suggests that everything is OK and there are no pending updates, which is not true 😉:

$ ./routeros-upgrader -n; echo $?
2024/07/26 11:34:54 checking installed packages
|DN> MikroTik1: unreachable
|DN> MikroTik2: unreachable
2024/07/26 11:34:54 no action required - exiting
0

@Marco98
Copy link
Owner

Marco98 commented Jul 27, 2024

Hi @issrec,
yeah it makes more sense in this case with a non-zero exit code.
I've now added an error to this. Please see this prerelease

@issrec
Copy link
Author

issrec commented Jul 29, 2024

Hi @Marco98,
I thank you for the change. It looks better:

$ ./routeros-upgrader -n; echo $?
2024/07/29 07:37:47 checking installed packages
|DN> MikroTik1: unreachable
|DN> MikroTik2: unreachable
2024/07/29 07:37:47 no action required - exiting
2024/07/29 07:37:47 fatal error: one or more routers unreachable
1
$ ./routeros-upgrader -n; echo $?
2024/07/29 07:38:39 checking installed packages
|DN> MikroTik1: unreachable
|UP> MikroTik2: dude-7.15.2-arm => dude-7.15.3-arm
|UP> MikroTik2: container-7.15.2-arm => container-7.15.3-arm
|UP> MikroTik2: routeros-7.15.2-arm => routeros-7.15.3-arm
|UP> MikroTik2: wireless-7.15.2-arm => wireless-7.15.3-arm
2

@Marco98
Copy link
Owner

Marco98 commented Jul 29, 2024

@issrec thank you!
Do you need additional tweaks for your automation or can i release the changes?

@issrec
Copy link
Author

issrec commented Jul 29, 2024

Overall it's OK and that's enough for my automation.
For now I see one/two situations that are not recognizable:

$ ./routeros-upgrader -n; echo $?
2024/07/26 11:35:28 checking installed packages
|UP> MikroTik1: routeros-7.15.2-powerpc => routeros-7.15.3-powerpc
|UP> MikroTik1: wireless-7.15.2-powerpc => wireless-7.15.3-powerpc
|UP> MikroTik2: dude-7.15.2-arm => dude-7.15.3-arm
|UP> MikroTik2: container-7.15.2-arm => container-7.15.3-arm
|UP> MikroTik2: routeros-7.15.2-arm => routeros-7.15.3-arm
|UP> MikroTik2: wireless-7.15.2-arm => wireless-7.15.3-arm
2
$ ./routeros-upgrader -n; echo $?
2024/07/29 07:38:39 checking installed packages
|DN> MikroTik1: unreachable
|UP> MikroTik2: dude-7.15.2-arm => dude-7.15.3-arm
|UP> MikroTik2: container-7.15.2-arm => container-7.15.3-arm
|UP> MikroTik2: routeros-7.15.2-arm => routeros-7.15.3-arm
|UP> MikroTik2: wireless-7.15.2-arm => wireless-7.15.3-arm
2

I thank you @Marco98 for the changes you made.

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

Successfully merging a pull request may close this issue.

2 participants