From 90cdc088edff3ef3260cb83a130c8b99ebe6ec45 Mon Sep 17 00:00:00 2001 From: hjp Date: Sat, 13 Oct 2018 08:01:58 +0000 Subject: [PATCH] Add script to mount all backups I had a simple zsh script before, but with LUKS support that would have become more complex, so I just copied the relevant code from the backup script. --- Build.PL | 5 +++-- MYMETA.json | 5 +++-- MYMETA.yml | 3 ++- scripts/mount-all-backups | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 5 deletions(-) create mode 100755 scripts/mount-all-backups diff --git a/Build.PL b/Build.PL index bfe6be9..9e1611f 100644 --- a/Build.PL +++ b/Build.PL @@ -14,10 +14,11 @@ my $build = Module::Build->new 'Config::YAML' => 0, }, script_files => [ - 'scripts/da', 'scripts/backup', - 'scripts/simba_export', + 'scripts/da', + 'scripts/mount-all-backups', 'scripts/remove_session', + 'scripts/simba_export', ], ); $build->create_build_script; diff --git a/MYMETA.json b/MYMETA.json index eddcb05..b795006 100644 --- a/MYMETA.json +++ b/MYMETA.json @@ -4,7 +4,7 @@ "unknown" ], "dynamic_config" : 0, - "generated_by" : "Module::Build version 0.421", + "generated_by" : "Module::Build version 0.422", "license" : [ "perl_5" ], @@ -49,5 +49,6 @@ "http://dev.perl.org/licenses/" ] }, - "version" : "0.002" + "version" : "0.002", + "x_serialization_backend" : "JSON::PP version 2.27300_01" } diff --git a/MYMETA.yml b/MYMETA.yml index c6837f7..9aed85b 100644 --- a/MYMETA.yml +++ b/MYMETA.yml @@ -4,7 +4,7 @@ author: - unknown build_requires: {} dynamic_config: 0 -generated_by: 'Module::Build version 0.421, CPAN::Meta::Converter version 2.142690' +generated_by: 'Module::Build version 0.422, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html @@ -31,3 +31,4 @@ requires: resources: license: http://dev.perl.org/licenses/ version: '0.002' +x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff --git a/scripts/mount-all-backups b/scripts/mount-all-backups new file mode 100755 index 0000000..c4b7516 --- /dev/null +++ b/scripts/mount-all-backups @@ -0,0 +1,35 @@ +#!/usr/bin/perl +use warnings; +use strict; +use v5.10; +use File::stat; + +my $st = stat("/backup/"); +my $base_device = $st->dev; +my %luks_devices; +for (glob("/backup/*")) { + my $st = stat($_); + my $dir_device = $st->dev; + say STDERR ("checking $_"); + if ($base_device == $dir_device) { + # not a mount point + (my $basedir = $_) =~ s{^/backup/}{}; + if ($basedir =~ /^luks-(.*)/) { + my $key = $1; + for my $dev (glob("/dev/disk/by-id/*$key*")) { + my ($devbase) = $dev =~ m{([^/]+$)}; + if (-e "/backup/keys/$devbase") { + say STDERR ("opening /dev/disk/by-id/$devbase on $_"); + system("/sbin/cryptsetup", "open", $dev, $basedir, "--key-file", "/backup/keys/$devbase"); + say STDERR ("mounting /dev/mapper/$basedir on $_"); + system("/bin/mount", "-o", "nodev,noexec,nomand,nosuid", "/dev/mapper/$basedir", $_); + } + } + } elsif (-e "/dev/disk/by-id/$basedir") { + # matching device exists + say STDERR ("mounting /dev/disk/by-id/$basedir on $_"); + system("/bin/mount", "-o", "nodev,noexec,nomand,nosuid", "/dev/disk/by-id/$basedir", $_); + } + } +} +