diff --git a/README.md b/README.md index d107177..ccad001 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,41 @@ U-Navigator ist als Unraid-Plugin machbar. Empfohlen wird ein hybrider Aufbau au Naechster sinnvoller Schritt: -Unraid-Plugin-Paketierung fuer die bestehende Web-App und das Backend. +Go-Backend oder gebuendelte Runtime, damit das Plugin nicht mehr von einer vorhandenen Node.js-Installation abhaengt. + +## Unraid Plugin installieren + +Plugin-URL: + +```text +https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/u-navigator.plg +``` + +Installation per Unraid Terminal: + +```sh +installplg https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/u-navigator.plg +``` + +Oder im WebGUI: + +```text +Plugins -> Install Plugin -> URL einfuegen -> Install +``` + +Danach starten: + +```sh +rc.u-navigator start +``` + +Status pruefen: + +```sh +rc.u-navigator status +``` + +Wichtig: Dieser erste Plugin-Spike benoetigt `node` auf dem Unraid-System. Falls `rc.u-navigator start` meldet, dass Node.js fehlt, muss als naechster Schritt das Backend als Go-Binary gebaut oder Node.js separat bereitgestellt werden. ## Lokal starten diff --git a/build-plugin.sh b/build-plugin.sh new file mode 100755 index 0000000..06004de --- /dev/null +++ b/build-plugin.sh @@ -0,0 +1,27 @@ +#!/bin/sh +set -eu + +PLUGIN="u-navigator" +VERSION="0.1.0" +PKG_DIR="packages" +WORK_DIR=".plugin-build" +PKG_NAME="${PLUGIN}-${VERSION}.tgz" + +rm -rf "$WORK_DIR" +mkdir -p "$WORK_DIR/usr/local/emhttp/plugins/${PLUGIN}/app" "$PKG_DIR" + +cp -R plugin-root/usr "$WORK_DIR/" +cp package.json "$WORK_DIR/usr/local/emhttp/plugins/${PLUGIN}/app/" +cp -R public "$WORK_DIR/usr/local/emhttp/plugins/${PLUGIN}/app/" +cp -R server "$WORK_DIR/usr/local/emhttp/plugins/${PLUGIN}/app/" +find "$WORK_DIR" -name "*.test.js" -delete +chmod +x "$WORK_DIR/usr/local/emhttp/plugins/${PLUGIN}/scripts/rc.u-navigator" + +tar -czf "$PKG_DIR/$PKG_NAME" -C "$WORK_DIR" usr +rm -rf "$WORK_DIR" + +MD5="$(md5 -q "$PKG_DIR/$PKG_NAME" 2>/dev/null || md5sum "$PKG_DIR/$PKG_NAME" | awk '{print $1}')" +sed "s/__VERSION__/${VERSION}/g; s/__MD5__/${MD5}/g" u-navigator.plg.in > u-navigator.plg + +echo "Built $PKG_DIR/$PKG_NAME" +echo "MD5 $MD5" diff --git a/packages/u-navigator-0.1.0.tgz b/packages/u-navigator-0.1.0.tgz new file mode 100644 index 0000000..963e76d Binary files /dev/null and b/packages/u-navigator-0.1.0.tgz differ diff --git a/plugin-root/usr/local/emhttp/plugins/u-navigator/U-Navigator.page b/plugin-root/usr/local/emhttp/plugins/u-navigator/U-Navigator.page new file mode 100644 index 0000000..c4293d0 --- /dev/null +++ b/plugin-root/usr/local/emhttp/plugins/u-navigator/U-Navigator.page @@ -0,0 +1,39 @@ +Menu="Tools" +Title="U-Navigator" +Icon="folder-open" +--- + + +
+

+ U-Navigator laeuft als lokaler Dienst auf Port . + Falls der Rahmen leer bleibt, pruefe den Dienst mit rc.u-navigator status. +

