<commit_before>#!/usr/bin/env bash
# Exit on first error and output commands
set -e
set -x

# Placeholder for `sed` injection of `data_dir`
# DATA_DIR_PLACEHOLDER

# Verify we have a data_dir variable set
if test "$data_dir" = ""; then
  echo "Environment variable \`data_dir\` wasn't set when calling \`bootstrap.sh\`." 1>&2
  echo "Please verify it is set before running it." 1>&2
  echo "Example: \`data_dir=\"/vagrant/data\"; . bin/bootstrap.sh\`" 1>&2
  exit 1
fi

# If ruby-install isn't installed, then install it
# DEV: Required for `chef-zero` due to `ruby>=2.0.0` dependency
if ! which ruby-install &> /dev/null; then
  wget -O ruby-install-0.6.0.tar.gz https://github.com/postmodern/ruby-install/archive/v0.6.0.tar.gz
  tar -xzvf ruby-install-0.6.0.tar.gz
  cd ruby-install-0.6.0/
  sudo make install
fi

# If we haven't updated apt-get, then update it now
# TODO: Consider a CLI flag to install external Ruby or not
#   http://rubies.travis-ci.org/ubuntu/14.04/x86_64/ruby-2.2.4
# TODO: Also explore apt option -- seems dead. might be able to with another box but would prefer dodging system level
# DEV: Required for `ruby-install`
if ! test -f .updated-apt-get; then
  sudo apt-get update
  touch .updated-apt-get
fi

# If we haven't installed ruby@2.x.x, then install it
# DEV: Required for `chef-zero` due to `ruby>=2.0.0` dependency
if ! test -d /home/vagrant/.rubies/ruby-2.2.4; then
  ruby-install ruby 2.2.4
fi

# If chef-zero isn't installed, then install it
# TODO: Handle misaligned versions
if ! test -f ~/.rubies/ruby-2.2.4/bin/chef-zero; then
  ~/.rubies/ruby-2.2.4/bin/gem install chef-zero --version 4.4.0
fi

# TODO: Remove me when Chef dev is over
echo "Development for Chef going on" 1>&2
exit 0

# If we haven't updated apt-get, then update it now
# TODO: Use timestamp to update it on a schedule (e.g. 1 day)
#   https://github.com/twolfson/twolfson.com-scripts/blob/150de4af2778e577ca3d57dab74b6dd7a0e1a55f/bin/bootstrap.sh#L6-L14
# TODO: Maybe build a function like `update_apt_get` used by other functions?
if ! test -f .updated-apt-get; then
  sudo apt-get update
  touch .updated-apt-get
fi

# If the timezone isn't as we expect, then update it now
# https://www.digitalocean.com/community/questions/how-to-change-the-timezone-on-ubuntu-14
# http://serverfault.com/a/84528
if test "$(date +"%z")" != "+0000"; then
  sudo chown root:root "$data_dir/etc/timezone"
  sudo chmod u=rw,g=r,o=r "$data_dir/etc/timezone"
  sudo cp --preserve "$data_dir/etc/timezone" /etc/timezone
  sudo dpkg-reconfigure --frontend noninteractive tzdata
fi

# If there is no ubuntu user, then create them
# DEV: Digital Ocean's Ubuntu images provision us as the root user so we must create an ubuntu user
# https://github.com/mizzy/specinfra/blob/v2.47.0/lib/specinfra/command/base/user.rb#L3-L5
# https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-14-04
# https://www.digitalocean.com/community/tutorials/how-to-edit-the-sudoers-file-on-ubuntu-and-centos
if ! id ubuntu &> /dev/null; then
  # Create password-less `ubuntu` user with metadata "Ubuntu"<commit_msg>Deciding to use prebuilt Travis CI ruby@2.x.x for speed<commit_after>#!/usr/bin/env bash
# Exit on first error and output commands
set -e
set -x

# Placeholder for `sed` injection of `data_dir`
# DATA_DIR_PLACEHOLDER

# Verify we have a data_dir variable set
if test "$data_dir" = ""; then
  echo "Environment variable \`data_dir\` wasn't set when calling \`bootstrap.sh\`." 1>&2
  echo "Please verify it is set before running it." 1>&2
  echo "Example: \`data_dir=\"/vagrant/data\"; . bin/bootstrap.sh\`" 1>&2
  exit 1
fi

# If `ruby@2.x.x` isn't installed, then install it
# DEV: Required for `chef-zero` due to `ruby>=2.0.0` dependency
# TODO: Figure out location -- prob keep it consistent with system `ruby-install`
if false; then
  # Download `ruby@2.2.4` prebuilt for Ubuntu@14.04 by Travis CI
  # http://rubies.travis-ci.org/ubuntu/14.04/x86_64/ruby-2.2.4
  cd /tmp
  wget https://rubies.travis-ci.org/ubuntu/14.04/x86_64/ruby-2.2.4.tar.bz2
  tar xzf ruby-2.2.4.tar.bz2

  # TODO: Verify SHA1 checksum

  # TODO: Install to `$PATH`?
fi

# If chef-zero isn't installed, then install it
# TODO: Handle misaligned versions
# if ! test -f ~/.rubies/ruby-2.2.4/bin/chef-zero; then
#   ~/.rubies/ruby-2.2.4/bin/gem install chef-zero --version 4.4.0
# fi

# TODO: Remove me when Chef dev is over
echo "Development for Chef going on" 1>&2
exit 0

# If we haven't updated apt-get, then update it now
# TODO: Use timestamp to update it on a schedule (e.g. 1 day)
#   https://github.com/twolfson/twolfson.com-scripts/blob/150de4af2778e577ca3d57dab74b6dd7a0e1a55f/bin/bootstrap.sh#L6-L14
# TODO: Maybe build a function like `update_apt_get` used by other functions?
if ! test -f .updated-apt-get; then
  sudo apt-get update
  touch .updated-apt-get
fi

# If the timezone isn't as we expect, then update it now
# https://www.digitalocean.com/community/questions/how-to-change-the-timezone-on-ubuntu-14
# http://serverfault.com/a/84528
if test "$(date +"%z")" != "+0000"; then
  sudo chown root:root "$data_dir/etc/timezone"
  sudo chmod u=rw,g=r,o=r "$data_dir/etc/timezone"
  sudo cp --preserve "$data_dir/etc/timezone" /etc/timezone
  sudo dpkg-reconfigure --frontend noninteractive tzdata
fi

# If there is no ubuntu user, then create them
# DEV: Digital Ocean's Ubuntu images provision us as the root user so we must create an ubuntu user
# https://github.com/mizzy/specinfra/blob/v2.47.0/lib/specinfra/command/base/user.rb#L3-L5
# https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-14-04
# https://www.digitalocean.com/community/tutorials/how-to-edit-the-sudoers-file-on-ubuntu-and-centos
if ! id ubuntu &> /dev/null; then
  # Create password-less `ubuntu` user with metadata "Ubuntu"
{'fraction_non_alphanumeric': 0.13360810578739482, 'fraction_numerical': 0.035720419027992445, 'mean_word_length': 3.742671009771987, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 12, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '574216', 'n_tokens_mistral': 2335, 'n_tokens_neox': 2107, 'n_words': 619}