264 lines
8.8 KiB
Bash
Executable File
264 lines
8.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# TCK RTU - Start Script
|
|
# Interactive menu for common development commands
|
|
|
|
# Flip the display horizontally, and maaaybe flip the mouse cursor+touchscreen as well
|
|
# NOW JUST RUN ./flip_display.sh
|
|
|
|
# Flip the display
|
|
#DISPLAY=:0 xrandr --output HDMI-1 --reflect x
|
|
|
|
# Flip the touch input (using ID 7 for your specific device)
|
|
#DISPLAY=:0 xinput set-prop 7 'Coordinate Transformation Matrix' -1 0 1 0 1 0 0 0 1
|
|
|
|
|
|
set -e
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
CYAN='\033[0;36m'
|
|
NC='\033[0m' # No Color
|
|
BOLD='\033[1m'
|
|
|
|
# Project directory
|
|
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/sample_interface" && pwd)"
|
|
|
|
# Default ports
|
|
DEV_PORT=5173
|
|
PREVIEW_PORT=4173
|
|
|
|
echo -e "${CYAN}${BOLD}"
|
|
echo "╔══════════════════════════════════════════════════════╗"
|
|
echo "║ TCK RTU - Development Menu ║"
|
|
echo "╚══════════════════════════════════════════════════════╝"
|
|
echo -e "${NC}"
|
|
|
|
show_menu() {
|
|
echo -e "${BOLD}Select an option:${NC}"
|
|
echo ""
|
|
echo -e " ${GREEN}1)${NC} dev Start dual-mode (8888 kiosk + 9999 remote HD)"
|
|
echo -e " ${GREEN}2)${NC} dev:8888 Start dev server on port 8888 (kiosk mode)"
|
|
echo -e " ${GREEN}3)${NC} dev:9090 Start dev server on port 9090 (remote mode)"
|
|
echo -e " ${GREEN}4)${NC} dev:9999 Start dev server on port 9999 (remote HD mode)"
|
|
echo -e " ${GREEN}5)${NC} test Run tests"
|
|
echo -e " ${GREEN}6)${NC} test:watch Run tests in watch mode"
|
|
echo -e " ${GREEN}7)${NC} build Build for production"
|
|
echo -e " ${GREEN}8)${NC} preview Preview production (port $PREVIEW_PORT)"
|
|
echo -e " ${GREEN}9)${NC} lint Run linter"
|
|
echo -e " ${GREEN}10)${NC} clean Clean build artifacts"
|
|
echo -e " ${GREEN}11)${NC} install Install dependencies"
|
|
echo -e " ${GREEN}p)${NC} port Change default port"
|
|
echo ""
|
|
echo -e " ${RED}0)${NC} Exit"
|
|
echo ""
|
|
}
|
|
|
|
get_ip_address() {
|
|
# Try to get the primary IP address
|
|
if command -v ip &> /dev/null; then
|
|
IP=$(ip route get 1.1.1.1 2>/dev/null | grep -oP 'src \K[^ ]+' | head -1)
|
|
elif command -v ifconfig &> /dev/null; then
|
|
IP=$(ifconfig 2>/dev/null | grep -oP 'inet \K[\d.]+' | grep -v '127.0.0.1' | head -1)
|
|
fi
|
|
|
|
if [ -z "$IP" ]; then
|
|
IP="localhost"
|
|
fi
|
|
echo "$IP"
|
|
}
|
|
|
|
show_connection_info() {
|
|
local port=$1
|
|
local IP=$(get_ip_address)
|
|
echo ""
|
|
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${GREEN} Server running at:${NC}"
|
|
echo -e "${GREEN} - Local: http://localhost:$port${NC}"
|
|
echo -e "${GREEN} - Network: http://$IP:$port${NC}"
|
|
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo ""
|
|
}
|
|
|
|
run_dev_server() {
|
|
local port=${1:-$DEV_PORT}
|
|
cd "$PROJECT_DIR"
|
|
echo -e "${BLUE}Starting development server on port $port...${NC}"
|
|
echo -e "${YELLOW}(Press Ctrl+C to stop)${NC}"
|
|
echo ""
|
|
npm run dev -- --host --port $port &
|
|
DEV_PID=$!
|
|
show_connection_info $port
|
|
wait $DEV_PID
|
|
}
|
|
|
|
run_preview_server() {
|
|
local port=${1:-$PREVIEW_PORT}
|
|
cd "$PROJECT_DIR"
|
|
echo -e "${BLUE}Starting preview server on port $port...${NC}"
|
|
echo -e "${YELLOW}(Press Ctrl+C to stop)${NC}"
|
|
echo ""
|
|
npm run preview -- --host --port $port &
|
|
PREVIEW_PID=$!
|
|
show_connection_info $port
|
|
wait $PREVIEW_PID
|
|
}
|
|
|
|
run_dual_mode() {
|
|
local IP=$(get_ip_address)
|
|
echo -e "${CYAN}${BOLD}"
|
|
echo "╔══════════════════════════════════════════════════════╗"
|
|
echo "║ TCK RTU - Dual Mode (Kiosk + Remote HD) ║"
|
|
echo "╚══════════════════════════════════════════════════════╝"
|
|
echo -e "${NC}"
|
|
echo -e "${BLUE}Starting servers on ports 8888 and 9999...${NC}"
|
|
echo -e "${YELLOW}(Press Ctrl+C to stop both servers)${NC}"
|
|
echo ""
|
|
|
|
# Start kiosk server on port 8888
|
|
cd "$PROJECT_DIR"
|
|
npm run dev -- --host --port 8888 &
|
|
KIOSK_PID=$!
|
|
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${GREEN} Kiosk Server (8888) started (PID: $KIOSK_PID)${NC}"
|
|
|
|
# Start remote HD server on port 9999
|
|
npm run dev -- --host --port 9999 &
|
|
REMOTE_PID=$!
|
|
echo -e "${GREEN} Remote HD Server (9999) started (PID: $REMOTE_PID)${NC}"
|
|
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo ""
|
|
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${GREEN} Dual-mode servers running:${NC}"
|
|
echo -e "${GREEN} - Kiosk (local touchscreen): http://localhost:8888${NC}"
|
|
echo -e "${GREEN} - Remote HD (desktop): http://localhost:9999${NC}"
|
|
echo ""
|
|
echo -e "${GREEN} - Network Kiosk: http://$IP:8888${NC}"
|
|
echo -e "${GREEN} - Network Remote HD: http://$IP:9999${NC}"
|
|
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo ""
|
|
|
|
# Wait for both processes
|
|
wait $KIOSK_PID $REMOTE_PID
|
|
}
|
|
|
|
change_port() {
|
|
echo -e "${BOLD}Change Default Port${NC}"
|
|
echo ""
|
|
echo -e "Current: Dev=$DEV_PORT, Preview=$PREVIEW_PORT"
|
|
echo ""
|
|
echo -n "Enter new dev port (current: $DEV_PORT): "
|
|
read -r new_dev_port
|
|
if [ -n "$new_dev_port" ]; then
|
|
DEV_PORT=$new_dev_port
|
|
fi
|
|
|
|
echo -n "Enter new preview port (current: $PREVIEW_PORT): "
|
|
read -r new_preview_port
|
|
if [ -n "$new_preview_port" ]; then
|
|
PREVIEW_PORT=$new_preview_port
|
|
fi
|
|
|
|
echo -e "${GREEN}Ports updated! Dev=$DEV_PORT, Preview=$PREVIEW_PORT${NC}"
|
|
echo ""
|
|
}
|
|
|
|
run_command() {
|
|
local option=$1
|
|
cd "$PROJECT_DIR"
|
|
|
|
case $option in
|
|
1|dev)
|
|
run_dual_mode
|
|
;;
|
|
2|dev:8888)
|
|
run_dev_server 8888
|
|
;;
|
|
3|dev:9090)
|
|
run_dev_server 9090
|
|
;;
|
|
4|dev:9999)
|
|
run_dev_server 9999
|
|
;;
|
|
5|test)
|
|
echo -e "${BLUE}Running tests...${NC}"
|
|
npm test
|
|
;;
|
|
6|test:watch)
|
|
echo -e "${BLUE}Running tests in watch mode...${NC}"
|
|
npm run test:watch
|
|
;;
|
|
7|build)
|
|
echo -e "${BLUE}Building for production...${NC}"
|
|
npm run build
|
|
echo -e "${GREEN}Build complete!${NC}"
|
|
;;
|
|
8|preview)
|
|
run_preview_server $PREVIEW_PORT
|
|
;;
|
|
9|lint)
|
|
echo -e "${BLUE}Running linter...${NC}"
|
|
npm run lint
|
|
;;
|
|
10|clean)
|
|
echo -e "${YELLOW}Cleaning build artifacts...${NC}"
|
|
rm -rf "$PROJECT_DIR/dist"
|
|
rm -rf "$PROJECT_DIR/node_modules/.vite"
|
|
echo -e "${GREEN}Clean complete!${NC}"
|
|
;;
|
|
11|install)
|
|
echo -e "${BLUE}Installing dependencies...${NC}"
|
|
npm install
|
|
echo -e "${GREEN}Dependencies installed!${NC}"
|
|
;;
|
|
p|port)
|
|
change_port
|
|
;;
|
|
0|exit)
|
|
echo -e "${GREEN}Goodbye!${NC}"
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo -e "${RED}Invalid option. Please try again.${NC}"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Check if dependencies are installed
|
|
if [ ! -d "$PROJECT_DIR/node_modules" ]; then
|
|
echo -e "${YELLOW}Dependencies not found. Running npm install...${NC}"
|
|
cd "$PROJECT_DIR"
|
|
npm install
|
|
fi
|
|
|
|
# Parse command line arguments
|
|
if [ $# -gt 0 ]; then
|
|
# Check for port override
|
|
if [[ "$1" == dev:* ]]; then
|
|
port="${1#dev:}"
|
|
run_dev_server "$port"
|
|
elif [[ "$1" == preview:* ]]; then
|
|
port="${1#preview:}"
|
|
run_preview_server "$port"
|
|
elif [[ "$1" =~ ^[[:digit:]]+$ ]]; then
|
|
# Direct port number
|
|
run_dev_server "$1"
|
|
else
|
|
run_command "$1"
|
|
fi
|
|
exit 0
|
|
fi
|
|
|
|
# Interactive menu
|
|
while true; do
|
|
show_menu
|
|
echo -n -e "${BOLD}Enter your choice (0-11 or p): ${NC}"
|
|
read -r choice
|
|
echo ""
|
|
run_command "$choice"
|
|
echo ""
|
|
done
|