+ +
+ diff --git a/plugin-root/usr/local/emhttp/plugins/u-navigator/scripts/rc.u-navigator b/plugin-root/usr/local/emhttp/plugins/u-navigator/scripts/rc.u-navigator new file mode 100644 index 0000000..91996bd --- /dev/null +++ b/plugin-root/usr/local/emhttp/plugins/u-navigator/scripts/rc.u-navigator @@ -0,0 +1,62 @@ +#!/bin/bash + +PLUGIN="u-navigator" +APP_DIR="/usr/local/emhttp/plugins/${PLUGIN}/app" +PID_FILE="/var/run/${PLUGIN}.pid" +LOG_FILE="/var/log/${PLUGIN}.log" +PORT="${U_NAV_PORT:-8088}" +ROOTS="${U_NAV_ROOTS:-/mnt/user}" +HOST="${U_NAV_HOST:-0.0.0.0}" + +is_running() { + [[ -f "$PID_FILE" ]] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null +} + +start() { + if is_running; then + echo "${PLUGIN} is already running with PID $(cat "$PID_FILE")" + return 0 + fi + + if ! command -v node >/dev/null 2>&1; then + echo "node is required but was not found. Install/provide Node.js before starting ${PLUGIN}." + return 1 + fi + + mkdir -p "$(dirname "$PID_FILE")" + U_NAV_ROOTS="$ROOTS" U_NAV_HOST="$HOST" PORT="$PORT" nohup node "${APP_DIR}/server/server.js" >>"$LOG_FILE" 2>&1 & + echo $! > "$PID_FILE" + echo "${PLUGIN} started on ${HOST}:${PORT} with roots ${ROOTS}" +} + +stop() { + if ! is_running; then + rm -f "$PID_FILE" + echo "${PLUGIN} is not running" + return 0 + fi + + kill "$(cat "$PID_FILE")" 2>/dev/null || true + rm -f "$PID_FILE" + echo "${PLUGIN} stopped" +} + +status() { + if is_running; then + echo "${PLUGIN} is running with PID $(cat "$PID_FILE")" + else + echo "${PLUGIN} is not running" + return 1 + fi +} + +case "$1" in + start) start ;; + stop) stop ;; + restart) stop; start ;; + status) status ;; + *) + echo "Usage: $0 {start|stop|restart|status}" + exit 2 + ;; +esac diff --git a/server/server.js b/server/server.js index 480db9b..6956997 100644 --- a/server/server.js +++ b/server/server.js @@ -226,9 +226,10 @@ function statusError(status, message) { if (import.meta.url === `file://${process.argv[1]}`) { const port = Number(process.env.PORT || 8088); + const host = process.env.U_NAV_HOST || process.env.HOST || '127.0.0.1'; createApp({ env: process.env }).then((app) => { - http.createServer(app).listen(port, '127.0.0.1', () => { - console.log(`U-Navigator listening on http://127.0.0.1:${port}`); + http.createServer(app).listen(port, host, () => { + console.log(`U-Navigator listening on http://${host}:${port}`); }); }).catch((error) => { console.error(error.message); diff --git a/u-navigator.plg b/u-navigator.plg new file mode 100644 index 0000000..0a71860 --- /dev/null +++ b/u-navigator.plg @@ -0,0 +1,51 @@ + + + + +]> + + + +### &version; +- Initial U-Navigator plugin spike. +- Installs WebGUI page, Node.js prototype backend, in-app window manager and drag-and-drop file navigator. + + + +https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/packages/&package; +9d6e248cb70c803f04bf491b06520764 + + + + +mkdir -p /boot/config/plugins/&name; +tar -xzf /boot/config/plugins/&name;/&package; -C / +chmod +x /usr/local/emhttp/plugins/&name;/scripts/rc.u-navigator +ln -sf /usr/local/emhttp/plugins/&name;/scripts/rc.u-navigator /usr/local/sbin/rc.u-navigator +echo "" +echo "-----------------------------------------------------------" +echo " &name; &version; has been installed." +echo "" +echo " Start: rc.u-navigator start" +echo " Stop: rc.u-navigator stop" +echo " Status: rc.u-navigator status" +echo "" +echo " Note: This prototype requires Node.js to be available on Unraid." +echo "-----------------------------------------------------------" +echo "" + + + + + +rc.u-navigator stop 2>/dev/null || true +rm -f /usr/local/sbin/rc.u-navigator +rm -rf /usr/local/emhttp/plugins/&name; +rm -rf /boot/config/plugins/&name; +rm -f /var/run/&name;.pid +echo "&name; has been removed." + + + + diff --git a/u-navigator.plg.in b/u-navigator.plg.in new file mode 100644 index 0000000..bf3dce8 --- /dev/null +++ b/u-navigator.plg.in @@ -0,0 +1,51 @@ + + + + +]> + + + +### &version; +- Initial U-Navigator plugin spike. +- Installs WebGUI page, Node.js prototype backend, in-app window manager and drag-and-drop file navigator. + + + +https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/packages/&package; +__MD5__ + + + + +mkdir -p /boot/config/plugins/&name; +tar -xzf /boot/config/plugins/&name;/&package; -C / +chmod +x /usr/local/emhttp/plugins/&name;/scripts/rc.u-navigator +ln -sf /usr/local/emhttp/plugins/&name;/scripts/rc.u-navigator /usr/local/sbin/rc.u-navigator +echo "" +echo "-----------------------------------------------------------" +echo " &name; &version; has been installed." +echo "" +echo " Start: rc.u-navigator start" +echo " Stop: rc.u-navigator stop" +echo " Status: rc.u-navigator status" +echo "" +echo " Note: This prototype requires Node.js to be available on Unraid." +echo "-----------------------------------------------------------" +echo "" + + + + + +rc.u-navigator stop 2>/dev/null || true +rm -f /usr/local/sbin/rc.u-navigator +rm -rf /usr/local/emhttp/plugins/&name; +rm -rf /boot/config/plugins/&name; +rm -f /var/run/&name;.pid +echo "&name; has been removed." + + + +