#!/bin/sh # RPCD backend for Metabolizer CMS LuCI app . /lib/functions.sh # Helpers json_output() { echo "$1" } get_status() { local enabled running cms_running post_count draft_count local gitea_connected hexo_running # Check metabolizer enabled enabled=$(uci -q get metabolizer.main.enabled || echo "0") # Check Streamlit CMS app if pgrep -f "streamlit.*metabolizer" >/dev/null 2>&1; then cms_running="true" else cms_running="false" fi # Check Hexo if lxc-info -n hexojs -s 2>/dev/null | grep -q "RUNNING"; then hexo_running="true" else hexo_running="false" fi # Check Gitea if lxc-info -n gitea -s 2>/dev/null | grep -q "RUNNING"; then gitea_connected="true" else gitea_connected="false" fi # Count posts/drafts local content_path=$(uci -q get metabolizer.content.repo_path || echo "/srv/metabolizer/content") post_count=0 draft_count=0 if [ -d "$content_path/_posts" ]; then post_count=$(ls -1 "$content_path/_posts/"*.md 2>/dev/null | wc -l) fi if [ -d "$content_path/_drafts" ]; then draft_count=$(ls -1 "$content_path/_drafts/"*.md 2>/dev/null | wc -l) fi cat </dev/null | sed 's/^title:[[:space:]]*//' | tr -d '"' | tr -d "'") local date=$(grep -m1 "^date:" "$f" 2>/dev/null | sed 's/^date:[[:space:]]*//') [ "$first" = "1" ] || echo "," first=0 echo " {\"slug\": \"$slug\", \"title\": \"$title\", \"date\": \"$date\"}" done fi echo "]" } gitea_status() { local content_path=$(uci -q get metabolizer.content.repo_path || echo "/srv/metabolizer/content") local has_repo="false" local last_sync="" local branch="" if [ -d "$content_path/.git" ]; then has_repo="true" cd "$content_path" last_sync=$(git log -1 --format="%ci" 2>/dev/null || echo "never") branch=$(git branch --show-current 2>/dev/null || echo "unknown") fi cat <&1 echo '{"status": "ok"}' } do_build() { metabolizerctl build 2>&1 echo '{"status": "ok"}' } do_publish() { metabolizerctl publish 2>&1 echo '{"status": "ok"}' } do_gitea_sync() { hexoctl gitea sync 2>&1 echo '{"status": "ok"}' } # RPCD interface case "$1" in list) cat <