From e4ddf366956b8d6fd3bc4aef629be2438fc44509 Mon Sep 17 00:00:00 2001 From: Martin Puppe Date: Mon, 14 Sep 2020 20:53:55 +0200 Subject: [PATCH] Add config option for cache home directory --- mpbackup | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mpbackup b/mpbackup index 0613d7d..efded99 100644 --- a/mpbackup +++ b/mpbackup @@ -8,6 +8,8 @@ DEFAULT_CONFIG_FILE = Pathname.new('/etc/mpbackup/config.yaml') NAME = 'mpbackup' VERSION = '0.4.0' +$original_cache_home = ENV['XDG_CACHE_HOME'] + def set_restic_vars(config) if config['repository-file'] puts "Reading repository from file #{config['repository-file']} …" @@ -23,6 +25,10 @@ def set_restic_vars(config) else password = STDIN.getpass('Please put in your restic password: ') end + if config['cache-home'] + puts "Setting XDG_CACHE_HOME to #{config['cache-home']} …" + ENV['XDG_CACHE_HOME'] = config['cache-home'] + end ENV['RESTIC_REPOSITORY'] = repo ENV['RESTIC_PASSWORD'] = password @@ -31,6 +37,11 @@ end def unset_restic_vars ENV.delete('RESTIC_REPOSITORY') ENV.delete('RESTIC_PASSWORD') + if $original_cache_home + ENV['XDG_CACHE_HOME'] = $original_cache_home + else + ENV.delete('XDG_CACHE_HOME') + end end def error(exit_status, message)