#!/bin/sh

set -e

if ! FWLOC=$(/usr/lib/raspberrypi-sys-mods/get_fw_loc); then
  echo "Could not determine firmware partition" >&2
  exit 1
fi

FOUND=0
for file in "$FWLOC/ssh" "$FWLOC/ssh.txt"; do
  [ -e "$file" ] || continue
  FOUND=1
  rm -f "$file"
done

if [ "$FOUND" = "1" ]; then
  systemctl enable --now --no-block ssh
fi

exit 0
