#!/bin/bash

#############################################
#		MINT-FM2
#--------------------------------------------
# Contributors: Shane Joe Lazar <shane AT archlinux DOT us>
# 		Kendall Tristan Weaver <kendalltweaver@gmail.com>
# Description: This is the user utility script for mint-fm2, written for Linux Mint 9 Fluxbox CE.
# License: GPL v2 or later.
#		/MINT-FM2
############################################# 

#############################################
#		LOAD VARIABLES
#--------------------------------------------

ACTION="$@"

# Get proper paths and names
MINTFM2PATH=$(readlink -f $(which $0))
MINTFM2ROOT=$(dirname $MINTFM2PATH)
MINTFM2NAME=$(basename $MINTFM2PATH)

# Load configs
source $MINTFM2ROOT/systemConfig

#		/LOAD VARIABLES
############################################# 

#############################################
#		LOAD FUNCTIONS
#--------------------------------------------

source $MINTFM2ROOT/functionLibrary

#		/LOAD FUNCTIONS
############################################# 

#############################################
#		SANITY ChECKS
#--------------------------------------------

if [[ "$SYSCONFIGS" != "LOADED" || "$LIBFUNCTIONS" != "LOADED" ]]
then
  echo "Error: Essential libraries and/or settings have not been loaded."
  echo "System Settings: $SYSCONFIGS"
  echo "Function Library: $LIBFUNCTIONS"
  exit 1
fi

#		/SANITY ChECKS
############################################# 

# Quit on errors and unbound variables
set -e
set -u

#############################################
#		CASES
#--------------------------------------------

case $ACTION in

# Generate an new menu with Zenity progress dialog
  generate-gui)
    utilsGenerateWithZenity
  ;;

# Update the existing menu
  update)
    utilsUpdate
  ;;

# Start the mint-fm2 user daemon
  generate)
    utilsGenerate
  ;;

# Control the mint-fm2 user daemon
  start|restart|stop)
    daemonControl $@
  ;;

# Expert debug mode
  debug)
    trap "rm -rf /tmp/$USER/bin/" INT TERM EXIT
    env MINTFM2ROOT=$(dirname $MINTFM2PATH) PS1="" /bin/bash --noprofile --init-file $MINTFM2ROOT/promptrc
    clear
  ;;

# Unknown commands
  *|"")
    utilsUsage
  ;;

esac
#		/CASES
############################################# 

exit 0
