#!/bin/bash

CURRENT="$(ls -1 /boot)"

apt update
#apt upgrade --yes

NEW="$(ls -1 /boot)"

if [ "$CURRENT" != "$NEW" ]; then
   echo "----------------------------------------------------------------------"
   echo "It looks like your kernel has been upgraded."
   echo "You should reboot and restart the build process."
   echo "----------------------------------------------------------------------"
   exit
fi

# if kernel was upgraded, you may need to reboot
apt-get install --yes --no-install-recommends mc squashfs-tools genisoimage zip unzip psmisc net-tools \
alsa-utils man less xz-utils ca-certificates openssl acpid acpi-support-base powermgmt-base bzip2 gpart \
hdparm sdparm mdadm smartmontools dosfstools lsof htop gddrescue rsync netcat ssh gpm wireless-tools \
ntfs-3g rfkill file dnsmasq ntpdate dvd+rw-tools usb-modeswitch pm-utils wget virt-what wpasupplicant connman

ln -sf bash /bin/sh

apt-get remove --yes vim* grub* debconf-i18n installation-report
apt-get autoremove --yes

CWD="$(pwd)"
cd /tmp
apt-get download acpi-support
dpkg -x acpi-support*.deb /tmp/acpisupport
cd /tmp/acpisupport
cp -aR * /
cp -aR lib/systemd /lib/
cd "$CWD"
