doti3/bar/src/mount_point_space.php

50 lines
1 KiB
PHP
Raw Normal View History

2017-06-19 16:36:59 +02:00
#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
2017-12-04 19:41:16 +01:00
$name = $argv[1] ?? 'root';
$mountPoint = $argv[2] ?? '/';
$range1 = $argv[3] ?? 70;
$range2 = $argv[4] ?? 90;
2017-06-19 16:36:59 +02:00
$command = sprintf(
'df -h %s | tail -n 1',
escapeshellcmd($mountPoint)
);
$result = trim(shell_exec($command));
if (empty($result)) {
die;
}
list($dev, $size, $used, $free, $usedP, $point) = explode(' ', preg_replace('/\s+/', ' ', $result));
$percent = intval($usedP);
if ($percent < $range1) {
$color = color('normal');
} elseif ($percent < $range2) {
$color = color('warning');
} else {
$color = color('critical');
}
2017-12-04 19:41:16 +01:00
if (getenv('BLOCK_BUTTON') === '1') {
$command = 'export DISPLAY=:0; pcmanfm '.escapeshellarg('file://'.$mountPoint).'&';
pclose(popen($command, 'r'));
}
2019-01-28 11:13:11 +01:00
$fullText = pspan($mountPoint, '#ccc', '#222').pspan($percent.'%', $color, '#000');
2017-06-19 16:36:59 +02:00
echo block(
2017-12-04 19:41:16 +01:00
'mount_point_space_'.$name,
2017-06-19 16:36:59 +02:00
[
'full_text' => $fullText,
'color' => $color,
2019-01-21 16:20:04 +01:00
'separator' => false,
'separator_block_width' => 0,
2017-06-19 16:36:59 +02:00
]
);