105 lines
3.4 KiB
Bash
105 lines
3.4 KiB
Bash
#!/bin/bash
|
|
# Setup and update Kiwy-Signage player code for SSH-based deployment
|
|
# This script is called by docker-entrypoint.sh on container startup
|
|
|
|
set -e
|
|
|
|
PLAYER_CODE_DIR="/app/data/player"
|
|
REPO_URL="https://gitea.moto-adv.com/ske087/Kiwy-Signage.git"
|
|
REPO_BRANCH="master"
|
|
|
|
echo "=========================================="
|
|
echo "Setting up Player Code for SSH Deployment"
|
|
echo "=========================================="
|
|
echo ""
|
|
|
|
# Create player data directory if it doesn't exist
|
|
if [ ! -d "$PLAYER_CODE_DIR" ]; then
|
|
echo "📁 Creating player code directory: $PLAYER_CODE_DIR"
|
|
mkdir -p "$PLAYER_CODE_DIR"
|
|
fi
|
|
|
|
# Check if git repository exists
|
|
if [ -d "$PLAYER_CODE_DIR/.git" ]; then
|
|
echo "🔄 Repository exists - updating from remote..."
|
|
cd "$PLAYER_CODE_DIR"
|
|
|
|
# Fetch latest changes
|
|
if git fetch origin "$REPO_BRANCH" 2>/dev/null; then
|
|
# Try to update
|
|
if git reset --hard "origin/$REPO_BRANCH" 2>/dev/null; then
|
|
echo "✅ Player code updated successfully"
|
|
COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
|
echo " Current version: $COMMIT"
|
|
else
|
|
echo "⚠️ Could not reset to remote - using existing code"
|
|
fi
|
|
else
|
|
echo "⚠️ Could not fetch from remote - using existing code"
|
|
fi
|
|
else
|
|
echo "📥 Cloning Kiwy-Signage repository..."
|
|
|
|
# Check if directory is not empty
|
|
if [ "$(ls -A "$PLAYER_CODE_DIR" 2>/dev/null)" ]; then
|
|
echo "⚠️ Directory not empty but no git repo - cleaning..."
|
|
rm -rf "$PLAYER_CODE_DIR"/*
|
|
rm -rf "$PLAYER_CODE_DIR"/.*
|
|
fi
|
|
|
|
# Clone the repository
|
|
if git clone --branch "$REPO_BRANCH" "$REPO_URL" "$PLAYER_CODE_DIR" 2>/dev/null; then
|
|
echo "✅ Repository cloned successfully"
|
|
COMMIT=$(git -C "$PLAYER_CODE_DIR" rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
|
echo " Current version: $COMMIT"
|
|
else
|
|
echo "❌ Failed to clone repository"
|
|
echo " Repository: $REPO_URL"
|
|
echo " This may be due to:"
|
|
echo " • Network connectivity issues"
|
|
echo " • Repository access restrictions"
|
|
echo " • Invalid repository URL"
|
|
echo ""
|
|
echo "⚠️ DigiServer will continue without pre-staged player code"
|
|
echo " SSH deployment will attempt to clone on-demand"
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
echo "📊 Player Code Directory:"
|
|
du -sh "$PLAYER_CODE_DIR" 2>/dev/null || echo " (empty or not ready)"
|
|
echo ""
|
|
|
|
# Create a metadata file
|
|
METADATA_FILE="$PLAYER_CODE_DIR/.deployment-info"
|
|
cat > "$METADATA_FILE" << EOF
|
|
# Kiwy-Signage Player Code - Deployment Metadata
|
|
# Auto-generated by setup-player-code.sh
|
|
|
|
Repository: $REPO_URL
|
|
Branch: $REPO_BRANCH
|
|
Updated: $(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
|
Version: $(git -C "$PLAYER_CODE_DIR" rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
|
Hostname: $(hostname)
|
|
|
|
## Usage
|
|
This directory contains the Kiwy-Signage player code that is:
|
|
1. Pre-staged in the DigiServer container
|
|
2. Used as a base for SSH-based remote deployment
|
|
3. Updated on each container restart (if network available)
|
|
|
|
For SSH deployment, this code is copied to remote hosts at:
|
|
/opt/kiwy-signage
|
|
|
|
## Manual Update
|
|
To manually update inside container:
|
|
cd /app/data/player
|
|
git pull origin $REPO_BRANCH
|
|
EOF
|
|
|
|
echo "✅ Player code setup complete"
|
|
echo " Location: $PLAYER_CODE_DIR"
|
|
echo " Metadata: $METADATA_FILE"
|
|
echo ""
|