#!/bin/bash -e

/usr/local/sbin/twofing-detect

if [ ! -f /etc/bbn-lite ]; then
  # this plugin needs systemd running during install
  apt-get -q -y install avnav-update-plugin || true
  systemctl restart avnav || true
fi

# Fix a bug documented somewhere in gentoo bug tracker
update-mime-database /usr/share/mime

# Keeping it enabled breaks wifi in nm-applet
systemctl disable dhcpcd.service || true

# Enable text login prompt on tty1 (Ctrl-Alt-F1)
systemctl enable getty@tty1

if [ -d /usr/local/share/aisdecoder ]; then
  if [ ! -f /usr/local/bin/aisdecoder ]; then
    pushd /usr/local/share/aisdecoder
      cd build
      # Moving to first-run due to this bug: https://gitlab.kitware.com/cmake/cmake/-/issues/20568
      cmake ../ -DCMAKE_BUILD_TYPE=RELEASE
      make -j 4
      cp aisdecoder /usr/local/bin/
      make clean
      cd ..
    popd
  fi
fi

if [ -x /usr/local/sbin/ufw-init ]
then
  /usr/local/sbin/ufw-init || true # Init firewall
fi

if [ -x /boot/first-boot.sh ]
then
  /boot/first-boot.sh || true
fi

touch /tmp/FIRSTRUN
systemctl disable firstRun.service
