massive improvement

This commit is contained in:
2025-03-04 22:28:11 +00:00
parent d1483ce581
commit 1b97e3ba68
21 changed files with 7152 additions and 1611 deletions

165
scripts/test-and-start.sh Executable file
View File

@@ -0,0 +1,165 @@
#!/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 "$@"

178
scripts/update.sh Executable file
View File

@@ -0,0 +1,178 @@
#!/bin/bash
# Update script for Transmission RSS Manager
# Text formatting
BOLD='\033[1m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Get script directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
APP_DIR="$(dirname "$SCRIPT_DIR")"
# Check if script is run with sudo
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}Please run as root (use sudo)${NC}"
exit 1
fi
# Print header
echo -e "${BOLD}==================================================${NC}"
echo -e "${BOLD} Transmission RSS Manager Updater ${NC}"
echo -e "${BOLD} Version 1.2.0 ${NC}"
echo -e "${BOLD}==================================================${NC}"
echo
# Function to check if a service is running
service_is_running() {
systemctl is-active --quiet "$1"
return $?
}
# Backup existing files
backup_app() {
echo -e "${BOLD}Backing up existing installation...${NC}"
TIMESTAMP=$(date +%Y%m%d%H%M%S)
BACKUP_DIR="${APP_DIR}_backup_${TIMESTAMP}"
# Create backup directory
mkdir -p "$BACKUP_DIR"
# Copy files to backup directory
cp -rf "$APP_DIR"/* "$BACKUP_DIR"
echo -e "${GREEN}Backup created at: $BACKUP_DIR${NC}"
}
# Update the application
update_app() {
echo -e "${BOLD}Updating application...${NC}"
# Get user account that owns the files
APP_USER=$(stat -c '%U' "$APP_DIR")
# Check if app is running as a service
WAS_RUNNING=false
if service_is_running transmission-rss-manager; then
WAS_RUNNING=true
echo -e "${YELLOW}Stopping service during update...${NC}"
systemctl stop transmission-rss-manager
fi
# Set environment variable to indicate it's an update
export IS_UPDATE=true
# Backup config files before update
if [ -f "$APP_DIR/config.json" ]; then
echo -e "${YELLOW}Backing up configuration file...${NC}"
CONFIG_BACKUP="${APP_DIR}/config.json.bak.$(date +%Y%m%d%H%M%S)"
cp "$APP_DIR/config.json" "$CONFIG_BACKUP"
echo -e "${GREEN}Configuration backed up to $CONFIG_BACKUP${NC}"
fi
# Update npm dependencies
cd "$APP_DIR"
echo -e "${YELLOW}Updating dependencies...${NC}"
npm install
# Fix permissions
chown -R $APP_USER:$APP_USER "$APP_DIR"
# Check if update script was successful
UPDATE_SUCCESS=true
# Restart service if it was running before
if [ "$WAS_RUNNING" = true ]; then
echo -e "${YELLOW}Restarting service...${NC}"
systemctl daemon-reload
systemctl start transmission-rss-manager
# Check if service started successfully
if service_is_running transmission-rss-manager; then
echo -e "${GREEN}Service restarted successfully.${NC}"
else
echo -e "${RED}Failed to restart service. Check logs with: journalctl -u transmission-rss-manager${NC}"
UPDATE_SUCCESS=false
fi
else
echo -e "${YELLOW}Service was not running before update. Not restarting.${NC}"
fi
# Provide info about configuration changes
if [ -f "$APP_DIR/config.json" ]; then
# Check if the configuration was updated by the service
if [ $(stat -c %Y "$APP_DIR/config.json") -gt $(stat -c %Y "$CONFIG_BACKUP") ]; then
echo -e "${GREEN}Configuration updated successfully with new options.${NC}"
echo -e "${YELLOW}Your existing settings have been preserved.${NC}"
else
echo -e "${YELLOW}Configuration was not modified during update.${NC}"
echo -e "${YELLOW}If you experience issues, check for new configuration options.${NC}"
fi
fi
if [ "$UPDATE_SUCCESS" = true ]; then
echo -e "${GREEN}Update completed successfully.${NC}"
else
echo -e "${RED}Update completed with some issues.${NC}"
echo -e "${YELLOW}If needed, you can restore configuration from: $CONFIG_BACKUP${NC}"
fi
}
# Check for updates in Git repository
check_git_updates() {
echo -e "${BOLD}Checking for updates in Git repository...${NC}"
# Check if git is installed
if ! command -v git &> /dev/null; then
echo -e "${YELLOW}Git is not installed, skipping Git update check.${NC}"
return 1
fi
# Check if app directory is a git repository
if [ ! -d "$APP_DIR/.git" ]; then
echo -e "${YELLOW}Not a Git repository, skipping Git update check.${NC}"
return 1
fi
# Check for updates
cd "$APP_DIR"
git fetch
# Check if we're behind the remote
BEHIND=$(git rev-list HEAD..origin/main --count)
if [ "$BEHIND" -gt 0 ]; then
echo -e "${GREEN}Updates available: $BEHIND new commit(s)${NC}"
# Confirm update
read -p "Do you want to pull the latest changes? (y/n) [y]: " CONFIRM
CONFIRM=${CONFIRM:-y}
if [[ $CONFIRM =~ ^[Yy]$ ]]; then
echo -e "${YELLOW}Pulling latest changes...${NC}"
git pull
return 0
else
echo -e "${YELLOW}Skipping Git update.${NC}"
return 1
fi
else
echo -e "${GREEN}Already up to date.${NC}"
return 1
fi
}
# Main update process
backup_app
if check_git_updates || [ "$1" = "--force" ]; then
update_app
else
echo -e "${YELLOW}No updates needed or available.${NC}"
echo -e "${YELLOW}Use --force flag to update dependencies anyway.${NC}"
fi
echo -e "${BOLD}==================================================${NC}"
echo -e "${BOLD} Update process completed ${NC}"
echo -e "${BOLD}==================================================${NC}"