Commit Graph

26 Commits

Author SHA1 Message Date
Michael Eischer df03e8a0ec self update: remove not possible exit codes 2026-05-20 22:46:11 +02:00
Michael Eischer 9299c45818 fix typos in cmd descriptions 2026-05-20 22:46:11 +02:00
Michael Eischer a816b827cf extract GlobalOptions into internal/global package
Rough steps:
```
mv cmd/restic/global* cmd/restic/secondary_repo* internal/global/
sed -i "s/package main/package global/" internal/global/*.go
Rename "GlobalOptions" to "Options" in internal/global/
Replace everywhere " GlobalOptions" -> " global.Options"
Replace everywhere "\*GlobalOptions" -> " *global.Options"
Make SecondaryRepoOptions public
Make create public
Make version public
```
2025-10-12 17:56:28 +02:00
Michael Eischer 2c677d8db4 global: make private fields public 2025-10-12 17:56:28 +02:00
Michael Eischer e753941ad3 move NewProgressPrinter to ui package 2025-10-03 18:55:46 +02:00
Michael Eischer 3410808dcf deduplicate termstatus setup 2025-10-03 18:55:46 +02:00
Michael Eischer 2d7611373e ignore JSON flag for fully unsupported commands
Considering the flag would result in a mostly empty terminal output,
which is probably worse than text output instead of JSON.
2025-09-21 15:38:29 +02:00
Michael Eischer 6b5c8ce14e change run* functions to accept ui.Terminal instead of *termstatus.Terminal 2025-09-15 22:37:25 +02:00
Michael Eischer 6c0dccf4a5 self-update: convert to termstatus 2025-09-15 22:33:52 +02:00
Michael Eischer 412d6d9ec5 Create root command via function 2025-02-07 21:29:33 +01:00
Michael Eischer aacd6a47e3 refactor to use constructor functions to create cobra commands
This allows getting rid of the global options variables
2025-02-07 18:56:45 +01:00
Michael Eischer dc9b6378f3 move cli flags into AddFlags on option structs 2025-02-06 22:10:41 +01:00
Michael Terry 56f28c9bd5 main: return an exit code (12) for "bad password" errors 2024-08-15 16:55:45 -04:00
Michael Eischer 94fdca08c4 return exit code 10 if repository does not exist 2024-07-10 21:46:26 +02:00
Michael Eischer d76a78aa99 return exit code 11 if the repository could not be locked 2024-07-10 21:37:32 +02:00
Michael Eischer 3b7228c8c1 explicitly document exit code 1 on error 2024-07-10 21:35:46 +02:00
Klemens Nanni 94f6e7d4a6 Reinstate selfupdate tag to make builds without self-update work
Revert what seems to be a typo introduced as part of the fix for #2041
in 2018 7d0f2eaf24.

`xbuild` does not look like a go build/tag keyword to me, I failed to
find documentation for it and using `go install -tags '!selfupdate' ...`
has no effect, i.e. self-update code is still compiled.

`+build` however works;  updating the OpenBSD port/binary package
security/restic to apply this PR works as expected:

```
	$ restic help | grep self
	$ restic self-update
	unknown command "self-update" for "restic"
```

(Using `go:build` now as per restic's style and gofmt.)

Previously, using `restic-0.14.0p1` on OpenBSD/amd64 7.2-current would
check for a newer version and probably attempt replacing the system wide
root-owned executable (on a read-only filesystem) as unprivileged user:

```
	$ restic version
	restic 0.14.0 compiled with go1.19.2 on openbsd/amd64
	$ restic help | grep self
	  self-update   Update the restic binary
	$ restic self-update
	writing restic to /usr/local/bin/restic
	find latest release of restic at GitHub
	restic is up to date
```

(It never tried to actually write besaid path;  doing so would fail, so
the current message can be considered misleading.)
2022-12-26 21:46:22 +04:00
Michael Eischer 6d2d297215 pass global context through cobra 2022-10-03 00:19:46 +02:00
Michael Eischer 985722b102 Remove ctx from globalOptions
Previously the global context was either accessed via gopts.ctx,
stored in a local variable and then used within that function or
sometimes both. This makes it very hard to follow which ctx or a wrapped
version of it reaches which method.

Thus just drop the context from the globalOptions struct and pass it
explicitly to every command line handler method.
2022-10-03 00:19:46 +02:00
jtagcat a7853057ab Change: selfupdate: 'writing restic to' as verbose
Running restic self-update --quiet no longer
prints "writing restic to /usr/local/bin/restic".

The only output printed with -q is failures or
"successfully updated restic to version 0.12.1"

https://github.com/restic/restic/pull/3535

fix test fail: changelog title can't end with `.`

shorten changelog title
2021-10-09 23:24:18 +03:00
Andreas Olsson ce14df303b Don't require self-update --output placeholder file
This removes the requirement on `restic self-update --output` to point
to a path of an existing file, to overwrite. In case the specified
path does exist we still want to verify that it's a regular file,
rather than a directory or a device, which gets overwritten.

We also want to verify that a path to a new file exists within an
existing directory. The alternative being running into that issue
after the actual download, etc has completed.

While at it I also replace `errors.Errorf` with the more appropriately
verbose `errors.Fatalf`.

Resolves #2491
2020-10-03 07:02:23 +02:00
Erik Rigtorp 94f4f13388 Add documentation on exit status codes to man pages
This is step one to start defining useful exit codes for all the commands.
2020-02-12 23:09:26 +01:00
Andy Jack 3f25537a06 Fix incorrect command name in long doc for self-update 2018-10-18 18:45:31 -04:00
Alexander Neumann a432b42c81 self-update: Check current version before download 2018-10-14 17:29:46 +02:00
Alexander Neumann 7d0f2eaf24 self-update: Use correct path to restic binary
Closes #2041
2018-10-14 17:29:19 +02:00
Alexander Neumann 6e1a3987b7 Add 'self-update' command
This commit adds a command called `self-update` which downloads the
latest released version of restic from GitHub and replacing the current
binary with it. It does not rely on any external program (so it'll work
everywhere), but still verifies the GPG signature using the embedded GPG
public key.

By default, the `self-update` command is hidden behind the `selfupdate`
built tag, which is only set when restic is built using `build.go`. The
reason for this is that downstream distributions will then not include
the command by default, so users are encouraged to use the
platform-specific distribution mechanism.
2018-08-12 23:34:47 +02:00