Add config option for cache home directory

This commit is contained in:
Martin Puppe 2020-09-14 20:53:55 +02:00
parent 43fff22a2a
commit e4ddf36695

View file

@ -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)