#!/bin/sh
# (c) Robert Shingledecker 2009-2010
# Adapted for Icewm
# Called from startx to setup initial icewm system  & tce menu

. /etc/init.d/tc-functions
. /usr/local/bin/icewm_menu_common

USER="$(cat /etc/sysconfig/tcuser)"
SYSDIR=/home/"$USER"/.icewm
[ -d "$SYSDIR" ] || mkdir -p "$SYSDIR"
cp -p /usr/local/share/icewm/menu "$SYSDIR"/.

if [ ! -f "$SYSDIR"/programs ]; then
	PROGRAMS="$SYSDIR"/programs
	echo "#Programs menu" >> "$PROGRAMS"
	echo "#Format: program menu_entry_name icon executable" >> "$PROGRAMS"
	echo "prog fltk-editor none fltk-editor" >> "$PROGRAMS"
	echo "prog xterm none xterm" >> "$PROGRAMS"
fi

if [ ! -f "$SYSDIR"/preferences ]; then
	cp -L /usr/local/share/icewm/preferences "$SYSDIR"
fi

if [ ! -f "$SYSDIR"/theme ]; then
	THEME="$SYSDIR"/theme
	echo "Theme="motif/default.theme"" >> "$THEME"
	killall -SIGHUP icewm
fi

TARGET="$SYSDIR"/menu
TMP="/tmp/icewm.$$"
TMP2="/tmp/icewm2.$$"

for D in `ls /usr/local/share/applications/tinycore-*`; do
   writeMenuItem "$D" >> "$TMP"
done
merge "$TMP" "$SYSDIR"/menu "End System" > "$TMP2"
mv "$TMP2" "$SYSDIR"/menu

icewm_ondemand

chown -R "$USER":staff "$SYSDIR"
chmod -R g+w "$SYSDIR"
rm "$TMP"
