init_environment.sh: update, refactoring and compatibility fixes.