<commit_before>bash -c '
<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>

if [ ! -f /usr/bin/chef-client ]; then
  haveged -w 1024
  pacman-key --init
  pkill haveged
  pacman-key --populate archlinux
  pacman -Syu --noconfirm

  pacman -S --noconfirm --needed wget ruby base-devel expect ntp

  ntpdate -u pool.ntp.org

  mkdir -p /root/build/
  cd /root/build/
  wget https://aur.archlinux.org/packages/ru/ruby-bundler/ruby-bundler.tar.gz
  tar -xzvf ruby-bundler.tar.gz
  cd /root/build/ruby-bundler/
  makepkg -s -f --asroot --noconfirm
  pacman -U --noconfirm ./ruby-bundler-*.pkg.tar.xz

  mkdir -p /root/build/
  cd /root/build/
  wget https://aur.archlinux.org/packages/om/omnibus-chef-git/omnibus-chef-git.tar.gz
  tar -xzvf omnibus-chef-git.tar.gz
  cd /root/build/omnibus-chef-git
  makepkg -s -f --asroot --noconfirm

  expect -c "
    spawn pacman -U --noconfirm ./omnibus-chef-git-*.pkg.tar.xz
    expect {
      \"y/n\" { send \"y\r\"; exp_continue }
    }
    exit
  "
fi

mkdir -p /etc/chef

cat > /etc/chef/validation.pem <<'EOP'
<%= validation_key %>
EOP
chmod 0600 /etc/chef/validation.pem

<% if encrypted_data_bag_secret -%>
cat > /etc/chef/encrypted_data_bag_secret <<'EOP'
<%= encrypted_data_bag_secret %>
EOP
chmod 0600 /etc/chef/encrypted_data_bag_secret
<% end -%>

<%# Generate Ohai Hints -%>
<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
mkdir -p /etc/chef/ohai/hints

<% @chef_config[:knife][:hints].each do |name, hash| -%>
cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
<%= hash.to_json %><commit_msg>Adds prebuilt option<commit_after>bash -c '
<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>

if [ ! -f /usr/bin/chef-client ]; then
  haveged -w 1024
  pacman-key --init
  pkill haveged
  pacman-key --populate archlinux
  pacman -Syu --noconfirm

  pacman -S --noconfirm --needed wget ruby base-devel expect ntp

  ntpdate -u pool.ntp.org

  mkdir -p /root/build/
  cd /root/build/
  wget https://aur.archlinux.org/packages/ru/ruby-bundler/ruby-bundler.tar.gz
  tar -xzvf ruby-bundler.tar.gz
  cd /root/build/ruby-bundler/
  makepkg -s -f --asroot --noconfirm
  pacman -U --noconfirm ./ruby-bundler-*.pkg.tar.xz

  mkdir -p /root/build/
  cd /root/build/

  # Uncomment whichever option you prefer:
  
    # Option 1: Build the package from source
    # You'll get the latest omnibus-chef-git, but it will take a while
  
    #wget https://aur.archlinux.org/packages/om/omnibus-chef-git/omnibus-chef-git.tar.gz
    #tar -xzvf omnibus-chef-git.tar.gz
    #cd /root/build/omnibus-chef-git
    #makepkg -s -f --asroot --noconfirm

    # Faster alternative: Fetch an outdated package that has already been built
    wget https://github.com/logankoester/chef-bootstrap-archlinux-omnibus/blob/master/pkg/omnibus-chef-git-11.6.0.r272.g6c61ef2-1-any.pkg.tar.xz?raw=true
    
  expect -c "
    spawn pacman -U --noconfirm ./omnibus-chef-git-*.pkg.tar.xz
    expect {
      \"y/n\" { send \"y\r\"; exp_continue }
    }
    exit
  "
fi

mkdir -p /etc/chef

cat > /etc/chef/validation.pem <<'EOP'
<%= validation_key %>
EOP
chmod 0600 /etc/chef/validation.pem

<% if encrypted_data_bag_secret -%>
cat > /etc/chef/encrypted_data_bag_secret <<'EOP'
<%= encrypted_data_bag_secret %>
EOP
chmod 0600 /etc/chef/encrypted_data_bag_secret
<% end -%>

<%# Generate Ohai Hints -%>
<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
mkdir -p /etc/chef/ohai/hints

<% @chef_config[:knife][:hints].each do |name, hash| -%>
cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
<%= hash.to_json %>
{'fraction_non_alphanumeric': 0.16870084079197178, 'fraction_numerical': 0.010035259018171955, 'mean_word_length': 3.066152149944873, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 29, 'https://': 5, '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': '880123', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1501, 'n_words': 294}