Compatibility improvements

Added various improvements as suggested by @JessThrysoee

- Use 'type' instead of 'which'
- Added OPTS var to reduce duplicated code
- Use 'exec -cl bash' for a 'clean' bash shell
- Added HOME=/root for 'sh' shell