<commit_before>#!/bin/bash -e

##################
# IMPLEMENTATION #
##################

function displayUsage()
{
    local -r scriptName="$(basename "${BASH_SOURCE[0]}")"

    echo -e '\033[1;33m'
    echo    'SYNOPSIS :'
    echo    "  ${scriptName}"
    echo    '    --help'
    echo    '    --cask-package-names    <CASK_PACKAGE_NAMES>'
    echo    '    --package-names         <PACKAGE_NAMES>'
    echo -e '\033[1;35m'
    echo    'DESCRIPTION :'
    echo    '  --help                  Help page (optional)'
    echo    '  --cask-package-names    List of cask package names seperated by spaces or commas (require)'
    echo    '  --package-names         List of package names seperated by spaces or commas (require)'
    echo -e '\033[1;36m'
    echo    'EXAMPLES :'
    echo    "  ./${scriptName} --help"
    echo    "  ./${scriptName} --cask-package-names 'chefdk, java' --package-names 'tree, wget'"
    echo    "  ./${scriptName} --cask-package-names 'chefdk, java'"
    echo    "  ./${scriptName} --package-names 'tree, wget'"
    echo -e '\033[0m'

    exit "${1}"
}

function installDependencies()
{
    if [[ "$(existCommand 'brew')" = 'false' ]]
    then
        "$(dirname "${BASH_SOURCE[0]}")/../cookbooks/brew/recipes/install.bash" 'true'
    fi
}

function installBrewPackage()
{
    local -r packageType="${1}"
    local -r packageNames="${2}"

    # Get App Name List

    local packageNameList=()

    IFS=$',' read -a packageNameList <<< "${packageNames}"

    # Each Package Name

    local packageName=''

    for packageName in "${packageNameList[@]}"
    do
        # Pre Install

        if [[ -f "$(dirname "${BASH_SOURCE[0]}")/../cookbooks/${packageName}/recipes/pre-install.bash" ]]
        then
            header "PRE-INSTALLING PACKAGE $(tr '[:lower:]' '[:upper:]' <<< "${packageName}")"
            sudo "$(dirname "${BASH_SOURCE[0]}")/../cookbooks/${packageName}/recipes/pre-install.bash"
        fi

        # Install

        if [[ "${packageType}" = 'cask' ]]
        then
            header "INSTALLING CASK PACKAGE $(tr '[:lower:]' '[:upper:]' <<< "${packageName}")"

            brew "${packageType}" reinstall --force "${packageName}"
            displayVersion "$(brew "${packageType}" list --versions "${packageName}")"
        else
            header "INSTALLING BREW PACKAGE $(tr '[:lower:]' '[:upper:]' <<< "${packageName}")"

            brew reinstall "${packageName}"
            displayVersion "$(brew list --versions "${packageName}")"
        fi

        # Post Install

        if [[ -f "$(dirname "${BASH_SOURCE[0]}")/../cookbooks/${packageName}/recipes/post-install.bash" ]]
        then
            header "POST-INSTALLING PACKAGE $(tr '[:lower:]' '[:upper:]' <<< "${packageName}")"
            sudo "$(dirname "${BASH_SOURCE[0]}")/../cookbooks/${packageName}/recipes/post-install.bash"
        fi
    done

    if [[ "${#packageNameList[@]}" -gt '0' ]]
    then
        sudo "$(dirname "${BASH_SOURCE[0]}")/clear-app-extended-attributes.bash"
    fi
}

