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

feat: add "force no" flag and exit codes #4

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Run the tool!

```shell
Usage of routeros-upgrader:
-b string
set branch (stable, testing, ..) (default "stable")
-c string
config path (default "routers.yml")
-d uint
Expand All @@ -48,6 +50,7 @@ Usage of routeros-upgrader:
install additional packages
-l string
limit routers
-n force no
-nofw
dont upgrade routerboard firmware
-t string
Expand Down
26 changes: 21 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bufio"
"bytes"
"errors"
"flag"
"fmt"
"log"
Expand All @@ -28,9 +29,11 @@ const (
)

var (
version = "dev"
commit = "none"
date = "unknown"
version = "dev"
commit = "none"
date = "unknown"
errPendingUpdatesRefused = errors.New("pending updates forced with no")
errRouterUnreachable = errors.New("one or more routers unreachable")
)

type RosParams struct {
Expand All @@ -49,7 +52,11 @@ type RosParams struct {
}

func main() {
if err := run(); err != nil {
err := run()
if errors.Is(err, errPendingUpdatesRefused) {
os.Exit(2)
}
if err != nil {
log.Fatalf("fatal error: %s", err)
}
}
Expand All @@ -63,6 +70,7 @@ func run() error {
tags := flag.String("t", "", "filter tags")
limit := flag.String("l", "", "limit routers")
forceyes := flag.Bool("y", false, "force yes")
forceno := flag.Bool("n", false, "force no")
delaysecs := flag.Uint("d", 10, "reboot delay in seconds")
extpkgsS := flag.String("extpkgs", "", "install additional packages")
prversion := flag.Bool("v", false, "print version")
Expand Down Expand Up @@ -100,10 +108,18 @@ func run() error {
pkgupdrts, fwupdrts := planUpgrades(rts, *tver, *branch, *noupdfw)
if len(pkgupdrts) == 0 && len(fwupdrts) == 0 {
log.Println("no action required - exiting")
for _, v := range rts {
if v.Conn == nil {
return errRouterUnreachable
}
}
return nil
}
if *forceno {
return errPendingUpdatesRefused
}
if !askYN("Install?", *forceyes) {
return nil
return errPendingUpdatesRefused
}

// Upgrade
Expand Down
Loading