# Config
mkdir -p $PKG/usr/share/applications
cat $CWD/lxdm-config.desktop > $PKG/usr/share/applications/lxdm-config.desktop
cat $CWD/lxdm.conf > $PKG/etc/lxdm/lxdm.conf
mv $PKG/etc/lxdm/lxdm.conf $PKG/etc/lxdm/lxdm.conf.new
chmod 644 $PKG/etc/lxdm/lxdm.conf.new
cat $CWD/PostLogout > $PKG/etc/lxdm/PostLogout
cp $CWD/login.png $PKG/usr/share/lxdm/themes/Industrial/login.png
cp $CWD/greeter*.ui $PKG/usr/share/lxdm/themes/Industrial/
rm $PKG/usr/sbin/lxdm
cat $CWD/lxdm-launcher > $PKG/usr/sbin/lxdm
chmod 0755 $PKG/usr/sbin/lxdm
( cd $PKG/usr/sbin ; ln -s lxdm gdm )
cp $CWD/Xsession $PKG/etc/lxdm/Xsession
chmod 755 $PKG/etc/lxdm/Xsession

# Nice icon
mkdir -p $PKG/usr/share/icons/hicolor/scalable/apps/
cp $CWD/lxde.svg $PKG/usr/share/icons/hicolor/scalable/apps/

# Policykit
mkdir -p $PKG/usr/share/polkit-1/actions
cat << EOS > $PKG/usr/share/polkit-1/actions/org.freedesktop.policykit.pkexec.$NAME.policy
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
 "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
  
  <action id="org.freedesktop.policykit.pkexec.run-$NAME">
  <description>Run $NAME</description>
  <message>Authentication is required to run LXDM Config as Root</message>
  <defaults>
  <allow_any>no</allow_any>
  <allow_inactive>no</allow_inactive>
  <allow_active>yes</allow_active>
  </defaults>
  <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/lxdm-config</annotate>
  <annotate key="org.freedesktop.policykit.exec.allow_gui">TRUE</annotate>
  </action>
  
</policyconfig>
EOS

# Launcher
mkdir -p $PKG/usr/sbin

cat << "EOF" > $PKG/usr/sbin/lxdm-config
#!/bin/bash
if [ $(which pkexec) ]; then
	pkexec /usr/bin/env USER=$USER /usr/bin/lxdm-config "$@"
else
	/usr/bin/lxdm-config "$@"
fi
EOF
chmod -R 755 $PKG/usr/sbin/lxdm-config

# Pam config for elogind
cat $CWD/lxdm.pam > $PKG/etc/pam.d/lxdm



