#!/bin/bash

PERMCONF="/home/root/.fvwm/personal/config"
PERMTOP="/home/root/.fvwm/personal/menutop"
PERMBOTTOM="/home/root/.fvwm/personal/menubottom"

mkdir -p /home/root/.fvwm/personal

if [ ! -f $PERMCONF ] ; then
  cat > $PERMCONF << EOF
# fvwm-pdaxrom user configuration file
# Here you can add/change configuration as you would in the .fvwm2rc
# file. It comes after every options of .fvwm2rc, so you can
# overwrite default settings from here.
#
# This file is created once and will be untouched when a new version of
# fvwm-pdaxrom is installed.

# Sample lines

# Key bindings
# Syntax reminder: Key <key> <context> <modifiers> <function>
# <context> - A = anywhere
# <modifiers> - N = none, M = Alt (Address),
# C = Control (Calendar), S = Shift, 2 = Fn key

#  add keybindig Fn+N to start dillo
#Key N A 2 Exec exec dillo
#  this disables the default keybindig for Fn+2
#Key 2 A 2 -

# Colors

# Menu colorset
#  change it to blue-orange, just for fun :)
#Colorset 0 fg blue, bg orange
# Menu colorset for the active item
#  this is the default
#Colorset 1 fg black, bg #6b83b5, hi #dcdcdc, sh #dcdcdc

# Colorset for the taskbar and for the IconMan
#  change it to olivegreen
#Colorset 3 Pixmap Panelbacks/olivegreen.png

# For the entire configuration, see the /usr/share/fvwm/.fvwm2rc file
EOF
fi

if [ ! -f $PERMTOP ] ; then
  cat > $PERMTOP << EOF
# pdaXrom menu - custom top config file
# Here you can add menu items to the _top_ of the
# applications directories in the pdaXrom menu
#
# This file is created once and will be untouched when a new version of
# fvwm-pdaxrom is installed.

#DestroyMenu MyCustomMenu
#AddToMenu MyCustomMenu %myappicon1.png%"MyApp1" Exec exec app1.sh
#AddToMenu MyCustomMenu %myappicon2.png%"MyApp2" Exec exec app2

#AddToMenu MenuFvwmRoot %myappicon3.png%"MyApp3" Exec exec /usr/bin/app3
#AddToMenu MenuFvwmRoot %mymenuicon.png%"MyMenu" Popup MyCustomMenu

# Horizontal line to separate menu items
#AddToMenu MenuFvwmRoot "" Nop
EOF
fi

if [ ! -f $PERMBOTTOM ] ; then
  cat > $PERMBOTTOM << EOF
# pdaXrom menu - custom top config file
# Here you can add menu items to the _bottom_ of the
# applications directories in the pdaXrom menu
#
# This file is created once and will be untouched when a new version of
# fvwm-pdaxrom is installed.

# Horizontal line to separate menu items
#AddToMenu MenuFvwmRoot "" Nop

#DestroyMenu MyCustomMenu
#AddToMenu MyCustomMenu %myappicon1.png%"MyApp1" Exec exec app1.sh
#AddToMenu MyCustomMenu %myappicon2.png%"MyApp2" Exec exec app2

#AddToMenu MenuFvwmRoot %myappicon3.png%"MyApp3" Exec exec /usr/bin/app3
#AddToMenu MenuFvwmRoot %mymenuicon.png%"MyMenu" Popup MyCustomMenu
EOF
fi

echo ''
echo 'Quit from X and execute startx to begin using Fvwm.'
echo 'If you remove this package, it restores your original window manager.'
echo -n 'Replacing the window manager with Fvwm...'
mv /home/root/.xinitrc /home/root/.xinitrc.mb
ln -s /usr/share/fvwm-pdaxrom/xinitrc /home/root/.xinitrc
echo ' done'

#if [ ! -e /home/root/.xinitrc ] ; then
#  echo 'ERROR: Unable to change default window manager to Fvwm.'
#  echo -n 'Switching back to the original...'
#  mv /home/root/.xinitrc.mb /home/root/.xinitrc
#  echo ' done'
#  exit 1
#fi
touch /home/root/.fvwm/welcome.runonce

if [ ! -d /home/root/.fvwm/personal/pixmaps ] ; then
  mkdir -p /home/root/.fvwm/personal/pixmaps
fi

