Verified Commit 641f2e10 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

dep_scripts: Add --dry-run option

parent fb45f296
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ INSTALL_DIR=""
PERFORM_TEST=

EXECUTION_MODE=
DRY_RUN=false

DEFAULT_PROFILE="default"
DEFAULT_VERSION="latest"
@@ -49,10 +50,10 @@ declare -A PROFILE_CLONEDEPS_ARGS PROFILE_CLONEDEPS_PATCHES

usage_short() {
	echo "
usage: compile_dep.sh [ -p PROFILE_NAME[:PROFILE_VERSION] |
                        -d DEPENDENCY_NAME[[@PROFILE_NAME][:PROFILE_VERSION]] ]
                      [ -l [PROFILE_NAME:[PROFILE_VERSION]] ]
                      [ -j COMPILE_CORES] [ -h ]
usage: compile_dep.sh -p PROFILE_NAME[:PROFILE_VERSION] |
                      -d DEPENDENCY_NAME[[@PROFILE_NAME][:PROFILE_VERSION]] |
                      -l [PROFILE_NAME:[PROFILE_VERSION]] | -n | -h
                      [ -j COMPILE_CORES]
                      SOURCES_PATH INSTALL_PATH
	"
}
@@ -70,7 +71,7 @@ positional arguments:

optional arguments:
    -h, --help  shows this help message and exits
    -l, --list-dependencies
    -l, --list-dependencies [[PROFILE_NAME:]PROFILE_VERSION]
                list dependencies available for building and installation
    -p, --profile PROFILE_NAME[:PROFILE_VERSION]
                allows installing a pre-defined set of dependencies as defined
@@ -91,6 +92,8 @@ optional arguments:
                number of cores that are used to compile the dependencies
                defaults to number of available cores
    -t, --test  Perform libraries tests.
    -n, --dry-run
                Do not actually run, print only what would be done.
"
}

@@ -371,6 +374,10 @@ while [[ $# -gt 0 ]]; do
        exit
        #shift # past argument
        ;;
    -n | --dry-run)
        DRY_RUN=true
        shift
        ;;
    *) # unknown option
        POSITIONAL+=("$1") # save it in an array for later
        shift              # past argument
@@ -438,15 +445,17 @@ for dep_name in "${PROFILE_DEP_LIST[@]}"; do
    echo -e "\n\n######## Installing:  ${dep_name} ###############################\n"

    if [[ -f "${install_script}" ]]; then
        source "${install_script}"
        [[ "$DRY_RUN" == true ]] || source "${install_script}"
    else
        echo "WARNING: Install script for '${dep_name}' not found. Skipping."
        continue
    fi

    if [[ "$DRY_RUN" == false ]]; then
        pkg_install

        [ "${PERFORM_TEST}" ] && pkg_check
    fi

done

+28 −19
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ DEPENDENCY=""

EXECUTION_MODE=
VERBOSE=false
DRY_RUN=false

DEFAULT_PROFILE="default"
DEFAULT_VERSION="latest"
@@ -247,19 +248,19 @@ clonedeps() {
    local ACTION

    if [[ -d "${SOURCE_DIR}/${FOLDER}/.git" ]]; then
        cd "${SOURCE_DIR}/${FOLDER}" && git fetch -q
        [[ "$DRY_RUN" == true ]] || (cd "${SOURCE_DIR}/${FOLDER}" && git fetch -q)
        ACTION="Pulled"
    else
        git clone ${COMMON_GIT_FLAGS} ${GIT_FLAGS} -- "${REPO}" "${SOURCE_DIR}/${FOLDER}"
        [[ "$DRY_RUN" == true ]] || (git clone ${COMMON_GIT_FLAGS} ${GIT_FLAGS} -- "${REPO}" "${SOURCE_DIR}/${FOLDER}")
        ACTION="Cloned"
    fi
    # fix the version
    cd "${SOURCE_DIR}/${FOLDER}" && git checkout -qf "${COMMIT}"
    [[ "$DRY_RUN" == true ]] || (cd "${SOURCE_DIR}/${FOLDER}" && git checkout -qf "${COMMIT}")
    echo "${ACTION} '${REPO}' to '${FOLDER}' with commit '[${COMMIT}]' and flags '${GIT_FLAGS}'"

    # apply patch if provided
    if [[ -n "${PATCH}" ]]; then
        git apply --verbose "${PATCH_DIR}/${PATCH}"
        [[ "$DRY_RUN" == true ]] || git apply --verbose "${PATCH_DIR}/${PATCH}"
    fi
}

@@ -273,6 +274,8 @@ wgetdeps() {

    FOLDER=$1
    URL=$2

    if [[ "$DRY_RUN" == false ]]; then
        if [[ -d "${SOURCE_DIR}/${FOLDER}" ]]; then
            # SC2115 Use "${var:?}" to ensure this never expands to /* .
            rm -rf "${SOURCE_DIR:?}/${FOLDER:?}"
@@ -286,14 +289,15 @@ wgetdeps() {
        curl ${COMMON_CURL_FLAGS} "$URL" || error_exit "Failed to download ${URL}" $?
        tar -xf "$FILENAME" --directory "${SOURCE_DIR}/${FOLDER}" --strip-components=1
        rm -f "$FILENAME"
    fi
    echo "Downloaded '${URL}' to '${FOLDER}'"
}

usage_short() {
    echo "
usage: dl_dep.sh [ -p PROFILE_NAME[:PROFILE_VERSION] |
                   -d DEPENDENCY_NAME[[@PROFILE_NAME][:PROFILE_VERSION]] ]
                 [ -l [[PROFILE_NAME:]PROFILE_VERSION] ] [ -h ]
usage: dl_dep.sh -p PROFILE_NAME[:PROFILE_VERSION] |
                 -d DEPENDENCY_NAME[[@PROFILE_NAME][:PROFILE_VERSION]] |
                 -l [[PROFILE_NAME:]PROFILE_VERSION] | -n | -h
                 DESTINATION_PATH
	"
}
@@ -326,6 +330,7 @@ optional arguments:
                                option provided. If PROFILE_NAME is unspecified, the 'default'
                                profile will be used. Similarly, if PROFILE_VERSION is unspecified,
                                the 'latest' version of the specified profile will be used.
        -n, --dry-run           Do not actually run, print only what would be done.
        -v, --verbose           Increase download verbosity
        "
}
@@ -399,6 +404,10 @@ while [[ $# -gt 0 ]]; do
        VERBOSE=true
        shift # past argument
        ;;
    -n | --dry-run)
        DRY_RUN=true
        shift
        ;;
    *) # unknown option
        POSITIONAL+=("$1") # save it in an array for later
        shift              # past argument