#!/bin/sh -e
# Including helpers
. /boot/ods-install/helpers.sh

# Sets ods user
log "Setting ods user ..."

ODS_USR=pi

# Removes boot message
log "Setting boot options in cmdline.txt ..."

cp /boot/cmdline.txt /boot/cmdline.back
cat > /boot/cmdline.txt << EOF
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty3 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait loglevel=0 logo.nologo vt.global_cursor_default=0 quiet splash plymouth.ignore-serial-consoles
EOF

# Sets up LXDE autostart
log "Configuring LXDE autostart ..."

rm -f /home/$ODS_USR/.config/lxsession/LXDE/autostart
cat >> /home/$ODS_USR/.config/lxsession/LXDE/autostart << EOF
@lxpanel --profile LXDE
@pcmanfm --desktop --profile LXDE
@xset s off
@xset -dpms
@xset s noblank
unclutter -display :0 -noevents -grab
@/usr/bin/chromium-browser --incognito --disable-translate --disable-infobars --no-first-run --kiosk http://localhost:4567/screen

EOF
chown $ODS_USR /home/$ODS_USR/.config/lxsession/LXDE/autostart

# Hides trash icon
log "Configuring LXDE desktop (Hiding trash icon) ..."

cat >> /home/$ODS_USR/.config/pcmanfm/LXDE/desktop-items-0.conf << EOF
[*]
wallpaper_mode=stretch
wallpaper_common=1
wallpaper=/etc/alternatives/desktop-background
desktop_bg=#000000
desktop_fg=#ffffff
desktop_shadow=#000000
desktop_font=Sans 12
folder=
show_wm_menu=0
sort=mtime;ascending;
show_documents=0
show_trash=0
show_mounts=0

EOF
chown $ODS_USR /home/$ODS_USR/.config/pcmanfm/LXDE/desktop-items-0.conf

# Hides task bar
log "Configuring LXDE desktop (Hiding task bar) ..."

cat >> /home/$ODS_USR/.config/lxpanel/LXDE/panels/panel << EOF
# lxpanel <profile> config file. Manually editing is not recommended.
# Use preference dialog in lxpanel to adjust config when you can.

Global {
  edge=bottom
  allign=left
  margin=0
  widthtype=percent
  width=100
  height=26
  transparent=0
  tintcolor=#000000
  alpha=0
  setdocktype=1
  setpartialstrut=1
  usefontcolor=1
  fontcolor=#ffffff
  background=1
  backgroundfile=/usr/share/lxpanel/images/background.png
  autohide=1
  heightwhenhidden=0
}
Plugin {
  type=space
  Config {
    Size=2
  }
}
Plugin {
  type=menu
  Config {
    image=/usr/share/lxde/images/lxde-icon.png
    system {
    }
    separator {
    }
    item {
      command=run
    }
    separator {
    }
    item {
      image=gnome-logout
      command=logout
    }
  }
}
Plugin {
  type=launchbar
  Config {
    Button {
      id=pcmanfm.desktop
    }
    Button {
      id=lxde-x-www-browser.desktop
    }
  }
}
Plugin {
  type=space
  Config {
    Size=4
  }
}
Plugin {
  type=wincmd
  Config {
    Button1=iconify
    Button2=shade
  }
}
Plugin {
  type=space
  Config {
    Size=4
  }
}
Plugin {
  type=pager
  Config {
  }
}
Plugin {
  type=space
  Config {
    Size=4
  }
}
Plugin {
  type=taskbar
  expand=1
  Config {
    tooltips=1
    IconsOnly=0
    AcceptSkipPager=1
    ShowIconified=1
    ShowMapped=1
    ShowAllDesks=0
    UseMouseWheel=1
    UseUrgencyHint=1
    FlatButton=0
    MaxTaskWidth=150
    spacing=1
  }
}
Plugin {
  type=cpu
  Config {
  }
}
Plugin {
  type=tray
  Config {
  }
}
Plugin {
  type=dclock
  Config {
    ClockFmt=%R
    TooltipFmt=%A %x
    BoldFont=0
    IconOnly=0
    CenterText=0
  }
}
Plugin {
  type=launchbar
  Config {
    Button {
      id=lxde-screenlock.desktop
    }
    Button {
      id=lxde-logout.desktop
    }
  }
}

EOF
chown $ODS_USR /home/$ODS_USR/.config/lxpanel/LXDE/panels/panel
