Add install_everything.sh, update README.md, WIKI.md

This commit is contained in:
2026-03-13 16:03:04 +08:00
parent e72a3ab85c
commit 99f1b3e095
3 changed files with 506 additions and 3 deletions

170
install_everything.sh Executable file
View File

@@ -0,0 +1,170 @@
#!/bin/bash
# TCK RTU - Install Everything Script
# This script installs all prerequisites and starts the application
# Usage: bash <(curl -sL https://raw.githubusercontent.com/REPO_URL/main/install_everything.sh)
# Or: ./install_everything.sh
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'
BOLD='\033[1m'
echo -e "${CYAN}${BOLD}"
echo "╔══════════════════════════════════════════════════════╗"
echo "║ TCK RTU - Automated Installation Script ║"
echo "╚══════════════════════════════════════════════════════╝"
echo -e "${NC}"
# Configuration
APP_DIR="/opt/tck_rtu"
REPO_URL="${REPO_URL:-https://github.com/your-repo/tck_rtu.git}"
# Detect if running as root
if [ "$EUID" -eq 0 ]; then
IS_ROOT=true
else
IS_ROOT=false
fi
# Function to install system dependencies
install_system_deps() {
echo -e "${BLUE}[1/5] Installing system dependencies...${NC}"
if command -v apt-get &> /dev/null; then
# Debian/Ubuntu
if [ "$IS_ROOT" = true ]; then
apt-get update
apt-get install -y curl git nginx
else
echo -e "${YELLOW}Not running as root. System deps must be installed manually:${NC}"
echo " sudo apt-get update"
echo " sudo apt-get install -y curl git nginx"
fi
elif command -v yum &> /dev/null; then
# RHEL/CentOS
if [ "$IS_ROOT" = true ]; then
yum install -y curl git nginx
else
echo -e "${YELLOW}Not running as root. Run manually: sudo yum install -y curl git nginx${NC}"
fi
elif command -v pacman &> /dev/null; then
# Arch
if [ "$IS_ROOT" = true ]; then
pacman -S --noconfirm curl git nginx
else
echo -e "${YELLOW}Not running as root. Run manually: sudo pacman -S --noconfirm curl git nginx${NC}"
fi
fi
echo -e "${GREEN}System dependencies check complete.${NC}"
}
# Function to install Node.js
install_node() {
echo -e "${BLUE}[2/5] Installing Node.js...${NC}"
if command -v node &> /dev/null; then
NODE_VERSION=$(node -v)
echo -e "${GREEN}Node.js already installed: $NODE_VERSION${NC}"
return
fi
if [ "$IS_ROOT" = true ]; then
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
else
echo -e "${YELLOW}Node.js not found. Please install manually:${NC}"
echo " curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash -"
echo " sudo apt-get install -y nodejs"
fi
echo -e "${GREEN}Node.js installation complete.${NC}"
}
# Function to clone or update repository
setup_repo() {
echo -e "${BLUE}[3/5] Setting up repository...${NC}"
if [ -d "$APP_DIR" ]; then
echo -e "${YELLOW}Directory $APP_DIR already exists. Updating...${NC}"
cd "$APP_DIR"
git pull origin main 2>/dev/null || git pull
else
echo -e "Cloning repository to $APP_DIR..."
if [ "$IS_ROOT" = true ]; then
mkdir -p "$APP_DIR"
git clone "$REPO_URL" "$APP_DIR"
else
echo -e "${YELLOW}Cannot create $APP_DIR without root. Using current directory.${NC}"
if [ ! -d "sample_interface" ]; then
echo "Please ensure the repository is cloned first."
exit 1
fi
APP_DIR=$(pwd)
fi
fi
cd "$APP_DIR"
echo -e "${GREEN}Repository setup complete.${NC}"
}
# Function to install npm dependencies
install_npm_deps() {
echo -e "${BLUE}[4/5] Installing npm dependencies...${NC}"
if [ ! -d "$APP_DIR/sample_interface" ]; then
echo -e "${RED}Error: sample_interface not found in $APP_DIR${NC}"
exit 1
fi
cd "$APP_DIR/sample_interface"
if [ -d "node_modules" ]; then
echo -e "${YELLOW}node_modules exists. Updating...${NC}"
npm update
else
npm install
fi
echo -e "${GREEN}NPM dependencies installed.${NC}"
}
# Function to start the application
start_app() {
echo -e "${BLUE}[5/5] Starting application...${NC}"
echo ""
cd "$APP_DIR"
# Make start.sh executable
chmod +x start.sh
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${GREEN}Installation complete!${NC}"
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo -e "Starting TCK RTU menu..."
echo ""
# Run start.sh
./start.sh
}
# Main execution
main() {
install_system_deps
install_node
setup_repo
install_npm_deps
start_app
}
# Run main
main