<file_sep>#!/usr/bin/env bash
#
# Bootstrap Script
#
# bin/bootstrap:  Resolve all dependencies the application requires to run.

set -e

MISSING=0
RED='\033[0;31m'
#GREEN='\033[0;32m'
NC='\033[0m' # No Color

cd "$(dirname "$0")/.."

# Ensure Homebrew dependencies are installed if using a Brewfile
if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ]; then
  brew bundle check >/dev/null 2>&1 || {
    echo "==> Installing Homebrew dependencies..."
    brew bundle
  }
fi

# Ensure Elixir is installed
command -v elixir >/dev/null 2>&1 || {
  echo -e "${RED}This app requires Elixir, but it was not found on your system.${NC}"
  echo -e "${RED}Install it using the instructions at http://elixir-lang.org${NC}"
  echo ""
  MISSING=$((MISSING + 1))
}

# Ensure Node.js is installed if this is a phoenix application
if [ -f "package.json" ]; then
  # Ensure Node.js is installed
  command -v npm >/dev/null 2>&1 || {
    echo -e "${RED}This app requires Node.js to build assets, but it was not found on your system.${NC}"
    echo -e "${RED}Install it using the instructions at http://nodejs.org${NC}"
    echo ""
    MISSING=$((MISSING + 1))
  }
fi

if [ $MISSING -gt 0 ]
then
  exit 1
fi

if [ -f "mix.exs" ]; then
  # Ensure Hex is installed
  command -v mix hex >/dev/null 2>&1 || {
    mix local.hex --force
  }

  # Ensure Rebar is installed
  if [ ! -f "$HOME/.mix/rebar3" ]; then
    mix local.rebar --force
  fi

  # Install Mix dependencies
  mix deps.get || { echo -e "${RED}Mix dependencies could not be installed!${NC}"; exit 1; }

fi

if [ -f "package.json" ]; then
  npm install || { echo -e "${RED}Node dependencies could not be installed!${NC}"; exit 1; }
fi
<file_sep>#!/usr/bin/env bash
#
# Build Script
#
# bin/build: Build the escript file for this application. 

set -e

cd "$(dirname "$0")/.."

# Ensure everything in the app is up to date.
bin/update

echo "Buiding CLI application..."

cd apps/fallout_hacker_cli

# Run the main function
mix escript.build

cd ../..
 
<file_sep>#!/usr/bin/env bash
#
# Update Script
#
# bin/update:  Update application to run for its current checkout.

set -e

cd "$(dirname "$0")/.."

bin/bootstrap

# Update the DB
#echo "==> Updating the DB..."

# Update DB.
#mix ecto.migrate
<file_sep># FalloutHacker

This application attempts to help you with the hacking mini-game that is featured
in the Fallout game series.  

This mini-game essentially gives you a list of possible passwords and four tries
to guess the password. An incorrect guess will give  likeness score which is the
number of characters that match. If all four tries get used, the terminal becomes
locked permanently.  I highly recommend you quick save before hacking.

This application allows you to enter all the passwords separated by spaces.
It will show an error if the words are not all the same length.  If they are the
same length, then it will give a "best" guess for you to try.  You are then
prompted for the likeness score for your guess.  This repeats until the password
is found.

## Example
```
  $ bin/run

  Enter possible passwords:  foo bar baz
  Your best guess is "BAR".
  Enter likeness:  2
  The password is "BAZ".
```

## The Algorithm

The algorithm for finding a password is pretty basic.   Each word is given a
score by calculating the likeness with all words in the list. For example, `FOO`
would get scores of `[3, 0, 0]`. The final score for a word is the number of
unique likenesses.  `FOO` has the unique likenesses of `[3, 0]` or a score of `2`.
The final scores for each word would be: `FOO=2, BAR=3, BAZ=3`. The "best" guess
returned is the result with the highest score.

Once a likeness is provided, the list of possible passwords gets filtered and the
password or a new "best" guess is returned.  

I put "best" in quotes because there are better algorithms to use but this one is
simple and generally works.  Upgrade your hacking perk and remember to quick save
and this should work just fine.
<file_sep>#!/usr/bin/env bash
#
# tmux Script
#
# bin/tmux:  Open tmux with windows for a full dev environment.

set -e

MISSING=0
RED='\033[0;31m'
#GREEN='\033[0;32m'
NC='\033[0m' # No Color

TMUX_SESS=fallhack-dev

cd "$(dirname "$0")/.."

command -v tmux >/dev/null 2>&1 || {
  echo -e "${RED}This app requires tmux, but it was not found on your system.${NC}"
  MISSING=$((MISSING + 1))
}

command -v vim >/dev/null 2>&1 || {
  echo -e "${RED}This app requires vim, but it was not found on your system.${NC}"
  MISSING=$((MISSING + 1))
}

command -v mix >/dev/null 2>&1 || {
  echo -e "${RED}This app requires mix, but it was not found on your system.${NC}"
  MISSING=$((MISSING + 1))
}

if [ $MISSING -gt 0 ]
then
  exit 1
fi

# Create tmux session
tmux new -s $TMUX_SESS -n $(pwd) -d

# Rename bash window
tmux rename-window -t "$TMUX_SESS:1" "bash"

# Open a vim window
tmux new-window -t "$TMUX_SESS:2" -n "vim" "vim $(pwd)"

# Open a test window
tmux new-window -t "$TMUX_SESS:3" -n "test" "mix test.watch"

# Select vim window
tmux select-window -t:2

# Attach to tmux session
tmux attach -t $TMUX_SESS

<file_sep>#!/usr/bin/env bash
#
# CiBuild Script
#
# bin/cibuild:  Setup environment for CI to run tests.

set -e

cd "$(dirname "$0")/.."

echo "Tests started at…"
date "+%H:%M:%S"

export MIX_ENV="test"

# run tests
echo "Running tests …"
date "+%H:%M:%S"

# run tests.
bin/test
<file_sep>#!/usr/bin/env bash
#
# Setup Script
#
# bin/setup:  Setup application for the first time after cloning, or set it
#          back to the initial first unused state.

set -e

cd "$(dirname "$0")/.."

bin/bootstrap

# Setup the DB
#echo "==> Setting up the DB..."

# Reset DB to a fresh state.
#mix ecto.reset

echo "==> App is now ready to go!"
<file_sep>#!/usr/bin/env bash
#
# Test Watch Script
#
# bin/watch:  Run tests continuously on file change.

set -e

cd "$(dirname "$0")/.."

[ -z "$DEBUG" ] || set -x

# Ensure everything in the app is up to date.
bin/update

echo "==> Running tests…"
mix test.watch
<file_sep>#!/usr/bin/env bash
#
# Run Script
#
# bin/run:  Launch the application and any extra required processes locally.

set -e

RED='\033[0;31m'
#GREEN='\033[0;32m'
NC='\033[0m' # No Color

cd "$(dirname "$0")/.."

# Ensure everything in the app is up to date.
bin/update

echo "Running application..."
echo ""

# Run the main function
case "$1" in
CLI|cli|"")
  mix run -e "FalloutHacker.CLI.main(true)"
  ;;
*)
  echo -e "${RED}Unrecognized command: $1${NC}"
esac
<file_sep>#!/usr/bin/env bash
#
# Console Script
#
# bin/console:  Launch a console for the application.

set -e

cd "$(dirname "$0")/.."

# Ensure everything in the app is up to date.
bin/update

# Run IEx console
iex -S mix
