diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c4058c..a179ef3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved error handling - Allow for specific snapshot to be restored +### Fixed + +- rclone in docker volumes + ### Changed - [Breaking Change] Declaration of docker volumes. See: https://autorestic.vercel.app/migration/1.4_1.5 @@ -20,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.4.1] - 2021-10-31 -### Fixes +### Fixed - Numeric values from config files not being passed to env. diff --git a/docs/markdown/migration/1.4_1.5.md b/docs/markdown/migration/1.4_1.5.md index dd74424..a94b435 100644 --- a/docs/markdown/migration/1.4_1.5.md +++ b/docs/markdown/migration/1.4_1.5.md @@ -1,5 +1,13 @@ # Migration from `1.4` to `1.5` +## Config files + +- The config file now required to have a version number. This has to be added with `version: 2` at the root. +- Hooks now optionally support `dir: /some/dir` in the [options object](https://pkg.go.dev/github.com/cupcakearmy/autorestic/internal#Hooks). +- Docker volumes don't get prefixed with `volume:` anymore, rather you have to set the `type: volume` in the [location config](https://pkg.go.dev/github.com/cupcakearmy/autorestic/internal#Hooks). + +See detailed instructions below. + ## Hooks Since `1.5` multiple sources for a location are possible. diff --git a/internal/config.go b/internal/config.go index be7118d..82d4a9b 100644 --- a/internal/config.go +++ b/internal/config.go @@ -26,6 +26,7 @@ type OptionMap map[string][]interface{} type Options map[string]OptionMap type Config struct { + Version string `yaml:"version"` Extras interface{} `yaml:"extras"` Locations map[string]Location `yaml:"locations"` Backends map[string]Backend `yaml:"backends"` @@ -35,7 +36,19 @@ type Config struct { var once sync.Once var config *Config +func exitConfig(err error, msg string) { + if err != nil { + colors.Error.Println(err) + } + if msg != "" { + colors.Error.Println(msg) + } + lock.Unlock() + os.Exit(1) +} + func GetConfig() *Config { + if config == nil { once.Do(func() { if err := viper.ReadInConfig(); err == nil { @@ -53,12 +66,24 @@ func GetConfig() *Config { return } + var versionConfig interface{} + viper.UnmarshalKey("version", &versionConfig) + if versionConfig == nil { + exitConfig(nil, "no version specified in config file. please see docs on how to migrate") + } + version, ok := versionConfig.(int) + if !ok { + exitConfig(nil, "version specified in config file is not an int") + } else { + // Check for version + if version != 2 { + exitConfig(nil, "unsupported version number. please check the docs") + } + } + config = &Config{} if err := viper.UnmarshalExact(config); err != nil { - colors.Error.Println(err) - colors.Error.Println("Could not parse config file!") - lock.Unlock() - os.Exit(1) + exitConfig(err, "Could not parse config file!") } }) }