<commit_before>#!/usr/bin/env bash

# ./generate.sh -a foo=bar -a cow=truck -b /usr/local -c tgz -d distro -e duh.env -f Linux_GEO.zip -i 2 -l -m 21 -o out -p 4 -q -r b -s -u http://example.com -v 1.1.0

set -e

# Use readlink from GNU coreutils to set current working directory
if [[ "$(uname -s)" =~ Darwin* ]]; then
  # Available from Homebrew: default install prepends a 'g' before adding
  # it to the PATH.
  THIS_DIR="$(cd "$(dirname "$(greadlink -f "$BASH_SOURCE")")" && pwd)"
else
  THIS_DIR="$(cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" && pwd)"
fi

THIS_FILE="$(basename "${BASH_SOURCE[0]}")"

declare -A BUILD_ARGS

BUILD_DIR="$THIS_DIR/build"
GEO_H_PATCH_FILE="geo_h.patch"
GEOSUPPORT_MAJOR="21"
GEOSUPPORT_MINOR="2"
GEOSUPPORT_PATCH=
GEOSUPPORT_RELEASE="b"
GSD_VERSION="${GSD_VERSION:-latest}"

usage() {
cat <<- EOF

    Usage: ${THIS_FILE} [OPTIONS] [ACTIONS]

    Options:
      -a list       Docker build argument key=value pairs
      -b string     Geosupport base install directory (default /opt/geosupport)
      -c string     Compression format for repackaging the DCP Geosupport distro
                    'tgz':  gzip'd tar file (default)
                    'zip':  zip file
      -d string     Local directory containing DCP Geosupport distro zip files (default "dist")
      -e string     Environment file (default "release.env" if it exists)
      -f string     Name of Geosupport distro file (default "linux_geo<major><release><patch>_<major>_<minor>.zip")
      -h            Show this usage message and exit
      -i string     Geosupport minor version (required)
      -l            Download the Geosupport distro from DCP site. If given, takes precedence over "-d"
      -m string     Geosupport major version (required)
      -o string     Local bind mount directory for release artifacts (default "out")
      -p string     Geosupport patch version
      -q            Supress script output
      -r string     Geosupport release modifier (required)
      -s            Skip patching and inclusion of Geosupport header files
      -u string     URL of the Geosupport distro. If given, takes precedence over "-d" and "-l"
      -v string     Version of this project (default "latest")

    Actions:
      clean         Remove the local bind mount directory (see "-o" option).
                    If given, always first action to execute.

      deploy        [Not implemented] Deploy built image version to DockerHub.
                    If specified, always causes build action to run first, even
                    if not given on the command line.

      generate      Generate project source using *.template files.

      repackage     Repackage the Geosupport distro.

      run           Build and run generated source for pre-release verification.

EOF
}

die() {
    echo "$*" 1>&2
    exit 1
}

