#!/bin/bash

if [ "$UID" -ne "0" ]
then
  echo "You are NOT root"
else
  apt-get -y install xserver-xorg lxde lightdm lxappearance
  apt -y install build-essential module-assistant dkms wget

  cp /etc/apt/sources.list /etc/apt/sources.list.0

  echo -e \
  "deb http://archive.raspberrypi.org/debian/ buster main ui" | \
  tee -a /etc/apt/sources.list > /dev/null

  echo -e \
  "# deb-src http://archive.raspberrypi.org/debian/ buster main ui" | \
  tee -a /etc/apt/sources.list > /dev/null

  apt-get update

  cd /etc/apt/
  wget http://archive.raspberrypi.org/debian/raspberrypi.gpg.key
  apt-key add raspberrypi.gpg.key
  apt-get update
  apt-get -y upgrade
  apt-get -y install raspberrypi-ui-mods

  cp /etc/systemd/system/autologin@.service \
         /etc/systemd/system/autologin@.service.init

  cat /etc/systemd/system/autologin@.service.init | \
    perl -pe 's/ pi / it /' | \
    tee /etc/systemd/system/autologin@.service > /dev/null
  
  systemctl stop connman
  systemctl disable connman
fi
