From 591ed32d6066935078bb9a341caaaf6674334239 Mon Sep 17 00:00:00 2001 From: Ewan Croft Date: Fri, 3 Jul 2026 19:59:19 +0100 Subject: [PATCH] Cross-platform host support (Windows, Linux, macOS) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add scripts/sysinfo-watcher.ps1 — PowerShell file watcher for Windows hosts - Add scripts/update-sysinfo.ps1 — PowerShell fastfetch runner for Windows - Add scripts/install.ps1 — PowerShell build + install for Windows - scripts/sysinfo-watcher.sh: platform-aware default SYSINFO_DIR (macOS/Linux) - scripts/update-sysinfo.sh: same, plus better cross-platform error messages - scripts/install.sh: auto-detect OS for plugin dir default, find built JAR by glob --- scripts/install.ps1 | 29 +++++++++++++++++++++++++++++ scripts/install.sh | 21 +++++++++++++++++---- scripts/sysinfo-watcher.ps1 | 32 ++++++++++++++++++++++++++++++++ scripts/sysinfo-watcher.sh | 17 ++++++++++++++--- scripts/update-sysinfo.ps1 | 26 ++++++++++++++++++++++++++ scripts/update-sysinfo.sh | 21 +++++++++++++++++---- 6 files changed, 135 insertions(+), 11 deletions(-) create mode 100644 scripts/install.ps1 create mode 100644 scripts/sysinfo-watcher.ps1 create mode 100644 scripts/update-sysinfo.ps1 diff --git a/scripts/install.ps1 b/scripts/install.ps1 new file mode 100644 index 0000000..b53f8ac --- /dev/null +++ b/scripts/install.ps1 @@ -0,0 +1,29 @@ +# install.ps1 — Build and install the Minefetch plugin into the Minecraft server. +# +# Usage: .\scripts\install.ps1 [[-PluginDir] ] + +param( + [string]$PluginDir = "C:\ProgramData\Minecraft\plugins" +) + +$ProjectDir = Split-Path -Parent $PSScriptRoot + +Write-Host "Building Minefetch..." +Set-Location $ProjectDir +& .\gradlew.bat shadowJar +if ($LASTEXITCODE -ne 0) { + Write-Error "Build failed" + exit 1 +} + +$Jar = Get-ChildItem -Path (Join-Path $ProjectDir "build\libs") -Filter "Minefetch-*-all.jar" | Select-Object -First 1 +if (-not $Jar) { + Write-Error "Build output not found at build\libs\Minefetch-*-all.jar" + exit 1 +} + +Write-Host "Installing to $PluginDir..." +New-Item -ItemType Directory -Force -Path $PluginDir | Out-Null +Copy-Item -Force -Path $Jar.FullName -Destination (Join-Path $PluginDir "Minefetch.jar") + +Write-Host "Done! Minefetch installed. Restart or /reload to enable." diff --git a/scripts/install.sh b/scripts/install.sh index bee4d5f..e37420c 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -2,10 +2,22 @@ # install.sh — Build and install the Minefetch plugin into the Minecraft server. # # Usage: ./scripts/install.sh [server-plugins-dir] +# +# Platform defaults: +# macOS: /Volumes/Storage/Server/MC/data/plugins +# Linux: /opt/minecraft/server/plugins +# Windows: (use install.ps1 instead) set -euo pipefail -PLUGIN_DIR="${1:-/Volumes/Storage/Server/MC/data/plugins}" +case "$(uname -s)" in + Darwin) DEFAULT_PLUGIN_DIR="/Volumes/Storage/Server/MC/data/plugins" ;; + Linux) DEFAULT_PLUGIN_DIR="${MC_PLUGIN_DIR:-/opt/minecraft/server/plugins}" ;; + *) echo "Unsupported OS. For Windows, use: powershell .\scripts\install.ps1" + exit 1 ;; +esac + +PLUGIN_DIR="${1:-$DEFAULT_PLUGIN_DIR}" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" @@ -13,13 +25,14 @@ echo "Building Minefetch..." cd "$PROJECT_DIR" ./gradlew shadowJar -JAR="$PROJECT_DIR/build/libs/Minefetch-1.0.0-all.jar" -if [ ! -f "$JAR" ]; then - echo "Error: Build output not found at $JAR" +JAR=$(ls "$PROJECT_DIR/build/libs/Minefetch-*-all.jar" 2>/dev/null | head -1) +if [ -z "$JAR" ]; then + echo "Error: Build output not found at build/libs/Minefetch-*-all.jar" exit 1 fi echo "Installing to $PLUGIN_DIR..." +mkdir -p "$PLUGIN_DIR" cp "$JAR" "$PLUGIN_DIR/Minefetch.jar" echo "Done! Minefetch installed. Restart or /reload to enable." diff --git a/scripts/sysinfo-watcher.ps1 b/scripts/sysinfo-watcher.ps1 new file mode 100644 index 0000000..e772163 --- /dev/null +++ b/scripts/sysinfo-watcher.ps1 @@ -0,0 +1,32 @@ +# sysinfo-watcher.ps1 — Host-side file watcher for on-demand sysinfo refresh. +# +# Polls the sysinfo directory for a .refresh trigger file. When the Minefetch +# plugin creates one (triggered by a player's /minefetch command), this watcher +# deletes the trigger and regenerates host.json with fresh fastfetch output. +# +# Usage: .\scripts\sysinfo-watcher.ps1 [[-SysinfoDir] ] + +param( + [string]$SysinfoDir = "C:\ProgramData\Minecraft\sysinfo" +) + +$ConfigPath = Join-Path $PSScriptRoot "fastfetch-config.jsonc" +$SysinfoFile = Join-Path $SysinfoDir "host.json" +$TriggerFile = Join-Path $SysinfoDir ".refresh" + +if (-not (Get-Command fastfetch -ErrorAction SilentlyContinue)) { + Write-Error "fastfetch not found. Install it with: scoop install fastfetch or winget install fastfetch" + exit 1 +} + +Write-Host "Watching $SysinfoDir for .refresh triggers..." + +while ($true) { + if (Test-Path $TriggerFile) { + Remove-Item -Force $TriggerFile + $tmpfile = Join-Path $SysinfoDir "host.json.tmp" + & fastfetch --config "$ConfigPath" --format json | Out-File -FilePath $tmpfile -Encoding utf8 + Move-Item -Force -Path $tmpfile -Destination $SysinfoFile + } + Start-Sleep -Milliseconds 500 +} diff --git a/scripts/sysinfo-watcher.sh b/scripts/sysinfo-watcher.sh index 5bf99a6..b57e843 100644 --- a/scripts/sysinfo-watcher.sh +++ b/scripts/sysinfo-watcher.sh @@ -8,18 +8,29 @@ # Usage: # ./scripts/sysinfo-watcher.sh [sysinfo-dir] # -# The default sysinfo dir matches the MC_SYSINFO_DIR default in compose.yml. +# Platform defaults: +# macOS: /Volumes/Storage/Server/MC/sysinfo +# Linux: /var/opt/minecraft/sysinfo +# Windows: .\scripts\sysinfo-watcher.ps1 set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -SYSINFO_DIR="${1:-/Volumes/Storage/Server/MC/sysinfo}" + +case "$(uname -s)" in + Darwin) DEFAULT_SYSINFO_DIR="/Volumes/Storage/Server/MC/sysinfo" ;; + Linux) DEFAULT_SYSINFO_DIR="${MC_SYSINFO_DIR:-/var/opt/minecraft/sysinfo}" ;; + *) echo "Unsupported OS. For Windows, use: powershell .\scripts\sysinfo-watcher.ps1" + exit 1 ;; +esac + +SYSINFO_DIR="${1:-$DEFAULT_SYSINFO_DIR}" SYSINFO_FILE="$SYSINFO_DIR/host.json" TRIGGER_FILE="$SYSINFO_DIR/.refresh" FASTFETCH_CONFIG="${MC_SYSINFO_CONFIG:-$SCRIPT_DIR/fastfetch-config.jsonc}" if ! command -v fastfetch &> /dev/null; then - echo "Error: fastfetch not found. Install it with: brew install fastfetch" + echo "Error: fastfetch not found. Install it with: brew install fastfetch (macOS) or sudo apt install fastfetch (Linux)" exit 1 fi diff --git a/scripts/update-sysinfo.ps1 b/scripts/update-sysinfo.ps1 new file mode 100644 index 0000000..507d68d --- /dev/null +++ b/scripts/update-sysinfo.ps1 @@ -0,0 +1,26 @@ +# update-sysinfo.ps1 — Capture host fastfetch output for the Minefetch plugin. +# +# Usage: .\scripts\update-sysinfo.ps1 [[-SysinfoDir] ] +# +# The output is written to a shared directory that gets mounted into the +# Minecraft container at /sysinfo/host.json. + +param( + [string]$SysinfoDir = "C:\ProgramData\Minecraft\sysinfo" +) + +$ConfigPath = Join-Path $PSScriptRoot "fastfetch-config.jsonc" +$SysinfoFile = Join-Path $SysinfoDir "host.json" + +if (-not (Get-Command fastfetch -ErrorAction SilentlyContinue)) { + Write-Error "fastfetch not found. Install it with: scoop install fastfetch or winget install fastfetch" + exit 1 +} + +New-Item -ItemType Directory -Force -Path $SysinfoDir | Out-Null +$tmpfile = Join-Path $SysinfoDir "host.json.tmp" + +& fastfetch --config "$ConfigPath" --format json | Out-File -FilePath $tmpfile -Encoding utf8 +Move-Item -Force -Path $tmpfile -Destination $SysinfoFile + +Write-Host "Written to $SysinfoFile" diff --git a/scripts/update-sysinfo.sh b/scripts/update-sysinfo.sh index e3f2caf..03e474f 100644 --- a/scripts/update-sysinfo.sh +++ b/scripts/update-sysinfo.sh @@ -1,10 +1,15 @@ #!/bin/bash # update-sysinfo.sh — Capture host fastfetch output for the Minefetch plugin. # -# Run this periodically (or set up a LaunchAgent) to refresh the system info +# Run this periodically (or set up a scheduled task) to refresh the system info # that the /minefetch in-game command displays. # -# Usage: ./scripts/update-sysinfo.sh +# Usage: ./scripts/update-sysinfo.sh [sysinfo-dir] [config-path] +# +# Platform defaults: +# macOS: /Volumes/Storage/Server/MC/sysinfo +# Linux: /var/opt/minecraft/sysinfo +# Windows: .\scripts\update-sysinfo.ps1 # # The output is written to a shared directory that gets mounted into the # Minecraft container at /sysinfo/host.json. @@ -12,14 +17,22 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -SYSINFO_DIR="${1:-/Volumes/Storage/Server/MC/sysinfo}" + +case "$(uname -s)" in + Darwin) DEFAULT_SYSINFO_DIR="/Volumes/Storage/Server/MC/sysinfo" ;; + Linux) DEFAULT_SYSINFO_DIR="${MC_SYSINFO_DIR:-/var/opt/minecraft/sysinfo}" ;; + *) echo "Unsupported OS. For Windows, use: powershell .\scripts\update-sysinfo.ps1" + exit 1 ;; +esac + +SYSINFO_DIR="${1:-$DEFAULT_SYSINFO_DIR}" SYSINFO_FILE="$SYSINFO_DIR/host.json" FASTFETCH_CONFIG="${2:-$SCRIPT_DIR/fastfetch-config.jsonc}" mkdir -p "$SYSINFO_DIR" if ! command -v fastfetch &> /dev/null; then - echo "Error: fastfetch not found. Install it with: brew install fastfetch" + echo "Error: fastfetch not found. Install it with: brew install fastfetch (macOS) or sudo apt install fastfetch (Linux)" exit 1 fi -- 2.51.2