#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

if [ ! -e /expanded_rootfs ]; then
  touch /expanded_rootfs
  raspi-config nonint do_expand_rootfs
  reboot
fi

if [ -e /boot/firmware/config.txt ]; then
  FIRMWARE=/firmware
else
  FIRMWARE=
fi

# Make it so the files can be edited by cc3dsfs...
GROUP_NAME=boot_files
GID_GROUP=$(getent group ${GROUP_NAME} | cut -d: -f3)

umount /boot${FIRMWARE}
mount -o umask=002,gid=${GID_GROUP} /boot${FIRMWARE}

exit 0
