#!/usr/bin/env bash

logg info 'Ensure /usr/local/share is a directory'
sudo mkdir -p /usr/local/share

logg info 'Clean up old theme files'
for ITEM_TO_BE_REMOVED of "/usr/share/backgrounds/images" "/usr/share/backgrounds/f32" "/usr/share/backgrounds/qubes" "/usr/share/wallpapers"; do
  if [ -d "$ITEM_TO_BE_REMOVED" ] || [ -f "$ITEM_TO_BE_REMOVED" ]; then
    logg info "Removing $ITEM_TO_BE_REMOVED"
    sudo rm -rf "$ITEM_TO_BE_REMOVED"
  fi
fi

logg info 'Copy /usr/local/src/{{ .theme }}/share to /usr/local/share'
sudo cp -rf /usr/local/src/{{ .theme }}/share/ /usr/local/share

logg info 'Converting all symlinks to equivalent regular files'
sudo find /usr/local/src -type l -exec squash-symlink {} +

logg info 'Ensure /boot/grub2/themes is a directory'
sudo mkdir -p /boot/grub2/themes

logg info 'Copy GRUB themes to /boot/grub2/themes'
sudo cp -rf /usr/local/share/grub/themes/ /boot/grub2/themes
