def download_pack(
    pack,
    abs_repo_base="/opt/stackstorm/packs",
    verify_ssl=True,
    force=False,
    proxy_config=None,
    force_owner_group=True,
    force_permissions=True,
    logger=LOG,
):
    """
    Download the pack and move it to /opt/stackstorm/packs.

    :param abs_repo_base: Path where the pack should be installed to.
    :type abs_repo_base: ``str``

    :param pack: Pack name.
    :rtype pack: ``str``

    :param force_owner_group: Set owner group of the pack directory to the value defined in the
                              config.
    :type force_owner_group: ``bool``

    :param force_permissions: True to force 770 permission on all the pack content.
    :type force_permissions: ``bool``

    :param force: Force the installation and ignore / delete the lock file if it already exists.
    :type force: ``bool``

    :return: (pack_url, pack_ref, result)
    :rtype: tuple
    """
    proxy_config = proxy_config or {}

    try:
        pack_url, pack_version = get_repo_url(pack, proxy_config=proxy_config)
    except Exception as e:
        # Pack not found or similar
        result = [None, pack, (False, six.text_type(e))]
        return result

    result = [pack_url, None, None]

    temp_dir_name = hashlib.md5(
        pack_url.encode(), **hashlib_kwargs
    ).hexdigest()  # nosec. remove nosec after py3.8 drop
    lock_file = LockFile("/tmp/%s" % (temp_dir_name))
    lock_file_path = lock_file.lock_file

    if force:
        logger.debug("Force mode is enabled, deleting lock file...")

        try:
            os.unlink(lock_file_path)
        except OSError:
            # Lock file doesn't exist or similar
            pass

    with lock_file:
        try:
            user_home = os.path.expanduser("~")
            abs_local_path = os.path.join(user_home, ".st2packs", temp_dir_name)

            if pack_url.startswith("file://"):
                # Local pack
                local_pack_directory = os.path.abspath(
                    os.path.join(pack_url.split("file://")[1])
                )
            else:
                local_pack_directory = None

            # If it's a local pack which is not a git repository, just copy the directory content
            # over
            if local_pack_directory and not os.path.isdir(
                os.path.join(local_pack_directory, ".git")
            ):
                if not os.path.isdir(local_pack_directory):
                    raise ValueError(
                        'Local pack directory "%s" doesn\'t exist'
                        % (local_pack_directory)
                    )

                logger.debug(
                    "Detected local pack directory which is not a git repository, just "
                    "copying files over..."
                )

                shutil.copytree(local_pack_directory, abs_local_path)
            else:
                # 1. Clone / download the repo
                clone_repo(
                    temp_dir=abs_local_path,
                    repo_url=pack_url,
                    verify_ssl=verify_ssl,
                    ref=pack_version,
                )

            pack_metadata = get_pack_metadata(pack_dir=abs_local_path)
            pack_ref = get_pack_ref(pack_dir=abs_local_path)
            result[1] = pack_ref

            # 2. Verify that the pack version if compatible with current StackStorm version
            if not force:
                verify_pack_version(pack_metadata=pack_metadata)

            # 3. Move pack to the final location
            move_result = move_pack(
                abs_repo_base=abs_repo_base,
                pack_name=pack_ref,
                abs_local_path=abs_local_path,
                pack_metadata=pack_metadata,
                force_owner_group=force_owner_group,
                force_permissions=force_permissions,
                logger=logger,
            )
            result[2] = move_result
        finally:
            cleanup_repo(abs_local_path=abs_local_path)

    return tuple(result)

    Download the pack and move it to /opt/stackstorm/packs.

    :param abs_repo_base: Path where the pack should be installed to.
    :type abs_repo_base: ``str``

    :param pack: Pack name.
    :rtype pack: ``str``

    :param force_owner_group: Set owner group of the pack directory to the value defined in the
                              config.
    :type force_owner_group: ``bool``

    :param force_permissions: True to force 770 permission on all the pack content.
    :type force_permissions: ``bool``

    :param force: Force the installation and ignore / delete the lock file if it already exists.
    :type force: ``bool``

    :return: (pack_url, pack_ref, result)
    :rtype: tuple
    
st2common/st2common/util/pack_management.py