#!/bin/sh
# ====================[ fluviol                           ]====================
#                     [ Time-stamp: "2009-04-18 19:29:36 leycec" ]
#
# --------------------( TODO                               )--------------------
# * Permit user-defined overwrite of variables via either explicit command-line
#   option or, if set, sourcing a shell-format "$FLUVIOL_CONFIG" file.
# * Recover from failure by running vanilla "fvwm-crystal" or "fvwm", instead,
#   if either reside in the current path. The user should be presented with a
#   prompt at which they will be asked to "Press any key...", so that they may
#   be made aware of this error prior to starting the LA.

# ....................{ CONFIGURATION                      }....................
# Absolute path to the Fluviola installation directory.
FLUVIOL_ROOT="${HOME}/.fluviol"

# Absolute path to the Fluviola FVWM script.
FLUVIOL_RC="${FLUVIOL_ROOT}/fluviol.fvwm"

# Absolute path to the Fluviola FVWM version file.
FLUVIOL_VERSION="${FLUVIOL_ROOT}/version"

# Absolute path to the FVWM binary.
FVWM=$(which fvwm 2>/dev/null)

# ....................{ CONFIGURATION =x11                 }....................
# Absolute path to the X.org configuration directory.
X11_ROOT="/etc/X11"

# Absolute path to the X.org "xinitrc.d" directory. If it exists under your
# Linux distro, this directory typically has one shell script for each X.org
# service to be started on X11 startup.
XINITRC_ROOT="$X11_ROOT/xinit/xinitrc.d"

# Absolute paths to the system-wide and user-specific Xresources files.
# These files are commonly used to set X.org-specific rendering attributes.
XRESOURCES_SYSTEM="$X11_ROOT/Xresources"
XRESOURCES_USER="$HOME/.Xresources"

# Absolute paths to the system-wide and user-specific Xmodmap files. These
# files are commonly used to transpose <Caps Lock> and <Esc>, and perform other
# permutations on the X.org-specific keyboard layout.
XMODMAP_SYSTEM="$X11_ROOT/Xmodmap"
XMODMAP_USER="$HOME/.Xmodmap"

# ....................{ SANITATION                         }....................
if [ ! -x "$FVWM" ]; then
  echo "fluviol: FVWM not installed!" 1>&2
  exit 1
fi

if [ ! -s "$FLUVIOL_RC" ]; then
  echo "fluviol: FVWM script \"$FLUVIOL_RC\" not found!" 1>&2
  exit 1
fi

if [ -s "$FLUVIOL_VERSION" ]
then FLUVIOL_VERSION_NUMBER=$(cat "$FLUVIOL_VERSION")
else FLUVIOL_VERSION_NUMBER="?.?.?"
  echo "fluviol: version file \"$FLUVIOL_VERSION\" not found!" 1>&2
fi

# ....................{ INITIATION                         }....................
echo "fluviol: v$FLUVIOL_VERSION_NUMBER"

# Load Xresources, if available.
echo "fluviol: merging Xresources..."
[ -s "$XRESOURCES_SYSTEM" ] && xrdb -merge "$XRESOURCES_SYSTEM"
[ -s "$XRESOURCES_USER"   ] && xrdb -merge "$XRESOURCES_USER"

# Load Xmodmap, if available.
echo "fluviol: merging Xmodmap..."
[ -s "$XMODMAP_SYSTEM" ] && xmodmap "$XMODMAP_SYSTEM"
[ -s "$XMODMAP_USER"   ] && xmodmap "$XMODMAP_USER"

# Load "xinitrc.d" services, if available.
if [ -d "$XINITRC_ROOT" ]; then
  echo "fluviol: running xinitrc.d scripts..."
  for XINITRC_SCRIPT in "$XINITRC_ROOT"/*; do "$XINITRC_SCRIPT"; done
fi

# ....................{ EXECUTION                          }....................
echo "fluviol: executing..."
FLUVIOL_ROOT="$FLUVIOL_ROOT" exec "$FVWM" -f "$FLUVIOL_RC"

# --------------------( COPYRIGHT AND LICENSE              )--------------------
# The information below applies to everything in this distribution,
# except where noted.
#              
# Copyleft 2010 by Cecil Curry.
#   
#   http://www.raiazome.com
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
