Skip to content

Instantly share code, notes, and snippets.

@subzero79
Last active October 17, 2017 01:47
Show Gist options
  • Save subzero79/184d1fac99fd6627236765655275a06c to your computer and use it in GitHub Desktop.
Save subzero79/184d1fac99fd6627236765655275a06c to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
/**
* Copyright (C) 2016-2017 OpenMediaVault Plugin Developers.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once '/usr/share/php/openmediavault/autoloader.inc';
require_once '/usr/share/php/openmediavault/globals.inc';
use OMV\Rpc\Rpc;
$context = ['username' => 'admin', 'role' => OMV_ROLE_ADMINISTRATOR];
$objects = Rpc::call('UnionFilesystems', 'getList', ['start' => 0, 'limit' => null], $context, Rpc::MODE_REMOTE);
foreach ($objects['data'] as $object) {
$mntent = Rpc::call('FsTab', 'get', ['uuid' => $object['self-mntentref']], $context, Rpc::MODE_REMOTE);
$mountPoint = $mntent['dir'];
$options = !empty($object['options']) ? explode(',', $object['options']) : [];
$options[] = 'category.create=' . $object['create-policy'];
$options[] = 'minfreespace=' . $object['min-free-space'];
$fs_members=array();
foreach($object['mntentref'] as $fs_uuid ) {
$mntent = Rpc::call('FsTab', 'get', ['uuid' => $fs_uuid ], $context, Rpc::MODE_REMOTE);
$tmp = array(
"dir" => $mntent['dir'],
"type" => $mntent['type']
);
array_push($fs_members, $tmp);
}
foreach ($fs_members as $fs_member) {
if ($fs_member['type'] != "zfs") {
$cmd = "systemd-escape --path --suffix=mount " . $fs_member['dir'];
$options[] = "x-systemd.requires=" . exec($cmd);
}
}
if (in_array('zfs', array_column($fs_members, 'type'))) {
$options[] = "x-systemd.requires=zfs-mount.service";
}
$rowData = sprintf(
'%s %s fuse.mergerfs %s 0 0',
implode(':', array_column($fs_members, 'dir')),
$mountPoint,
implode(',', $options)
);
echo $rowData . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment