def _install_galaxy_config(tool_env, bin_dirs, env_vars):
    """
    Setup galaxy tool config files (env.sh-es) and default version
    symbolic links.
    """
    install_dir = tool_env["system_install"]
    env_path = os.path.join(install_dir, "env.sh")
    bin_paths = [os.path.join(install_dir, bin_dir) for bin_dir in bin_dirs]
    path_pieces = [bin_path for bin_path in bin_paths if env.safe_exists(bin_path)]
    if len(path_pieces) > 0 and not env.safe_exists(env_path):
        path_addtion = ":".join(path_pieces)
        # Standard bin install, just add it to path
        env.safe_sudo("echo 'PATH=%s:$PATH' > %s" % (path_addtion, env_path))
        venv_path = "%s/%s" % (install_dir, "venv")
        if env.safe_exists(venv_path):
            #  Have env.sh activate virtualdirectory
            env.safe_sudo("echo '. %s/bin/activate' >> %s" % (venv_path, env_path))
        env.safe_sudo("chmod +x %s" % env_path)
        for env_var, env_var_value in env_vars.iteritems():
            env_var_template = Template(env_var_value)
            expanded_env_var_value = env_var_template.substitute(tool_env)
            env.safe_sudo("echo 'export %s=%s' >> %s" % (env_var, expanded_env_var_value, env_path))
        env.logger.debug("Added Galaxy env.sh file: %s" % env_path)

    # TODO: If a direct install (i.e. tool_install_dir specified instead of galaxy_tools_dir)
    # default is still setup. This is not really desired.
    _set_default_config(tool_env, install_dir)
    if _read_boolean(tool_env, "autoload_galaxy_tools", False) and env.safe_exists(env_path):
        # In this case, the web user (e.g. ubuntu) should auto-load all of
        # galaxy's default env.sh files so they are available for direct use
        # as well.
        _add_to_profiles(". %s" % env_path, profiles=["~/.bashrc"])
dataset/ETHPy150Open chapmanb/cloudbiolinux/cloudbio/galaxy/tools.py/_install_galaxy_config/original