36 lines
1.2 KiB
Plaintext
36 lines
1.2 KiB
Plaintext
|
#!/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", $_);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|