Alternative, you might be interested in the auto configure functionality of RetroArch: essentially, it changes the input settings depending on the controllers that are currently plugged in and supports hotplugging. You can find more information about that at
https://github.com/libretro/RetroArch/wiki/RGUI (quite at the bottom that site)
I never found time to have a deeper look into that, but I think that it might even be worth to be included into the RetroPie Script. Any help here would be greatly appreciated!