195 lines
No EOL
5.9 KiB
Bash
195 lines
No EOL
5.9 KiB
Bash
#!/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
|
|
|
|
# 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
|
|
echo "Error: User $USERNAME does not exist"
|
|
exit 1
|
|
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 "$INSTALL_DIR"
|
|
chown $USERNAME:docker "$INSTALL_DIR"
|
|
|
|
# Copy files to installation directory
|
|
if [ "$SCRIPT_DIR" != "$INSTALL_DIR" ]; then
|
|
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"
|
|
else
|
|
# Files are already in the target directory, just ensure permissions
|
|
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"
|
|
fi
|
|
|
|
# Create default .env file if it doesn't exist
|
|
if [ ! -f "$INSTALL_DIR/.env" ]; then
|
|
cat > "$INSTALL_DIR/.env" << EOF
|
|
# Base directory for stacks
|
|
COMPOSESYNC_BASE_DIR="$INSTALL_DIR/stacks"
|
|
|
|
# Number of versions to keep (default: 10)
|
|
KEEP_VERSIONS=10
|
|
|
|
# Update interval in seconds (default: 3600)
|
|
UPDATE_INTERVAL_SECONDS=3600
|
|
|
|
# Update mode (notify_only or notify_and_apply)
|
|
UPDATE_MODE=notify_and_apply
|
|
|
|
# Optional: Webhook URL for notifications
|
|
# NOTIFICATION_WEBHOOK_URL=
|
|
EOF
|
|
chown $USERNAME:docker "$INSTALL_DIR/.env"
|
|
fi
|
|
|
|
# Copy example configuration files
|
|
if [ "$SCRIPT_DIR" != "$INSTALL_DIR" ]; then
|
|
cp config.toml.example "$INSTALL_DIR/config.toml"
|
|
chown $USERNAME:docker "$INSTALL_DIR/config.toml"
|
|
else
|
|
# File is already in the target directory, just ensure it exists and has proper permissions
|
|
if [ ! -f "$INSTALL_DIR/config.toml" ]; then
|
|
cp config.toml.example "$INSTALL_DIR/config.toml"
|
|
fi
|
|
chown $USERNAME:docker "$INSTALL_DIR/config.toml"
|
|
fi
|
|
|
|
# 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
|
|
|
|
# Enable and start the service
|
|
systemctl enable composesync
|
|
systemctl start composesync
|
|
|
|
# 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 "🎉 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" |