Files
kitty-web/install.sh
T

93 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
# kitty-web installer
# Mobile-first web terminal with tmux, ttyd, and push notifications
set -e
TTYD_VERSION="1.7.7"
SERVICE_USER="${KITTY_USER:-rdp}"
TTYD_PORT="${TTYD_PORT:-7681}"
NOTIFY_PORT="${NOTIFY_PORT:-7682}"
FONT_SIZE="${FONT_SIZE:-18}"
echo "=== kitty-web installer ==="
echo "Service user: $SERVICE_USER"
echo "ttyd port: $TTYD_PORT"
echo "Notify port: $NOTIFY_PORT"
# Check root
if [ "$EUID" -ne 0 ]; then
echo "Run as root"
exit 1
fi
# Install dependencies
echo "[1/6] Installing dependencies..."
apt install -y tmux 2>/dev/null || true
# Install ttyd
if ! command -v ttyd &>/dev/null; then
echo "[2/6] Installing ttyd $TTYD_VERSION..."
curl -sL "https://github.com/tsl0922/ttyd/releases/latest/download/ttyd.x86_64" -o /usr/local/bin/ttyd
chmod +x /usr/local/bin/ttyd
else
echo "[2/6] ttyd already installed"
fi
# Create user if needed
if ! id "$SERVICE_USER" &>/dev/null; then
echo "[3/6] Creating user $SERVICE_USER..."
useradd -m -s /bin/bash "$SERVICE_USER"
else
echo "[3/6] User $SERVICE_USER exists"
fi
# Deploy files
echo "[4/6] Deploying files..."
mkdir -p /opt/kitty-web/static
# Build custom index (inject toolbar into ttyd's default page)
TMPINDEX=$(mktemp)
ttyd --port 0 /bin/true &
TTYD_PID=$!
sleep 1
# Can't easily grab default page without a running instance, so we'll
# add toolbar.js loading to the page at runtime via the notify server
kill $TTYD_PID 2>/dev/null || true
cp "$(dirname "$0")/toolbar.js" /opt/kitty-web/static/toolbar.js
cp "$(dirname "$0")/manifest.json" /opt/kitty-web/static/manifest.json
cp "$(dirname "$0")/icon-192.png" /opt/kitty-web/static/icon-192.png 2>/dev/null || true
cp "$(dirname "$0")/icon-512.png" /opt/kitty-web/static/icon-512.png 2>/dev/null || true
cp "$(dirname "$0")/notify-server.py" /opt/kitty-web/notify-server.py
chmod +x /opt/kitty-web/notify-server.py
# Install kitty-notify command
cp "$(dirname "$0")/kitty-notify" /usr/local/bin/kitty-notify
chmod +x /usr/local/bin/kitty-notify
# Install tmux config
sudo -u "$SERVICE_USER" cp "$(dirname "$0")/config/tmux.conf" "$(eval echo ~$SERVICE_USER)/.tmux.conf" 2>/dev/null || true
# Install systemd services
echo "[5/6] Installing services..."
sed "s/User=rdp/User=$SERVICE_USER/g; s/Group=rdp/Group=$SERVICE_USER/g; s/--port 7681/--port $TTYD_PORT/g; s/fontSize=18/fontSize=$FONT_SIZE/g" \
"$(dirname "$0")/systemd/ttyd-kitty.service" > /etc/systemd/system/ttyd-kitty.service
sed "s/User=rdp/User=$SERVICE_USER/g" \
"$(dirname "$0")/systemd/kitty-notify.service" > /etc/systemd/system/kitty-notify.service
systemctl daemon-reload
systemctl enable --now ttyd-kitty kitty-notify
echo "[6/6] Verifying..."
sleep 2
systemctl is-active ttyd-kitty && echo " ttyd: OK (port $TTYD_PORT)"
systemctl is-active kitty-notify && echo " notify: OK (port $NOTIFY_PORT)"
echo ""
echo "=== kitty-web is running ==="
echo "Direct access: http://$(hostname -I | awk '{print $1}'):$TTYD_PORT"
echo ""
echo "For reverse proxy setup, see README.md"
echo "Send notifications: kitty-notify 'Hello from the terminal!'"