Skip to content

A live bird collage card for your Home Assistant dashboard.

Trying and catching

ehpersonal3823a1e7a1d44c
diff --git a/homepage/views.php b/homepage/views.php
index 7e8723c5..7a2d34b6 100644
--- a/homepage/views.php
+++ b/homepage/views.php
@@ -4,7 +4,14 @@ $user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
$home = trim($home);
if(!isset($_SESSION['behind'])) {
- $_SESSION['behind'] = trim(shell_exec("sudo -u$user git -C ".$home."/BirdNET-Pi fetch > /dev/null 2>&1 && sudo -u$user git -C ".$home."/BirdNET-Pi status | sed -n '2 p' | cut -d ' ' -f 7"));
+ $fetch = shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi fetch 2>&1");
+ // some kind of error
+ if(strlen($fetch) > 0) {
+ $fetch = shell_exec("sudo git -C ".$home."/BirdNET-Pi fetch 2>&1");
+ $_SESSION['behind'] = trim(shell_exec("sudo git -C ".$home."/BirdNET-Pi status | sed -n '2 p' | cut -d ' ' -f 7"));
+ } else {
+ $_SESSION['behind'] = trim(shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi status | sed -n '2 p' | cut -d ' ' -f 7"));
+ }
}
if(intval($_SESSION['behind']) >= 99) {?>
<style>
diff --git a/scripts/system_controls.php b/scripts/system_controls.php
index 7ba3aefc..76a5a7c0 100644
--- a/scripts/system_controls.php
+++ b/scripts/system_controls.php
@@ -3,7 +3,14 @@ session_start();
$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
$home = trim($home);
-$_SESSION['behind'] = trim(shell_exec("sudo -u$user git -C ".$home."/BirdNET-Pi fetch > /dev/null 2>&1 && sudo -u$user git -C ".$home."/BirdNET-Pi status | sed -n '2 p' | cut -d ' ' -f 7"));
+$fetch = shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi fetch 2>&1");
+// some kind of error
+if(strlen($fetch) > 0) {
+ $fetch = shell_exec("sudo git -C ".$home."/BirdNET-Pi fetch 2>&1");
+ $_SESSION['behind'] = trim(shell_exec("sudo git -C ".$home."/BirdNET-Pi status | sed -n '2 p' | cut -d ' ' -f 7"));
+} else {
+ $_SESSION['behind'] = trim(shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi status | sed -n '2 p' | cut -d ' ' -f 7"));
+}
?><html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<br>