#!/usr/bin/env bash
echo "FIXME: does not start session on clean install, use lightdm until you fix this."

exit 0

set -x
DEST=${1:-/etc/skel}
USER_NAME=${2:-default}

cat > ${DEST}/.xinitrc <<'EOF'
DEFAULT_SESSION=enlightenment_start

session=$1

case $session in
    enlightenment     ) exec enlightenment_start ;;
    xfce|xfce4        ) exec startxfce4          ;;
    *                 ) exec $DEFAULT_SESSION    ;;
esac

if [ -d ${HOME}/.xinitrc.d ]; then
  for f in ${HOME}/.xinitrc.d/*; do
    [ -x "$f" ] && . "$f"
  done
  unset f
fi
EOF

# Set enlightenment as the default session.
apt install -y slim


## /etc/slim.conf
# login_cmd	exec /bin/bash -login /etc/X11/Xsession %session
# sessiondir	/usr/share/xsessions/ # contains enlightenment.desktop:Exec=/usr/bin/enlightenment and xfce.desktop:Exec=startxfce4
# default_user	devuan
auto_login=no
SLIM_CONFIG=/etc/slim.conf
#sed -i "s/^.*auto_login.*/auto_login\          no/"                        	${SLIM_CONFIG} && \
sed -i "s/^.*auto_login.*/auto_login\          ${auto_login}/"                  ${SLIM_CONFIG} && \
sed -i "s|^.*login_cmd.*|login_cmd exec /bin/sh - ~/.xinitrc \%session|" 	${SLIM_CONFIG} && \
sed -i "s/^.*default_user.*/default_user\ ${USER_NAME}/"  			${SLIM_CONFIG} && \
sed -i "/${sessiondir}/s/^/# /g" 						${SLIM_CONFIG} 
