Major improvements: flexible install dir, configurable compose file name for git, enhanced webhook notifications, cross-platform lock, robust rollback, and updated docs.\n\n- Install dir is now user-confirmable and dynamic\n- Added COMPOSE_FILENAME for git stacks\n- Webhook payloads now include git context and rollback events\n- Lock file age check is cross-platform\n- Rollback notifications for success/failure\n- Updated TOML example and documentation\n- Many robustness and UX improvements
This commit is contained in:
parent
f0dba7cc0a
commit
70486907aa
18 changed files with 3788 additions and 1767 deletions
144
install.sh
144
install.sh
|
|
@ -1,16 +1,80 @@
|
|||
#!/bin/bash
|
||||
|
||||
# ComposeSync Installation Script
|
||||
#
|
||||
# For non-interactive SSH installation, set the username:
|
||||
# export COMPOSESYNC_USER=yourusername
|
||||
# sudo ./install.sh
|
||||
#
|
||||
# For interactive installation:
|
||||
# sudo ./install.sh
|
||||
|
||||
# Exit on error
|
||||
set -e
|
||||
|
||||
# Get the directory where this script is located
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
DEFAULT_INSTALL_DIR="$SCRIPT_DIR"
|
||||
|
||||
# Check if running as root
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "Please run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get username
|
||||
read -p "Enter the username to run ComposeSync (must be in docker group): " USERNAME
|
||||
# Check for required dependencies
|
||||
check_dependencies() {
|
||||
local missing_deps=()
|
||||
|
||||
for dep in docker systemctl wget git; do
|
||||
if ! command -v "$dep" &> /dev/null; then
|
||||
missing_deps+=("$dep")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#missing_deps[@]} -ne 0 ]; then
|
||||
echo "Error: Missing required dependencies: ${missing_deps[*]}"
|
||||
echo "Please install them before running this script."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if Docker service is running
|
||||
if ! systemctl is-active --quiet docker; then
|
||||
echo "Error: Docker service is not running"
|
||||
echo "Start Docker with: sudo systemctl start docker"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_dependencies
|
||||
|
||||
# Get installation directory
|
||||
if [ -n "${COMPOSESYNC_INSTALL_DIR:-}" ]; then
|
||||
INSTALL_DIR="$COMPOSESYNC_INSTALL_DIR"
|
||||
echo "Using installation directory from environment: $INSTALL_DIR"
|
||||
else
|
||||
echo "ComposeSync will be installed in: $DEFAULT_INSTALL_DIR"
|
||||
read -p "Is this correct? (y/N): " confirm
|
||||
if [[ $confirm =~ ^[Yy]$ ]]; then
|
||||
INSTALL_DIR="$DEFAULT_INSTALL_DIR"
|
||||
else
|
||||
read -p "Enter installation directory: " INSTALL_DIR
|
||||
fi
|
||||
fi
|
||||
|
||||
# Validate installation directory
|
||||
if [ ! -d "$INSTALL_DIR" ]; then
|
||||
echo "Error: Installation directory $INSTALL_DIR does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get username (support both interactive and non-interactive modes)
|
||||
if [ -n "${COMPOSESYNC_USER:-}" ]; then
|
||||
USERNAME="$COMPOSESYNC_USER"
|
||||
echo "Using username from environment: $USERNAME"
|
||||
else
|
||||
read -p "Enter the username to run ComposeSync (must be in docker group): " USERNAME
|
||||
fi
|
||||
|
||||
# Verify user exists and is in docker group
|
||||
if ! id "$USERNAME" &>/dev/null; then
|
||||
|
|
@ -21,23 +85,27 @@ fi
|
|||
if ! groups "$USERNAME" | grep -q docker; then
|
||||
echo "Error: User $USERNAME is not in the docker group"
|
||||
echo "Add user to docker group with: sudo usermod -aG docker $USERNAME"
|
||||
echo "Then log out and back in, or run: newgrp docker"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create necessary directories
|
||||
mkdir -p /opt/composesync
|
||||
chown $USERNAME:docker /opt/composesync
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
chown $USERNAME:docker "$INSTALL_DIR"
|
||||
|
||||
# Copy files to installation directory
|
||||
cp update-agent.sh /opt/composesync/
|
||||
chmod +x /opt/composesync/update-agent.sh
|
||||
chown $USERNAME:docker /opt/composesync/update-agent.sh
|
||||
cp update-agent.sh "$INSTALL_DIR/"
|
||||
cp config-parser.sh "$INSTALL_DIR/"
|
||||
chmod +x "$INSTALL_DIR/update-agent.sh"
|
||||
chmod +x "$INSTALL_DIR/config-parser.sh"
|
||||
chown $USERNAME:docker "$INSTALL_DIR/update-agent.sh"
|
||||
chown $USERNAME:docker "$INSTALL_DIR/config-parser.sh"
|
||||
|
||||
# Create default .env file if it doesn't exist
|
||||
if [ ! -f /opt/composesync/.env ]; then
|
||||
cat > /opt/composesync/.env << EOF
|
||||
if [ ! -f "$INSTALL_DIR/.env" ]; then
|
||||
cat > "$INSTALL_DIR/.env" << EOF
|
||||
# Base directory for stacks
|
||||
COMPOSESYNC_BASE_DIR=/opt/composesync/stacks
|
||||
COMPOSESYNC_BASE_DIR="$INSTALL_DIR/stacks"
|
||||
|
||||
# Number of versions to keep (default: 10)
|
||||
KEEP_VERSIONS=10
|
||||
|
|
@ -51,11 +119,15 @@ UPDATE_MODE=notify_and_apply
|
|||
# Optional: Webhook URL for notifications
|
||||
# NOTIFICATION_WEBHOOK_URL=
|
||||
EOF
|
||||
chown $USERNAME:docker /opt/composesync/.env
|
||||
chown $USERNAME:docker "$INSTALL_DIR/.env"
|
||||
fi
|
||||
|
||||
# Update service file with username
|
||||
sed "s/YOUR_USERNAME/$USERNAME/" composesync.service > /etc/systemd/system/composesync.service
|
||||
# Copy example configuration files
|
||||
cp config.toml.example "$INSTALL_DIR/config.toml"
|
||||
chown $USERNAME:docker "$INSTALL_DIR/config.toml"
|
||||
|
||||
# Update service file with username and installation directory
|
||||
sed "s|YOUR_USERNAME|$USERNAME|g; s|/opt/composesync|$INSTALL_DIR|g" composesync.service > /etc/systemd/system/composesync.service
|
||||
|
||||
# Reload systemd
|
||||
systemctl daemon-reload
|
||||
|
|
@ -64,10 +136,44 @@ systemctl daemon-reload
|
|||
systemctl enable composesync
|
||||
systemctl start composesync
|
||||
|
||||
echo "ComposeSync has been installed and started!"
|
||||
echo "You can check the status with: systemctl status composesync"
|
||||
echo "View logs with: journalctl -u composesync -f"
|
||||
# Verify service started successfully
|
||||
if systemctl is-active --quiet composesync; then
|
||||
echo "✅ ComposeSync service started successfully!"
|
||||
else
|
||||
echo "❌ ComposeSync service failed to start"
|
||||
echo "Check the logs with: sudo journalctl -u composesync -n 50"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "To manage your stacks, create directories in /opt/composesync/stacks/"
|
||||
echo "Example: sudo mkdir -p /opt/composesync/stacks/immich"
|
||||
echo " sudo chown $USERNAME:docker /opt/composesync/stacks/immich"
|
||||
echo "🎉 ComposeSync has been installed successfully!"
|
||||
echo ""
|
||||
echo "📋 Next steps:"
|
||||
echo "1. Configure your stacks:"
|
||||
echo " sudo nano $INSTALL_DIR/config.toml # TOML format (recommended)"
|
||||
echo " sudo nano $INSTALL_DIR/.env # Legacy .env format"
|
||||
echo ""
|
||||
echo "2. Create your override files:"
|
||||
echo " sudo mkdir -p $INSTALL_DIR/stacks/immich"
|
||||
echo " sudo nano $INSTALL_DIR/stacks/immich/docker-compose.override.yml"
|
||||
echo ""
|
||||
echo "3. Check service status:"
|
||||
echo " sudo systemctl status composesync"
|
||||
echo ""
|
||||
echo "4. View logs:"
|
||||
echo " sudo journalctl -u composesync -f"
|
||||
echo ""
|
||||
echo "📖 Example TOML configuration:"
|
||||
echo " [global]"
|
||||
echo " UPDATE_INTERVAL_SECONDS = 3600"
|
||||
echo " "
|
||||
echo " [immich]"
|
||||
echo " URL = \"https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml\""
|
||||
echo " PATH = \"$INSTALL_DIR/stacks/immich\""
|
||||
echo " TOOL = \"wget\""
|
||||
echo ""
|
||||
echo "🔧 Service management:"
|
||||
echo " sudo systemctl start composesync # Start service"
|
||||
echo " sudo systemctl stop composesync # Stop service"
|
||||
echo " sudo systemctl restart composesync # Restart service"
|
||||
echo " sudo systemctl status composesync # Check status"
|
||||
Loading…
Add table
Add a link
Reference in a new issue