<commit_before>#!/bin/bash
set -eu

function create_user {
  local USER_NAME="$1"

  # If user doesnot exist, try to create it.
  if ! id -u "$USER_NAME" >/dev/null 2>&1; then
    useradd -m -G vcap,bosh_sudoers -s /bin/bash "$USER_NAME"
  fi
}

function inject_key {
  local USER_NAME="$1"
  local USER_KEY="$2"

  local USER_HOME=/home/"$USER_NAME"
  mkdir -p "$USER_HOME"/.ssh
  echo "$USER_KEY" > "$USER_HOME"/.ssh/authorized_keys
  chown -R "$USER_NAME:$USER_NAME" "$USER_HOME"/.ssh
  chmod 700 "$USER_HOME"/.ssh
  chmod 600 "$USER_HOME"/.ssh/authorized_keys
}

function remove_keys {
  # BOOM
  rm -f /home/*/.ssh/authorized_keys
}

remove_keys
<% p('shrc.extra_users').each do | user |
  username = user['name']
  userkey = user['public_key']

  # Regex for sanity check
  name_regex = /^[a-z_][a-z0-9_.-]{0,30}$/
  key_regex = /^ssh-rsa AAAA[0-9A-Za-z\/+]+[=]{0,3}[0-9A-Za-z@_.- ]*$/

  if username.match(name_regex) %>
create_user "<%= username %>"
<%  if (not userkey.nil?) and userkey.match(key_regex) %>
inject_key "<%= username %>" "<%= userkey %>"
<%  end
  end
end %><commit_msg>10L: stupid regex<commit_after>#!/bin/bash
set -eu

function create_user {
  local USER_NAME="$1"

  # If user doesnot exist, try to create it.
  if ! id -u "$USER_NAME" >/dev/null 2>&1; then
    useradd -m -G vcap,bosh_sudoers -s /bin/bash "$USER_NAME"
  fi
}

function inject_key {
  local USER_NAME="$1"
  local USER_KEY="$2"

  local USER_HOME=/home/"$USER_NAME"
  mkdir -p "$USER_HOME"/.ssh
  echo "$USER_KEY" > "$USER_HOME"/.ssh/authorized_keys
  chown -R "$USER_NAME:$USER_NAME" "$USER_HOME"/.ssh
  chmod 700 "$USER_HOME"/.ssh
  chmod 600 "$USER_HOME"/.ssh/authorized_keys
}

function remove_keys {
  # BOOM
  rm -f /home/*/.ssh/authorized_keys
}

remove_keys
<% p('shrc.extra_users').each do | user |
  username = user['name']
  userkey = user['public_key']

  # Regex for sanity check
  name_regex = /^[a-z_][a-z0-9_.-]{0,30}$/
  key_regex = /^ssh-rsa AAAA[0-9A-Za-z\/+]+[=]{0,3}[ 0-9A-Za-z@_.-]*$/

  if username.match(name_regex) %>
create_user "<%= username %>"
<%  if (not userkey.nil?) and userkey.match(key_regex) %>
inject_key "<%= username %>" "<%= userkey %>"
<%  end
  end
end %>
{'fraction_non_alphanumeric': 0.19206204379562045, 'fraction_numerical': 0.020985401459854013, 'mean_word_length': 3.616842105263158, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, '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': '1197096', 'n_tokens_mistral': 981, 'n_tokens_neox': 895, 'n_words': 187}