<commit_before>#!/bin/bash -e

__bootstrap_state() {
  __process_msg "injecting empty machines array"
  local machines=$(cat $STATE_FILE | \
    jq '.machines=[]')
  _update_state "$machines"

  __process_msg "injecting empty master integrations"
  local master_integrations=$(cat $STATE_FILE | \
    jq '.masterIntegrations=[]')
  _update_state "$master_integrations"

  __process_msg "injecting empty system integrations"
  local system_integrations=$(cat $STATE_FILE | \
    jq '.systemIntegrations=[]')
  _update_state "$system_integrations"

  __process_msg "injecting empty services array"
  local services=$(cat $STATE_FILE | \
    jq '.services=[]')
  _update_state "$services"
}

__validate_args() {
  __process_marker "Validating arguments"

  ################## set IS_UPGRADE #############################
  if [ "$IS_UPGRADE" == "" ]; then
    __process_error "IS_UPGRADE not set, exiting"
    exit 1
  else
    __process_msg "Running an upgrade: $IS_UPGRADE"
  fi

  ################## set SHIPPABLE_VERSION ########################
  local state_release_version=$(cat $STATE_FILE \
    | jq -r '.release')

  if [ $IS_UPGRADE == true ];then
    ## Running an upgrade, empty release version means error
    if [ "$state_release_version" == "" ]; then
      __process_error "No 'release' value defined in statefile, existing"
      exit 1
    else
      SHIPPABLE_VERSION=$release_version
      __process_msg "Release version present for an upgrade, skipping bootstrap"
      __process_msg "Shippable version: $SHIPPABLE_VERSION"
    fi
  else
    ## Running a fresh install, empty release version is ok
    if [ "$state_release_version" == "" ]; then
      __process_msg "bootstrapping state.json for latest release"
      __bootstrap_state
      local release=$(cat $STATE_FILE \
        | jq '.release="'"$SHIPPABLE_VERSION"'"')
      _update_state "$release"
      __process_msg "Shippable release version: $SHIPPABLE_VERSION"
    else
      __process_msg "using existing state.json for version: $SHIPPABLE_VERSION"
    fi
  fi

  __process_msg "Shippable release version: $SHIPPABLE_VERSION"

  ################## set  INSTALL_MODE ##########################
  local state_install_mode=$(cat $STATE_FILE \
    | jq -r '.installMode')

  if [ $IS_UPGRADE == true ]; then
    # if doing an upgrade, use installMode from state file<commit_msg>release version does not change on reinstall<commit_after>#!/bin/bash -e

__bootstrap_state() {
  __process_msg "injecting empty machines array"
  local machines=$(cat $STATE_FILE | \
    jq '.machines=[]')
  _update_state "$machines"

  __process_msg "injecting empty master integrations"
  local master_integrations=$(cat $STATE_FILE | \
    jq '.masterIntegrations=[]')
  _update_state "$master_integrations"

  __process_msg "injecting empty system integrations"
  local system_integrations=$(cat $STATE_FILE | \
    jq '.systemIntegrations=[]')
  _update_state "$system_integrations"

  __process_msg "injecting empty services array"
  local services=$(cat $STATE_FILE | \
    jq '.services=[]')
  _update_state "$services"
}

__validate_args() {
  __process_marker "Validating arguments"

  ################## set IS_UPGRADE #############################
  # Always set IS_UPGRADE from cmd line args

  if [ "$IS_UPGRADE" == "" ]; then
    __process_error "IS_UPGRADE not set, exiting"
    exit 1
  else
    __process_msg "Running an upgrade: $IS_UPGRADE"
  fi

  ################## set SHIPPABLE_VERSION ########################
  # for upgrade, there MUST be a previous release version
  local state_release_version=$(cat $STATE_FILE \
    | jq -r '.release')

  if [ $IS_UPGRADE == true ];then
    ## Running an upgrade, empty release version means error
    if [ "$state_release_version" == "" ]; then
      __process_error "No 'release' value defined in statefile, exiting.
      Run installer from scratch to update release version."
      exit 1
    else
      __process_msg "Release version present for an upgrade, skipping bootstrap"
    fi
  else
    ## Running a fresh install, empty release version means bootstrap statefile
    if [ "$state_release_version" == "" ]; then
      __process_msg "bootstrapping state.json for latest release"
      __bootstrap_state
    else
      __process_msg "Release version present for an install, skipping bootstrap"
    fi
  fi

  local release=$(cat $STATE_FILE \
    | jq '.release="'"$SHIPPABLE_VERSION"'"')
  _update_state "$release"

  __process_msg "Shippable release version: $SHIPPABLE_VERSION"

  ################## set  INSTALL_MODE ##########################
  local state_install_mode=$(cat $STATE_FILE \
    | jq -r '.installMode')

  if [ $IS_UPGRADE == true ]; then
    # if doing an upgrade, use installMode from state file
{'fraction_non_alphanumeric': 0.14667508417508418, 'fraction_numerical': 0.0008417508417508417, 'mean_word_length': 4.072572038420491, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5792848', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1390, 'n_words': 404}