#!/bin/bash
# Ubuntu Satanic Edition theme selection script

usage()
{
  echo "Usage: sataniconf command theme"
  echo
  echo "Commands:"
  echo "  plymouth - set the bootup theme"
  echo "  themes available:"
  echo "    satanic-logo"
  echo "    default"
  echo
  echo "  gdm - set the GDM login theme"
  echo "  themes available:"

  for file in /usr/share/backgrounds/SE*; do
    echo "    $(basename $file | sed 's/-Wide//' | sed 's/\.png//')"
  done

  echo
  exit 2
}

#--------------------------------------------------------------------------
set_gdm()
{
  DIR=/usr/share/backgrounds
  gtk_theme=Inhuman
  icon_theme=Revenge

  if [ $1 = "default" ]; then
    # Default to standard Ubuntu theme
    wallpaper=$DIR/warty-final-ubuntu.png
    gtk_theme=Ambiance
    icon_theme=Ubuntu-Mono-Dark
  else
    # Satanic theme, default to widescreen if available
    wpwide=${1}-Wide.png
    wp=${1}.png

    if [ -f $DIR/$wpwide ]; then
      wallpaper=$DIR/$wpwide
    else
      wallpaper=$DIR/$wp
    fi
  fi

  if [ ! -f "$wallpaper" ]; then
    echo "Wallpaper not found: $wallpaper"
    usage
  fi

  sudo -u gdm gconftool-2 --set --type string /desktop/gnome/background/picture_filename $wallpaper
  sudo -u gdm gconftool-2 --set --type string /desktop/gnome/interface/gtk_theme $gtk_theme
  sudo -u gdm gconftool-2 --set --type string /desktop/gnome/interface/icon_theme $icon_theme

  echo "GDM GTK theme : $gtk_theme"
  echo "GDM icon theme: $icon_theme"
  echo "GDM background: $wallpaper"
}

#--------------------------------------------------------------------------
set_plymouth()
{
  case $1 in
    satanic-logo)  theme=satanic-logo;;
    default)
      echo "Reverting to default plymouth theme"
      sudo update-alternatives --auto default.plymouth
      sudo update-initramfs -u
      return;;
    *) usage;;
  esac

  sudo update-alternatives --set default.plymouth /lib/plymouth/themes/${theme}/${theme}.plymouth
  sudo update-initramfs -u
  echo "Plymouth theme set to $theme"
}

#--------------------------------------------------------------------------
# Main
if [ $# -ne 2 ]; then
  usage
fi

action=$1
theme=$2

case $action in
  gdm)      set_gdm $theme;;
  plymouth) set_plymouth $theme;;
  *)        usage;;
esac

