<commit_before>#!/bin/bash

# Parameters :
# $1 is the IP address of the bootstrap node
# $2 is the Chef environment name, default "Test-Laptop"

set -e
set -x

if [[ $# -ne 2 ]]; then
	echo "Usage: `basename $0` IP-Address Chef-Environment" >> /dev/stderr
	exit
fi

CHEF_SERVER=$1
CHEF_ENVIRONMENT=$2

# Assume we are running in the chef-bcpc directory
sudo /opt/chefdk/bin/chef-client -E "$CHEF_ENVIRONMENT" -c .chef/knife.rb
PEM_RELATIVE_PATH=.chef/$(hostname -f).pem
sudo chown $(whoami):root $PEM_RELATIVE_PATH
sudo chmod 550 $PEM_RELATIVE_PATH
[ ! -L /etc/chef/client.pem ] && \
  sudo ln -s $(readlink -f $PEM_RELATIVE_PATH) /etc/chef/client.pem
[ ! -L ~/.chef ] && \
  sudo ln -s $(readlink -f .chef) ~/.chef

admin_val=`sudo knife client show $(hostname -f) -c .chef/knife.rb | grep ^admin: | sed "s/admin:[^a-z]*//"`
if [[ "$admin_val" != "true" ]]; then
  # Make this client an admin user before proceeding.
  echo -e "/\"admin\": false\ns/false/true\nw\nq\n" | EDITOR=ed sudo -E knife client edit `hostname -f` -c .chef/knife.rb -k /etc/chef-server/admin.pem -u admin
fi

#
# build_bins.sh has already built the BCPC local repository, but we
# still need to configure Apache and chef-vault before doing a
# complete Chef run.
#
sudo -E /opt/chefdk/bin/chef-client \
     -c .chef/knife.rb \
     -o 'recipe[bcpc::apache-mirror]'

sudo -E /opt/chefdk/bin/chef-client \
     -c .chef/knife.rb \
     -o 'recipe[bcpc::chef_vault_install]'

sudo /opt/chefdk/bin/chef-client \
     -c .chef/knife.rb \
     -o 'recipe[bcpc::chef_poise_install]'


#
# For some reason that I don't understand,we need to do this before
# BCPC-Bootstrap so that we have os in the chef vault to allow bootstrap-gpg
# to be properly put inside the configs/Test-Laptop data bag as we aren't even installing the chef vault until after the first apt run
#
sudo -E /opt/chefdk/bin/chef-client \
     -c .chef/knife.rb \
     -o 'recipe[bach_repository::apt]'

<commit_msg>Generate bootstrap client key with "knife client"<commit_after>#!/bin/bash

# Parameters :
# $1 is the IP address of the bootstrap node
# $2 is the Chef environment name, default "Test-Laptop"

set -e
set -x

if [[ $# -ne 2 ]]; then
	echo "Usage: `basename $0` IP-Address Chef-Environment" >> /dev/stderr
	exit
fi

CHEF_SERVER=$1
CHEF_ENVIRONMENT=$2

sudo knife clean create $(hostname -f) -a -d -f .chef/$(hostname -f).pem \
  -u admin -k /etc/chef-server/admin.pem
PEM_RELATIVE_PATH=.chef/$(hostname -f).pem
sudo chown $(whoami):root $PEM_RELATIVE_PATH
sudo chmod 550 $PEM_RELATIVE_PATH

# Assume we are running in the chef-bcpc directory
sudo /opt/chefdk/bin/chef-client -E "$CHEF_ENVIRONMENT" -c .chef/knife.rb
[ ! -L /etc/chef/client.pem ] && \
  sudo ln -s $(readlink -f $PEM_RELATIVE_PATH) /etc/chef/client.pem
[ ! -L ~/.chef ] && \
  sudo ln -s $(readlink -f .chef) ~/.chef

#
# build_bins.sh has already built the BCPC local repository, but we
# still need to configure Apache and chef-vault before doing a
# complete Chef run.
#
sudo -E /opt/chefdk/bin/chef-client \
     -c .chef/knife.rb \
     -o 'recipe[bcpc::apache-mirror]'

sudo -E /opt/chefdk/bin/chef-client \
     -c .chef/knife.rb \
     -o 'recipe[bcpc::chef_vault_install]'

sudo /opt/chefdk/bin/chef-client \
     -c .chef/knife.rb \
     -o 'recipe[bcpc::chef_poise_install]'


#
# For some reason that I don't understand,we need to do this before
# BCPC-Bootstrap so that we have os in the chef vault to allow bootstrap-gpg
# to be properly put inside the configs/Test-Laptop data bag as we aren't even installing the chef vault until after the first apt run
#
sudo -E /opt/chefdk/bin/chef-client \
     -c .chef/knife.rb \
     -o 'recipe[bach_repository::apt]'


{'fraction_non_alphanumeric': 0.13918223666395885, 'fraction_numerical': 0.00487408610885459, 'mean_word_length': 3.178733031674208, 'pattern_counts': {'":': 1, '<': 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': '5297387', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1425, 'n_words': 420}