summaryrefslogtreecommitdiffstats
path: root/lib/App/BorgRestore/Settings.pm
blob: 2aa24ad054d56d2557236a990dbe9ba9c64c07bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package App::BorgRestore::Settings;
use v5.10;
use strict;
use warnings;

use App::BorgRestore::Helper;

use File::Path qw(mkpath);
use Sys::Hostname;

our $borg_repo = "backup:borg-".hostname;
our $cache_path_base = sprintf("%s/borg-restore.pl", $ENV{XDG_CACHE_HOME} // $ENV{HOME}."/.cache");
our @backup_prefixes = (
	{regex => "^/", replacement => ""},
);

my @configfiles = (
	sprintf("%s/borg-restore.cfg", $ENV{XDG_CONFIG_HOME} // $ENV{HOME}."/.config"),
	"/etc/borg-restore.cfg",
);

for my $configfile (@configfiles) {
	$configfile = App::BorgRestore::Helper::untaint($configfile, qr/.*/);
	if (-e $configfile) {
		unless (my $return = do $configfile) {
			die "couldn't parse $configfile: $@" if $@;
			die "couldn't do $configfile: $!"    unless defined $return;
			die "couldn't run $configfile"       unless $return;
		}
	}
}
$cache_path_base = App::BorgRestore::Helper::untaint($cache_path_base, qr/.*/);

# ensure the cache directory exists
mkpath(get_cache_dir(), {mode => oct(700)});

sub get_cache_dir {
	return "$cache_path_base/v2";
}

sub get_cache_path {
	my $item = shift;
	return get_cache_dir()."/$item";
}

sub get_db_path {
	return get_cache_path('archives.db');
}


1;

__END__