forked from TrueCloudLab/restic
parent
41a4d67d93
commit
7d0f2eaf24
1 changed files with 22 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
||||||
// +build selfupdate
|
// xbuild selfupdate
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
@ -36,10 +36,30 @@ func init() {
|
||||||
cmdRoot.AddCommand(cmdSelfUpdate)
|
cmdRoot.AddCommand(cmdSelfUpdate)
|
||||||
|
|
||||||
flags := cmdSelfUpdate.Flags()
|
flags := cmdSelfUpdate.Flags()
|
||||||
flags.StringVar(&selfUpdateOptions.Output, "output", os.Args[0], "Save the downloaded file as `filename`")
|
flags.StringVar(&selfUpdateOptions.Output, "output", "", "Save the downloaded file as `filename` (default: running binary itself)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func runSelfUpdate(opts SelfUpdateOptions, gopts GlobalOptions, args []string) error {
|
func runSelfUpdate(opts SelfUpdateOptions, gopts GlobalOptions, args []string) error {
|
||||||
|
if opts.Output == "" {
|
||||||
|
file, err := os.Executable()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "unable to find executable")
|
||||||
|
}
|
||||||
|
|
||||||
|
opts.Output = file
|
||||||
|
}
|
||||||
|
|
||||||
|
fi, err := os.Lstat(opts.Output)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !fi.Mode().IsRegular() {
|
||||||
|
return errors.Errorf("output file %v is not a normal file, use --output to specify a different file", opts.Output)
|
||||||
|
}
|
||||||
|
|
||||||
|
Printf("writing restic to %v\n", opts.Output)
|
||||||
|
|
||||||
v, err := selfupdate.DownloadLatestStableRelease(gopts.ctx, opts.Output, Verbosef)
|
v, err := selfupdate.DownloadLatestStableRelease(gopts.ctx, opts.Output, Verbosef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Fatalf("unable to update restic: %v", err)
|
return errors.Fatalf("unable to update restic: %v", err)
|
||||||
|
|
Loading…
Reference in a new issue