Implement system status and update functionality
- Add system status card to dashboard with uptime and version display - Implement version checking against git repository - Add one-click update functionality - Update footer and version references to 2.0.0 - Add server endpoints for status, update checking, and update application 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,178 +1,84 @@
|
||||
#!/bin/bash
|
||||
# Update script for Transmission RSS Manager
|
||||
|
||||
# Text formatting
|
||||
BOLD='\033[1m'
|
||||
# Transmission RSS Manager - Update Script
|
||||
# This script pulls the latest version from git and runs necessary updates
|
||||
|
||||
# Color and formatting
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[0;33m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
BOLD='\033[1m'
|
||||
|
||||
# Get script directory
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
APP_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
# Installation directory (should be current directory)
|
||||
INSTALL_DIR=$(pwd)
|
||||
|
||||
# Check if script is run with sudo
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo -e "${RED}Please run as root (use sudo)${NC}"
|
||||
# Check if we're in the right directory
|
||||
if [ ! -f "$INSTALL_DIR/package.json" ] || [ ! -d "$INSTALL_DIR/modules" ]; then
|
||||
echo -e "${RED}Error: This script must be run from the installation directory.${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
|
||||
# Get the current version
|
||||
CURRENT_VERSION=$(grep -oP '"version": "\K[^"]+' package.json)
|
||||
echo -e "${YELLOW}Current version: ${BOLD}$CURRENT_VERSION${NC}"
|
||||
|
||||
# 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}"
|
||||
# Check for git repository
|
||||
if [ ! -d ".git" ]; then
|
||||
echo -e "${RED}Error: This installation was not set up using git.${NC}"
|
||||
echo -e "Please use the bootstrap installer to perform a fresh installation."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${BOLD}==================================================${NC}"
|
||||
echo -e "${BOLD} Update process completed ${NC}"
|
||||
echo -e "${BOLD}==================================================${NC}"
|
||||
# Stash any local changes
|
||||
echo -e "${YELLOW}Backing up any local configuration changes...${NC}"
|
||||
git stash -q
|
||||
|
||||
# Pull the latest changes
|
||||
echo -e "${YELLOW}Pulling latest updates from git...${NC}"
|
||||
git pull
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${RED}Failed to pull updates. Restoring original state...${NC}"
|
||||
git stash pop -q
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the new version
|
||||
NEW_VERSION=$(grep -oP '"version": "\K[^"]+' package.json)
|
||||
echo -e "${GREEN}New version: ${BOLD}$NEW_VERSION${NC}"
|
||||
|
||||
# Check if update is needed
|
||||
if [ "$CURRENT_VERSION" == "$NEW_VERSION" ]; then
|
||||
echo -e "${GREEN}You already have the latest version.${NC}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Install any new npm dependencies
|
||||
echo -e "${YELLOW}Installing dependencies...${NC}"
|
||||
npm install
|
||||
|
||||
# Apply any local configuration changes
|
||||
if git stash list | grep -q "stash@{0}"; then
|
||||
echo -e "${YELLOW}Restoring local configuration changes...${NC}"
|
||||
git stash pop -q
|
||||
# Handle conflicts if any
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${RED}There were conflicts when restoring your configuration.${NC}"
|
||||
echo -e "Please check the files and resolve conflicts manually."
|
||||
echo -e "Your original configuration is saved in .git/refs/stash"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Restart the service
|
||||
echo -e "${YELLOW}Restarting service...${NC}"
|
||||
if command -v systemctl &> /dev/null; then
|
||||
sudo systemctl restart transmission-rss-manager
|
||||
else
|
||||
echo -e "${RED}Could not restart service automatically.${NC}"
|
||||
echo -e "Please restart the service manually."
|
||||
fi
|
||||
|
||||
# Update complete
|
||||
echo -e "${GREEN}${BOLD}Update complete!${NC}"
|
||||
echo -e "Updated from version $CURRENT_VERSION to $NEW_VERSION"
|
||||
echo -e "Changes will take effect immediately."
|
||||
Reference in New Issue
Block a user