PHP shims: derive paths from __DIR__ (PHP-FPM runs as caddy user)
BirdNET-Pi's installer runs PHP-FPM as the caddy user, so getenv('HOME')
resolves to /var/lib/caddy - not the install user's home. Every path
constructed from getenv('HOME') was broken on first install.
PHP resolves __DIR__ through the install_services.sh symlink to the
realpath ($HOME/BirdNET-Pi/avian/api), so dirname(__DIR__, 2) = the
BirdNET-Pi install root and dirname(__DIR__, 3) = the user's home.
Works under any username because nothing is hardcoded.
Also fixed birdnet-api.php's DB_PATH which walked one level too far
(used , 3) - the BirdNET-Pi root is , 2).
This commit is contained in:
@@ -31,7 +31,7 @@ if ($sci !== '' && !preg_match('/^[A-Za-z]{2,40}(?:[ ][a-z]{2,40}){1,3}$/', $sci
|
||||
exit;
|
||||
}
|
||||
|
||||
$BY_DATE = getenv('HOME') . '/BirdSongs/Extracted/By_Date';
|
||||
$BY_DATE = dirname(__DIR__, 3) . '/BirdSongs/Extracted/By_Date';
|
||||
|
||||
// ---- Direct-by-file lookup ----
|
||||
// BirdNET-Pi writes <base>.mp3 and <base>.png next to each other under
|
||||
@@ -93,7 +93,7 @@ if ($file !== '') {
|
||||
}
|
||||
|
||||
function resolve_common(string $sci): ?string {
|
||||
$f = getenv('HOME') . '/BirdNET-Pi/scripts/birds.json';
|
||||
$f = dirname(__DIR__, 3) . '/BirdNET-Pi/scripts/birds.json';
|
||||
if (is_readable($f)) {
|
||||
$list = json_decode((string)file_get_contents($f), true);
|
||||
if (is_array($list)) {
|
||||
@@ -107,7 +107,7 @@ function resolve_common(string $sci): ?string {
|
||||
}
|
||||
}
|
||||
}
|
||||
$labels = getenv('HOME') . '/BirdNET-Pi/model/labels.txt';
|
||||
$labels = dirname(__DIR__, 3) . '/BirdNET-Pi/model/labels.txt';
|
||||
if (is_readable($labels)) {
|
||||
foreach (file($labels, FILE_IGNORE_NEW_LINES) as $line) {
|
||||
if (strpos($line, '_') !== false) {
|
||||
|
||||
Reference in New Issue
Block a user