#!/bin/bash

## %CopyrightBegin%
##
## SPDX-License-Identifier: Apache-2.0
##
## Copyright Ericsson AB 2026. All Rights Reserved.
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
##     http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
## %CopyrightEnd%

## If EX_DOC is not set to a file, we search the PATH for it using command -v
if [ ! -f "${EX_DOC}" ]; then
   EX_DOC=$(command -v ex_doc)
fi

if [ -z "${EX_DOC}" ]; then
    echo -n "Could not find ex_doc! "
    read -p "Do you want to download latest ex_doc from github? (y/n)? " -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]
    then
        if $ERL_TOP/otp_build download_ex_doc; then
            read -p "Press any key to continue..." -n 1 -r
            echo "continuing"
            EX_DOC=$(command -v ex_doc)
        else
            exit 1
        fi
    else
        exit 1
    fi
fi
