furt/scripts/start.sh
michael 78e8dedf8e fix(json): add multi-platform JSON library compatibility
- Add flexible JSON detection (cjson preferred, dkjson fallback)
- Update main.lua and mail.lua with found_cjson detection
- Update start.sh to check both JSON libraries
- Enables furt to run on Arch Linux without manual patches
- Maintains API compatibility with existing cjson usage

Fixes #108
2025-09-05 17:44:42 +02:00

84 lines
2.2 KiB
Bash
Executable file

#!/bin/sh
# furt-lua/scripts/start.sh - Bereinigt ohne obsoletes Environment-System
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
echo -e "${GREEN}=== Furt Lua HTTP-Server Startup ===${NC}"
# User can override this manually if needed:
LUA_COMMAND=""
# Config check first (like old .env check)
if [ "$(uname)" = "OpenBSD" ] || [ "$(uname)" = "FreeBSD" ]; then
CONFIG_FILE="/usr/local/etc/furt/furt.conf"
else
CONFIG_FILE="/etc/furt/furt.conf"
fi
if [ ! -f "$CONFIG_FILE" ] && [ ! -f "$PROJECT_DIR/config/furt.conf" ]; then
echo -e "${RED}Error: furt.conf not found${NC}"
echo "Create config first in $CONFIG_FILE or $PROJECT_DIR/config/furt.conf"
exit 1
fi
if [ -z "$LUA_COMMAND" ]; then
# Test standard distribution paths
for cmd in lua51 lua5.1; do
if command -v "$cmd" >/dev/null 2>&1; then
LUA_COMMAND="$cmd"
break
fi
done
fi
if [ -z "$LUA_COMMAND" ]; then
echo -e "${RED}Error: No Lua 5.1 found${NC}"
echo "Install options:"
echo " Arch: pacman -S lua51"
echo " OpenBSD: pkg_add lua51"
echo " Debian: apt install lua5.1"
echo " FreeBSD: pkg install lua51"
echo ""
echo "Or set: LUA_COMMAND=/custom/path/lua51 at top of this script"
exit 1
fi
echo -e "${GREEN}Found Lua:${NC} $LUA_COMMAND"
# Dependency checks (lua-socket, lua-cjson)
$LUA_COMMAND -e "require('socket')" 2>/dev/null || {
echo -e "${RED}Error: lua-socket not found${NC}"
exit 1
}
# JSON library check (cjson preferred, dkjson fallback)
if ! ($LUA_COMMAND -e "require('cjson')" 2>/dev/null || $LUA_COMMAND -e "require('dkjson')" 2>/dev/null); then
echo -e "${RED}Error: No JSON library found${NC}"
echo "Install lua-cjson or lua-dkjson"
exit 1
fi
cd "$PROJECT_DIR"
echo -e "${GREEN}Starting Furt...${NC}"
# Service vs Interactive Detection
if [ ! -t 0 ] || [ ! -t 1 ]; then
# Service mode - Background
"$LUA_COMMAND" src/main.lua &
else
# Interactive mode - Foreground
exec "$LUA_COMMAND" src/main.lua
fi
# Furt liest selbst seine Config aus furt.conf
#exec "$LUA_COMMAND" src/main.lua