From 88c6949208596c2166176136f8ea739707bef46e Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Thu, 6 May 2021 15:04:35 +0200 Subject: [PATCH] custom restic binary --- cmd/root.go | 1 + docs/markdown/cli/general.md | 8 ++++++++ internal/config.go | 2 +- internal/utils.go | 6 ++++-- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 2e234ba..3201aac 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -37,6 +37,7 @@ func init() { rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.autorestic.yml or ./.autorestic.yml)") rootCmd.PersistentFlags().BoolVar(&internal.CI, "ci", false, "CI mode disabled interactive mode and colors and enables verbosity") rootCmd.PersistentFlags().BoolVarP(&internal.VERBOSE, "verbose", "v", false, "verbose mode") + rootCmd.PersistentFlags().StringVar(&internal.RESTIC_BIN, "restic-bin", "restic", "specify custom restic binary") cobra.OnInitialize(initConfig) } diff --git a/docs/markdown/cli/general.md b/docs/markdown/cli/general.md index 294555b..748c7bc 100644 --- a/docs/markdown/cli/general.md +++ b/docs/markdown/cli/general.md @@ -27,4 +27,12 @@ Verbose mode will show the output of the native restic commands that are otherwi autorestic --verbose backup -a ``` +## `--restic-bin` + +With `--restic-bin` you can specify to run a specific restic binary. This can be useful if you want to [create a custom binary with root access that can be executed by any user](https://restic.readthedocs.io/en/stable/080_examples.html#full-backup-without-root). + +```bash +autorestic --restic-bin /some/path/to/my/custom/restic/binary +``` + > :ToCPrevNext diff --git a/internal/config.go b/internal/config.go index 4fb7013..b9ff25b 100644 --- a/internal/config.go +++ b/internal/config.go @@ -129,7 +129,7 @@ func CheckConfig() error { return fmt.Errorf("config could not be loaded/found") } if !CheckIfResticIsCallable() { - return fmt.Errorf(`restic was not found. Install either with "autorestic install" or manually`) + return fmt.Errorf(`%s was not found. Install either with "autorestic install" or manually`, RESTIC_BIN) } for name, backend := range c.Backends { backend.name = name diff --git a/internal/utils.go b/internal/utils.go index cd32e9b..9a73a05 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -10,13 +10,15 @@ import ( "github.com/cupcakearmy/autorestic/internal/colors" ) +var RESTIC_BIN string + func CheckIfCommandIsCallable(cmd string) bool { _, err := exec.LookPath(cmd) return err == nil } func CheckIfResticIsCallable() bool { - return CheckIfCommandIsCallable("restic") + return CheckIfCommandIsCallable(RESTIC_BIN) } type ExecuteOptions struct { @@ -50,7 +52,7 @@ func ExecuteCommand(options ExecuteOptions, args ...string) (string, error) { } func ExecuteResticCommand(options ExecuteOptions, args ...string) (string, error) { - options.Command = "restic" + options.Command = RESTIC_BIN return ExecuteCommand(options, args...) }