Autostart.sh

autostart.sh is run on system startup. It can be used to run commands before XBMC/Kodi starts. To create it simple use nano

nano /storage/.config/autostart.sh

This script will hold up the boot process until it has completed, so if you want it run in the background the contents of your script should be encase like this

(
 some commands;
 some more commands
) &

nohup script.sh &

If you want to keep a shell script active in the background nohup cmd can be useful.

You can also access the file via the configfiles samba share.

/storage/.config/shutdown.sh

Depending on when you want your commands to run you need to put them in the proper location, or under the *) case if you want it run for any.

case "$1" in
  halt)
    # your commands here
    ;;
  poweroff)
    # your commands here
    ;;
  reboot)
    # your commands here
    ;;
  *)
    # your commands here
    ;;
esac

Please see the Useful Shell Scripts page for examples of extra functionality and behaviours that can be added into autostart.sh.