Skip to content

Instantly share code, notes, and snippets.

@vasi
Created January 4, 2015 18:33
Show Gist options
  • Save vasi/ea73895eddca4d64e004 to your computer and use it in GitHub Desktop.
Save vasi/ea73895eddca4d64e004 to your computer and use it in GitHub Desktop.
Allow adding backuppcfs.pl filesystems to fstab
#!/usr/bin/perl
use warnings;
use strict;
use Getopt::Long;
use Data::Dumper;
my $debug = 0;
# Valid options for backuppcfs
my %backuppcfs_opts = map { $_ => 1 } qw(uid user gid group mode foreground
correct-links cache);
# Get the arguments given to this script
my $mount_opts_str = '';
GetOptions('o=s' => \$mount_opts_str);
my $dev = shift @ARGV; # ignore
my $target = shift @ARGV;
# Process mount-type '-o foo,bar=iggy,etc' type options
my (@fuse_opts, @backuppcfs_args);
my @mount_opts = split(',', $mount_opts_str);
foreach my $opt (@mount_opts) {
my ($name, $value) = ($opt =~ /^([^=]+)(?:=(.*)|$)/);
if ($backuppcfs_opts{$name}) {
# Extract backuppcfs arguments from the mount options
push @backuppcfs_args, "--$name", $value;
} else {
# If it's not a backuppcfs arg, it's fuse mount option
push @fuse_opts, $opt;
}
}
# Add the fuse mount options
if (@fuse_opts) {
push @backuppcfs_args, '-o', join(',', @fuse_opts);
}
# Run the filesystem
my $backuppcfs = "/usr/local/bin/backuppcfs.pl";
my @cmd = ($backuppcfs, @backuppcfs_args, $target);
if ($debug) {
unshift @cmd, 'echo';
}
exec(@cmd);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment