<commit_before>#!/usr/bin/env bash
# Installs chef-client via the ombnibus installer (with minimal dependencies),
# and tries to converge twice: first, with just this runlist -
#     recipe[chef-client::config],recipe[chef-client::service]
# ; and then again with the full runlist.
set -e
test $UID == 0 || (echo "Error: must run as root"; exit 1)
echo "Installing Chef with ${0}..."

######### STEP 0: CONFIG, rendered by bootscript gem
NODE_NAME="<%= chef_attributes['chef_client']['config']['node_name'] %>"
CHEF_URL="<%= chef_attributes['chef_client']['config']['chef_server_url'] %>"
VALIDATION_PEM='<%= ramdisk_mount %>/chef/validation.pem'
DATABAG_SECRET='<%= ramdisk_mount %>/chef/encrypted_data_bag_secret'
CHEF_VERSION="<%= (defined? chef_version) ? chef_version : '' %>"
OMNIBUS_INSTALLER_URL="http://opscode.com/chef/install.sh"
CHEF_BIN="/usr/bin/chef-client" # Unix Chef omnibus always symlinks here
PID_FILE="/var/run/chef/client.pid"

######### STEP 1: MOVE CHEF SECRETS INTO PLACE
chmod 0600 "$VALIDATION_PEM"
if ! [ "$VALIDATION_PEM" == "/etc/chef/validation.pem" ] ; then
  ln -sf "$VALIDATION_PEM" "/etc/chef/validation.pem"
fi
if [ -e "$DATABAG_SECRET" ] ; then
  chmod 0600 "$DATABAG_SECRET"
  if ! [ "$DATABAG_SECRET" == "/etc/chef/encrypted_data_bag_secret" ] ; then
    ln -sf "$DATABAG_SECRET" "/etc/chef/encrypted_data_bag_secret"
  fi
fi

######### STEP 2: CONFIGURE OPERATING SYSTEM AND INSTALL DEPENDENCIES
echo "Performing package update..."
export DEBIAN_FRONTEND=noninteractive
apt-get update -y
echo "Installing build-essential and curl..."
apt-get --force-yes -y install build-essential curl

######### STEP 3: INSTALL CHEF VIA OMNIBUS INSTALLER
echo "Downloading Chef..."
installer=$(basename $OMNIBUS_INSTALLER_URL)
if ! (which $CHEF_BIN >/dev/null 2>&1) ; then
  if (which curl >/dev/null 2>&1); then
    curl -L -o $installer $OMNIBUS_INSTALLER_URL
  else
    echo "Cannot find curl - cannot download Chef!"
  fi
fi
cmd="bash $installer"
if ! [ "$CHEF_VERSION" == "" ] ; then
  cmd="$cmd -v ${CHEF_VERSION}"
fi
echo "Installing Chef..."
$cmd
rm -f $installer

######### STEP 4: INITIAL, ONE-PASS CHEF CONVERGENCE
echo "Performing initial convergence..."
INITIAL_RUNLIST="recipe[chef-client::config],recipe[chef-client::service]"
cmd="$CHEF_BIN --once --no-color -o $INITIAL_RUNLIST"
echo $cmd
$cmd

######### STEP 5: MANUAL CONVERGENCE ON FULL RUNLIST
# Signal Chef service to converge - not working
#if [ -f $PID_FILE ] ; then
#  PID=$(cat $PID_FILE)
#  echo "Signalling chef service (PID $PID) to converge..."
#  sleep 1
#  kill -USR1 $PID
#  kill -HUP $PID
#fi
echo "Manually executing full convergence..."
cmd="$CHEF_BIN --once --no-color"
echo $cmd
exec $cmd
<commit_msg>make dual-stage Chef convergence optional with :chef_initial_runlist<commit_after>#!/usr/bin/env bash
# Installs chef-client via the ombnibus installer (with minimal dependencies),
# and tries to converge twice: first, with just this runlist -
#     recipe[chef-client::config],recipe[chef-client::service]
# ; and then again with the full runlist.
set -e
test $UID == 0 || (echo "Error: must run as root"; exit 1)
echo "Installing Chef with ${0}..."

######### STEP 0: CONFIG, rendered by bootscript gem
NODE_NAME="<%= chef_attributes['chef_client']['config']['node_name'] %>"
CHEF_URL="<%= chef_attributes['chef_client']['config']['chef_server_url'] %>"
VALIDATION_PEM='<%= ramdisk_mount %>/chef/validation.pem'
DATABAG_SECRET='<%= ramdisk_mount %>/chef/encrypted_data_bag_secret'
CHEF_VERSION="<%= (defined? chef_version) ? chef_version : '' %>"
CHEF_INITIAL_RUNLIST="<%=
  (defined? chef_initial_runlist) ? chef_initial_runlist : '' %>"
OMNIBUS_INSTALLER_URL="http://opscode.com/chef/install.sh"
CHEF_BIN="/usr/bin/chef-client" # Unix Chef omnibus always symlinks here
PID_FILE="/var/run/chef/client.pid"

######### STEP 1: MOVE CHEF SECRETS INTO PLACE
chmod 0600 "$VALIDATION_PEM"
if ! [ "$VALIDATION_PEM" == "/etc/chef/validation.pem" ] ; then
  ln -sf "$VALIDATION_PEM" "/etc/chef/validation.pem"
fi
if [ -e "$DATABAG_SECRET" ] ; then
  chmod 0600 "$DATABAG_SECRET"
  if ! [ "$DATABAG_SECRET" == "/etc/chef/encrypted_data_bag_secret" ] ; then
    ln -sf "$DATABAG_SECRET" "/etc/chef/encrypted_data_bag_secret"
  fi
fi

######### STEP 2: CONFIGURE OPERATING SYSTEM AND INSTALL DEPENDENCIES
echo "Performing package update..."
export DEBIAN_FRONTEND=noninteractive
apt-get update -y
echo "Installing build-essential and curl..."
apt-get --force-yes -y install build-essential curl

######### STEP 3: INSTALL CHEF VIA OMNIBUS INSTALLER
echo "Downloading Chef..."
installer=$(basename $OMNIBUS_INSTALLER_URL)
if ! (which $CHEF_BIN >/dev/null 2>&1) ; then
  if (which curl >/dev/null 2>&1); then
    curl -L -o $installer $OMNIBUS_INSTALLER_URL
  else
    echo "Cannot find curl - cannot download Chef!"
  fi
fi
cmd="bash $installer"
if ! [ "$CHEF_VERSION" == "" ] ; then
  cmd="$cmd -v ${CHEF_VERSION}"
fi
echo "Installing Chef..."
$cmd
rm -f $installer

######### STEP 4: INITIAL, ONE-PASS CHEF CONVERGENCE
echo "Performing initial convergence..."
cmd="$CHEF_BIN --once --no-color"
if [[ "$CHEF_INITIAL_RUNLIST" != "" ]] ; then
  cmd="$cmd -o $CHEF_INITIAL_RUNLIST"
fi
echo $cmd
$cmd

######### STEP 5: SIGNAL SERVICE TO CONVERGE
echo "Signalling chef service to converge..."
killall -USR1 chef-client || echo "  (...no chef client service detected)"

echo "Done."

{'fraction_non_alphanumeric': 0.16326151560178306, 'fraction_numerical': 0.008358098068350668, 'mean_word_length': 4.87882096069869, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6598320', 'n_tokens_mistral': 2074, 'n_tokens_neox': 1935, 'n_words': 520}