165 lines
4.6 KiB
Bash
Executable File
165 lines
4.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# Test and start script for Transmission RSS Manager
|
|
# This script checks the installation, dependencies, and starts the application
|
|
|
|
# Text formatting
|
|
BOLD='\033[1m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[0;33m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Get directory of this script
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
|
APP_DIR="$(dirname "$SCRIPT_DIR")"
|
|
|
|
# Function to check if a command exists
|
|
command_exists() {
|
|
command -v "$1" &> /dev/null
|
|
}
|
|
|
|
# Check Node.js and npm
|
|
check_node() {
|
|
echo -e "${BOLD}Checking Node.js and npm...${NC}"
|
|
|
|
if command_exists node; then
|
|
NODE_VERSION=$(node -v)
|
|
echo -e "${GREEN}Node.js is installed: $NODE_VERSION${NC}"
|
|
else
|
|
echo -e "${RED}Node.js is not installed. Please install Node.js 14 or later.${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
if command_exists npm; then
|
|
NPM_VERSION=$(npm -v)
|
|
echo -e "${GREEN}npm is installed: $NPM_VERSION${NC}"
|
|
else
|
|
echo -e "${RED}npm is not installed. Please install npm.${NC}"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Check if Transmission is running
|
|
check_transmission() {
|
|
echo -e "${BOLD}Checking Transmission...${NC}"
|
|
|
|
# Try to get the status of the transmission-daemon service
|
|
if command_exists systemctl; then
|
|
if systemctl is-active --quiet transmission-daemon; then
|
|
echo -e "${GREEN}Transmission daemon is running${NC}"
|
|
else
|
|
echo -e "${YELLOW}Warning: Transmission daemon does not appear to be running${NC}"
|
|
echo -e "${YELLOW}You may need to start it with: sudo systemctl start transmission-daemon${NC}"
|
|
fi
|
|
else
|
|
# Try a different method if systemctl is not available
|
|
if pgrep -x "transmission-daemon" > /dev/null; then
|
|
echo -e "${GREEN}Transmission daemon is running${NC}"
|
|
else
|
|
echo -e "${YELLOW}Warning: Transmission daemon does not appear to be running${NC}"
|
|
echo -e "${YELLOW}Please start Transmission daemon before using this application${NC}"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# Check dependencies in package.json
|
|
check_dependencies() {
|
|
echo -e "${BOLD}Checking dependencies...${NC}"
|
|
|
|
# Check if node_modules exists
|
|
if [ ! -d "$APP_DIR/node_modules" ]; then
|
|
echo -e "${YELLOW}Node modules not found. Installing dependencies...${NC}"
|
|
cd "$APP_DIR" && npm install
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo -e "${RED}Failed to install dependencies.${NC}"
|
|
exit 1
|
|
else
|
|
echo -e "${GREEN}Dependencies installed successfully${NC}"
|
|
fi
|
|
else
|
|
echo -e "${GREEN}Dependencies are already installed${NC}"
|
|
fi
|
|
}
|
|
|
|
# Check if config.json exists
|
|
check_config() {
|
|
echo -e "${BOLD}Checking configuration...${NC}"
|
|
|
|
if [ ! -f "$APP_DIR/config.json" ]; then
|
|
echo -e "${RED}Configuration file not found: $APP_DIR/config.json${NC}"
|
|
echo -e "${YELLOW}Please run the installer or create a config.json file${NC}"
|
|
exit 1
|
|
else
|
|
echo -e "${GREEN}Configuration file found${NC}"
|
|
fi
|
|
}
|
|
|
|
# Start the application
|
|
start_app() {
|
|
echo -e "${BOLD}Starting Transmission RSS Manager...${NC}"
|
|
|
|
# Check if running as a service
|
|
if command_exists systemctl; then
|
|
if systemctl is-active --quiet transmission-rss-manager; then
|
|
echo -e "${YELLOW}Transmission RSS Manager is already running as a service${NC}"
|
|
echo -e "${YELLOW}To restart it, use: sudo systemctl restart transmission-rss-manager${NC}"
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
# Start the application
|
|
cd "$APP_DIR"
|
|
|
|
# Parse arguments
|
|
FOREGROUND=false
|
|
DEBUG=false
|
|
|
|
while [[ "$#" -gt 0 ]]; do
|
|
case $1 in
|
|
--foreground|-f) FOREGROUND=true ;;
|
|
--debug|-d) DEBUG=true ;;
|
|
*) echo "Unknown parameter: $1"; exit 1 ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if [ "$FOREGROUND" = true ]; then
|
|
echo -e "${GREEN}Starting in foreground mode...${NC}"
|
|
|
|
if [ "$DEBUG" = true ]; then
|
|
echo -e "${YELLOW}Debug mode enabled${NC}"
|
|
DEBUG_ENABLED=true node server.js
|
|
else
|
|
node server.js
|
|
fi
|
|
else
|
|
echo -e "${GREEN}Starting in background mode...${NC}"
|
|
|
|
if [ "$DEBUG" = true ]; then
|
|
echo -e "${YELLOW}Debug mode enabled${NC}"
|
|
DEBUG_ENABLED=true nohup node server.js > logs/output.log 2>&1 &
|
|
else
|
|
nohup node server.js > logs/output.log 2>&1 &
|
|
fi
|
|
|
|
echo $! > "$APP_DIR/transmission-rss-manager.pid"
|
|
echo -e "${GREEN}Application started with PID: $!${NC}"
|
|
echo -e "${GREEN}Logs available at: $APP_DIR/logs/output.log${NC}"
|
|
fi
|
|
}
|
|
|
|
# Main script
|
|
echo -e "${BOLD}==================================================${NC}"
|
|
echo -e "${BOLD} Transmission RSS Manager - Test & Start ${NC}"
|
|
echo -e "${BOLD}==================================================${NC}"
|
|
echo
|
|
|
|
# Run checks
|
|
check_node
|
|
check_transmission
|
|
check_dependencies
|
|
check_config
|
|
|
|
# Start the application
|
|
start_app "$@" |