function install()
{
    local -r caskPackageNames="${1}"
    local -r packageNames="${2}"

    # Upgrade Brew

    "$(dirname "${BASH_SOURCE[0]}")/upgrade-brew.bash"

    # Install Packages

    installBrewPackage 'cask' "${caskPackageNames}"
    installBrewPackage '' "${packageNames}"

    # Clean Up
<commit_msg>bug fixes<commit_after>#!/bin/bash -e

##################
# IMPLEMENTATION #
##################

function displayUsage()
{
    local -r scriptName="$(basename "${BASH_SOURCE[0]}")"

    echo -e '\033[1;33m'
    echo    'SYNOPSIS :'
    echo    "  ${scriptName}"
    echo    '    --help'
    echo    '    --cask-package-names    <CASK_PACKAGE_NAMES>'
    echo    '    --package-names         <PACKAGE_NAMES>'
    echo -e '\033[1;35m'
    echo    'DESCRIPTION :'
    echo    '  --help                  Help page (optional)'
    echo    '  --cask-package-names    List of cask package names seperated by spaces or commas (require)'
    echo    '  --package-names         List of package names seperated by spaces or commas (require)'
    echo -e '\033[1;36m'
    echo    'EXAMPLES :'
    echo    "  ./${scriptName} --help"
    echo    "  ./${scriptName} --cask-package-names 'chefdk, java' --package-names 'tree, wget'"
    echo    "  ./${scriptName} --cask-package-names 'chefdk, java'"
    echo    "  ./${scriptName} --package-names 'tree, wget'"
    echo -e '\033[0m'

    exit "${1}"
}

function installDependencies()
{
    if [[ "$(existCommand 'brew')" = 'false' ]]
    then
        "$(dirname "${BASH_SOURCE[0]}")/../cookbooks/brew/recipes/install.bash" 'true'
    fi
}

function installBrewPackage()
{
    local -r packageType="${1}"
    local -r packageNames="${2}"

    # Get App Name List

    local packageNameList=()

    IFS=$',' read -a packageNameList <<< "${packageNames}"

    # Each Package Name

    local packageName=''

    for packageName in "${packageNameList[@]}"
    do
        # Pre Install

        if [[ -f "$(dirname "${BASH_SOURCE[0]}")/../cookbooks/${packageName}/recipes/pre-install.bash" ]]
        then
            header "PRE-INSTALLING PACKAGE $(tr '[:lower:]' '[:upper:]' <<< "${packageName}")"
            sudo "$(dirname "${BASH_SOURCE[0]}")/../cookbooks/${packageName}/recipes/pre-install.bash"
        fi

        # Install

        if [[ "${packageType}" = 'cask' ]]
        then
            header "INSTALLING CASK PACKAGE $(tr '[:lower:]' '[:upper:]' <<< "${packageName}")"

            brew "${packageType}" reinstall --force "${packageName}"
            displayVersion "$(brew "${packageType}" list --versions "${packageName}")"
        else
            header "INSTALLING BREW PACKAGE $(tr '[:lower:]' '[:upper:]' <<< "${packageName}")"

            brew reinstall "${packageName}"
            displayVersion "$(brew list --versions "${packageName}")"
        fi

        # Post Install

        if [[ -f "$(dirname "${BASH_SOURCE[0]}")/../cookbooks/${packageName}/recipes/post-install.bash" ]]
        then
            header "POST-INSTALLING PACKAGE $(tr '[:lower:]' '[:upper:]' <<< "${packageName}")"
            sudo "$(dirname "${BASH_SOURCE[0]}")/../cookbooks/${packageName}/recipes/post-install.bash"
        fi
    done

    if [[ "${packageType}" = 'cask' && "${#packageNameList[@]}" -gt '0' ]]
    then
        sudo "$(dirname "${BASH_SOURCE[0]}")/clear-app-extended-attributes.bash"
    fi
}

function install()
{
    local -r caskPackageNames="${1}"
    local -r packageNames="${2}"

    # Upgrade Brew

    "$(dirname "${BASH_SOURCE[0]}")/upgrade-brew.bash"

    # Install Packages

    installBrewPackage 'cask' "${caskPackageNames}"
    installBrewPackage '' "${packageNames}"

    # Clean Up

{'fraction_non_alphanumeric': 0.19338422391857507, 'fraction_numerical': 0.010776829815895825, 'mean_word_length': 2.498429319371728, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3502414', 'n_tokens_mistral': 2227, 'n_tokens_neox': 2113, 'n_words': 481}