From 3b45fc21efb0bf4ea62d31cbb3adcf3b68594281 Mon Sep 17 00:00:00 2001 From: MickLesk Date: Mon, 22 Jun 2026 21:39:17 +0200 Subject: [PATCH] fix(librenms): run daily.sh as librenms user with git available Install git, initialize git metadata for tarball deployments, and execute daily.sh via su so updates no longer fail with permission or missing git. --- ct/librenms.sh | 17 ++++++++++++++--- install/librenms-install.sh | 11 +++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ct/librenms.sh b/ct/librenms.sh index e5dd91fc9..7404dd93e 100644 --- a/ct/librenms.sh +++ b/ct/librenms.sh @@ -29,10 +29,21 @@ function update_script() { exit fi setup_mariadb + ensure_dependencies git + if [[ ! -d /opt/librenms/.git ]]; then + msg_info "Initializing LibreNMS git metadata" + LIBRENMS_VERSION=$(cat ~/.librenms 2>/dev/null) + cd /opt/librenms + git init -q + git remote add origin https://github.com/librenms/librenms.git + git fetch --depth 1 origin "refs/tags/v${LIBRENMS_VERSION}" 2>/dev/null || + git fetch --depth 1 origin "refs/tags/${LIBRENMS_VERSION}" 2>/dev/null || true + git checkout -qf FETCH_HEAD 2>/dev/null || true + chown -R librenms:librenms .git + msg_ok "Initialized LibreNMS git metadata" + fi msg_info "Updating LibreNMS" - su librenms - cd /opt/librenms - ./daily.sh + $STD su - librenms -s /bin/bash -c 'cd /opt/librenms && ./daily.sh' msg_ok "Updated LibreNMS" exit } diff --git a/install/librenms-install.sh b/install/librenms-install.sh index 9fa2a0f27..b50472227 100644 --- a/install/librenms-install.sh +++ b/install/librenms-install.sh @@ -17,6 +17,7 @@ msg_info "Installing Dependencies" $STD apt install -y \ acl \ fping \ + git \ graphviz \ imagemagick \ mtr-tiny \ @@ -64,6 +65,16 @@ EOF chown -R librenms:librenms /opt/librenms chmod 771 /opt/librenms chmod -R ug=rwX /opt/librenms/bootstrap/cache /opt/librenms/storage /opt/librenms/logs /opt/librenms/rrd +if [[ ! -d /opt/librenms/.git ]]; then + LIBRENMS_VERSION=$(cat ~/.librenms 2>/dev/null) + cd /opt/librenms + git init -q + git remote add origin https://github.com/librenms/librenms.git + git fetch --depth 1 origin "refs/tags/v${LIBRENMS_VERSION}" 2>/dev/null || + git fetch --depth 1 origin "refs/tags/${LIBRENMS_VERSION}" 2>/dev/null || true + git checkout -qf FETCH_HEAD 2>/dev/null || true + chown -R librenms:librenms .git +fi msg_ok "Configured LibreNMS" msg_info "Configure MariaDB"