<commit_before># -*- mode: bash; tab-width: 2; -*-
# vim: ts=2 sw=2 ft=bash noet

# Copy the compiled jars into the app directory to run live
publish_release() {
	nos_print_bullet "Moving build into live app directory..."
	rsync -a $(nos_code_dir)/ $(nos_app_dir)
}

# Determine the elixir runtime to install. This will first check
# within the boxfile.yml, then will rely on default_runtime to
# provide a sensible default
runtime() {
  echo $(nos_validate \
    "$(nos_payload "config_runtime")" \
    "string" "$(default_runtime)")
}

# Provide a default elixir version.
default_runtime() {
  echo "elixir-1.4"
}

# Determine the erlang runtime to install. This will first check
# within the boxfile.yml, then will rely on default_erlang_runtime to
# provide a sensible default
erlang_runtime() {
  echo $(nos_validate \
    "$(nos_payload "config_erlang_runtime")" \
    "string" "$(default_erlang_runtime)")
}

# Provide a default erlang version.
default_erlang_runtime() {
  echo "erlang-19"
}

# Install the elixir and erlang runtime along with any dependencies.
install_runtime_packages() {
  pkgs=("$(erlang_runtime)" "$(runtime)")
  
  # add any client dependencies
  pkgs+=("$(query_dependencies)")

  nos_install ${pkgs[@]}
}

# Elixir is built on the erlang ecosystem, which allows for processes
# to be attached to remotely. This engine tries to make this process
# simple, and has created a handful of scripts to facilitate in this.
install_helper_scripts() {
	# generate the files
	nos_template_file \
		'bin/node-start' \
		$(nos_data_dir)/bin/node-start
		
	nos_template_file \
		'bin/node-attach' \
		$(nos_data_dir)/bin/node-attach
		
	# chmod them
	chmod +x $(nos_data_dir)/bin/node-start
	chmod +x $(nos_data_dir)/bin/node-attach
}

# Uninstall build dependencies
uninstall_build_packages() {
  # currently elixir doesn't install any build-only deps... I think
  pkgs=()

  # if pkgs isn't empty, let's uninstall what we don't need
  if [[ ${#pkgs[@]} -gt 0 ]]; then
    nos_uninstall ${pkgs[@]}
  fi
}

# compiles a list of dependencies that will need to be installed
query_dependencies() {
  deps=()

  # mysql
	if [[ `grep 'mysql\|maria' $(nos_code_dir)/mix.exs` ]]; then
		deps+=(mysql-client)
	fi
  # memcache
	if [[ `grep 'memcache' $(nos_code_dir)/mix.exs` ]]; then
		deps+=(libmemcached)
	fi
  # postgres
	if [[ `grep 'postgrex' $(nos_code_dir)/mix.exs` ]]; then
		deps+=(postgresql94-client)
	fi
  # redis
	if [[ `grep 'red\|yar\|verk' $(nos_code_dir)/mix.exs` ]]; then
		deps+=(redis)
	fi
  
  echo "${deps[@]}"
}

# install hex locally
install_hex() {
	cd $(nos_code_dir)
	nos_run_process "Installing hex" \
		"mix local.hex --force"
	cd - >/dev/null
}

# install rebar locally
install_rebar() {
	cd $(nos_code_dir)
	nos_run_process "Installing rebar" \
		"mix local.rebar --force"
	cd - >/dev/null<commit_msg>Copy symbolic links as directories for release<commit_after># -*- mode: bash; tab-width: 2; -*-
# vim: ts=2 sw=2 ft=bash noet

# Copy the compiled jars into the app directory to run live
publish_release() {
	nos_print_bullet "Moving build into live app directory..."
	rsync -a -k $(nos_code_dir)/ $(nos_app_dir)
}

# Determine the elixir runtime to install. This will first check
# within the boxfile.yml, then will rely on default_runtime to
# provide a sensible default
runtime() {
  echo $(nos_validate \
    "$(nos_payload "config_runtime")" \
    "string" "$(default_runtime)")
}

# Provide a default elixir version.
default_runtime() {
  echo "elixir-1.4"
}

# Determine the erlang runtime to install. This will first check
# within the boxfile.yml, then will rely on default_erlang_runtime to
# provide a sensible default
erlang_runtime() {
  echo $(nos_validate \
    "$(nos_payload "config_erlang_runtime")" \
    "string" "$(default_erlang_runtime)")
}

# Provide a default erlang version.
default_erlang_runtime() {
  echo "erlang-19"
}

# Install the elixir and erlang runtime along with any dependencies.
install_runtime_packages() {
  pkgs=("$(erlang_runtime)" "$(runtime)")

  # add any client dependencies
  pkgs+=("$(query_dependencies)")

  nos_install ${pkgs[@]}
}

# Elixir is built on the erlang ecosystem, which allows for processes
# to be attached to remotely. This engine tries to make this process
# simple, and has created a handful of scripts to facilitate in this.
install_helper_scripts() {
	# generate the files
	nos_template_file \
		'bin/node-start' \
		$(nos_data_dir)/bin/node-start

	nos_template_file \
		'bin/node-attach' \
		$(nos_data_dir)/bin/node-attach

	# chmod them
	chmod +x $(nos_data_dir)/bin/node-start
	chmod +x $(nos_data_dir)/bin/node-attach
}

# Uninstall build dependencies
uninstall_build_packages() {
  # currently elixir doesn't install any build-only deps... I think
  pkgs=()

  # if pkgs isn't empty, let's uninstall what we don't need
  if [[ ${#pkgs[@]} -gt 0 ]]; then
    nos_uninstall ${pkgs[@]}
  fi
}

# compiles a list of dependencies that will need to be installed
query_dependencies() {
  deps=()

  # mysql
	if [[ `grep 'mysql\|maria' $(nos_code_dir)/mix.exs` ]]; then
		deps+=(mysql-client)
	fi
  # memcache
	if [[ `grep 'memcache' $(nos_code_dir)/mix.exs` ]]; then
		deps+=(libmemcached)
	fi
  # postgres
	if [[ `grep 'postgrex' $(nos_code_dir)/mix.exs` ]]; then
		deps+=(postgresql94-client)
	fi
  # redis
	if [[ `grep 'red\|yar\|verk' $(nos_code_dir)/mix.exs` ]]; then
		deps+=(redis)
	fi

  echo "${deps[@]}"
}

# install hex locally
install_hex() {
	cd $(nos_code_dir)
	nos_run_process "Installing hex" \
		"mix local.hex --force"
	cd - >/dev/null
}

# install rebar locally
install_rebar() {
	cd $(nos_code_dir)
	nos_run_process "Installing rebar" \
		"mix local.rebar --force"
	cd - >/dev/null
{'fraction_non_alphanumeric': 0.13248162408120406, 'fraction_numerical': 0.0035001750087504373, 'mean_word_length': 4.062001771479185, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1144797', 'n_tokens_mistral': 2093, 'n_tokens_neox': 2006, 'n_words': 584}