log() {
    local category="INFO"
    local message=""
    if [ $# -eq 1 ]; then
        message="$1"
    fi
    if [ $# -eq 2 ]; then
        category="$1"
        message="$2"
    fi
    printf '%s [%s] %s\n' "$(date --rfc-3339=seconds)" "$1" "$2"
}

clean() {
    log "CLEAN" "Removing build directory ${BUILD_DIR}..."
    rm -rf "${BUILD_DIR}" || die "Error: could not remove build directory ${BUILD_DIR}."
    log "CLEAN" "Build directory ${BUILD_DIR} removed."
}

deploy() {
    die "Warning: "deploy" action has not been implemented yet."
}

generate() {
    log "GENERATE" "Generating Docker files for version ${GSD_VERSION}..."
    log "GENERATE" "Generated  Docker files geosupport-deploy version ${GSD_VERSION}."
}

repackage() {

}

run() {

}

while [ $# -gt 0 ]; do
	# Necessary!
	OPTIND=1<commit_msg>Prefer greadlink. Die if not present on macos.<commit_after>#!/usr/bin/env bash

# ./generate.sh -a foo=bar -a cow=truck -b /usr/local -c tgz -d distro -e duh.env -f Linux_GEO.zip -i 2 -l -m 21 -o out -p 4 -q -r b -s -u http://example.com -v 1.1.0

set -e

die() {
    echo "$*" 1>&2
    exit 1
}

#
# Prefer readlink from GNU coreutils to set current working directory.
#
# NOTE to macos users:
#
#   On the macos, the BSD version of readlink is already installed
#   and used by the operating system. Sadly, this script is not designed
#   to work with the BSD version and this script will bail if the
#   GNU readlink (greadlink) is not available.
#
#   The good new is that GNU readlink is available from Homebrew which
#   install prepends a 'g' before adding it to the PATH.
#
if [[ -n "$(command -v greadlink)" ]]; then
  THIS_DIR="$(cd "$(dirname "$(greadlink -f "$BASH_SOURCE")")" && pwd)"
elif [[ "$(uname -s)" =~ Darwin* ]]; then
  die "[ERROR] GNU readlink (greadlink) not found."
else
  THIS_DIR="$(cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" && pwd)"
fi

THIS_FILE="$(basename "${BASH_SOURCE[0]}")"

declare -A BUILD_ARGS

BUILD_DIR="$THIS_DIR/build"
GEO_H_PATCH_FILE="geo_h.patch"
GEOSUPPORT_MAJOR="21"
GEOSUPPORT_MINOR="2"
GEOSUPPORT_PATCH=
GEOSUPPORT_RELEASE="b"
GSD_VERSION="${GSD_VERSION:-latest}"

usage() {
cat <<- EOF

    Usage: ${THIS_FILE} [OPTIONS] [ACTIONS]

    Options:
      -a list       Docker build argument key=value pairs
      -b string     Geosupport base install directory (default /opt/geosupport)
      -c string     Compression format for repackaging the DCP Geosupport distro
                    'tgz':  gzip'd tar file (default)
                    'zip':  zip file
      -d string     Local directory containing DCP Geosupport distro zip files (default "dist")
      -e string     Environment file (default "release.env" if it exists)
      -f string     Name of Geosupport distro file (default "linux_geo<major><release><patch>_<major>_<minor>.zip")
      -h            Show this usage message and exit
      -i string     Geosupport minor version (required)
      -l            Download the Geosupport distro from DCP site. If given, takes precedence over "-d"
      -m string     Geosupport major version (required)
      -o string     Local bind mount directory for release artifacts (default "out")
      -p string     Geosupport patch version
      -q            Supress script output
      -r string     Geosupport release modifier (required)
      -s            Skip patching and inclusion of Geosupport header files
      -u string     URL of the Geosupport distro. If given, takes precedence over "-d" and "-l"
      -v string     Version of this project (default "latest")

    Actions:
      clean         Remove the local bind mount directory (see "-o" option).
                    If given, always first action to execute.

      deploy        [Not implemented] Deploy built image version to DockerHub.
                    If specified, always causes build action to run first, even
                    if not given on the command line.

      generate      Generate project source using *.template files.

      repackage     Repackage the Geosupport distro.

      run           Build and run generated source for pre-release verification.

EOF
}

log() {
    local category="INFO"
    local message=""
    if [ $# -eq 1 ]; then
        message="$1"
    fi
    if [ $# -eq 2 ]; then
        category="$1"
        message="$2"
    fi
    printf '%s [%s] %s\n' "$(date --rfc-3339=seconds)" "$1" "$2"
}

clean() {
    log "CLEAN" "Removing build directory ${BUILD_DIR}..."
    rm -rf "${BUILD_DIR}" || die "Error: could not remove build directory ${BUILD_DIR}."
    log "CLEAN" "Build directory ${BUILD_DIR} removed."
}

deploy() {
    die "Warning: "deploy" action has not been implemented yet."
}

generate() {
    log "GENERATE" "Generating Docker files for version ${GSD_VERSION}..."
    log "GENERATE" "Generated  Docker files geosupport-deploy version ${GSD_VERSION}."
}

repackage() {
    log "REPACKAGE" "Repackaging DCP zip file."
}

run() {
    log "RUN" "Begining regeneration process."
}

while [ $# -gt 0 ]; do
	# Necessary!
	OPTIND=1
{'fraction_non_alphanumeric': 0.11311642094560244, 'fraction_numerical': 0.0068632435180477885, 'mean_word_length': 2.5670897552130554, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1138910', 'n_tokens_mistral': 2515, 'n_tokens_neox': 2418, 'n_words': 902}