Hello,
Option A: Place your custom script it "/etc/config" directory. Its contents is untouched if firmware upgrade is done with "Keep setting" checkbox selected.
Option B: Place your custom script in any directory you like. Than open "/etc/config/sysupgrade.conf" file and enter path to script's directory. Directories, which will be listed in this file, will remain after firmware upgrade with "Keep settings" checkbox selected.