#!/usr/bin/env bash
#
# Cloudesta Roundcube skin — re-apply after a cPanel/Roundcube update.
#
# cPanel updates can replace the bundled Roundcube and wipe custom skins.
# Run this after any update to restore + recompile the Cloudesta skin.
# Safe to schedule via cron (e.g. nightly) as a safety net.
#
set -euo pipefail

RC_DIR="/usr/local/cpanel/base/3rdparty/roundcube"
HERE="$(cd "$(dirname "$0")" && pwd)"
SKIN_SRC="$HERE/cloudesta"
SKIN_DST="$RC_DIR/skins/cloudesta"

# Re-copy only if missing or source is newer
if [ ! -d "$SKIN_DST" ] || [ "$SKIN_SRC" -nt "$SKIN_DST" ]; then
  echo ">> Restoring Cloudesta skin"
  rm -rf "$SKIN_DST"
  cp -a "$SKIN_SRC" "$RC_DIR/skins/"
  cd "$RC_DIR"
  [ -x "bin/updatecss.sh" ] && bin/updatecss.sh --dir skins/cloudesta
  echo ">> Skin restored and recompiled."
else
  echo ">> Skin already present and up to date. Nothing to do."
fi
