<commit_before>#!/bin/bash

defaultkey="/home/nic/.ssh/openstack_rsa"
host="$1"

SSH=$(which ssh)

which fping && fping $host

if [[ -z $2 ]]
  then
    echo "using key from $defaultkey key"
    cloudkey="$defaultkey"
  else
    cloudkey="$2"
fi

if [[ -f "${cloudkey}" ]]
  then
    SSHOPTIONS="-o UserKnownHostsFile=/dev/null"
    SSHOPTIONS="$SSHOPTIONS -o PasswordAuthentication=no"
    SSHOPTIONS="$SSHOPTIONS -o StrictHostKeyChecking=no"
    SSHOPTIONS="$SSHOPTIONS -F /dev/null"
    SSHOPTIONS="$SSHOPTIONS -i${cloudkey}"
    SSHOPTIONS="$SSHOPTIONS -q -tt"
    for user in cirros centos ubuntu
    do
      CMD="$SSH ${SSHOPTIONS} -l ${user} ${host} sudo whoami"
      # echo "trying $CMD"
      ruser=$(${CMD})
      if [[ "$ruser" =~ "root" ]]
        then
          echo "succeeded with user ${user}"
          xuser="${user}"
        else
          echo "failed with user ${user}"
      fi
    done
  else
    echo "the cloud key file (${cloudkey}) was not found"
fi

if [[ -z $xuser ]]
  then
    echo "all logins failed"
  else
    echo "login succeeded with '$xuser'"
fi<commit_msg>working recruit/check-cloud-init.sh with password login too - debug verbosity<commit_after>#!/bin/bash

    defaultkey="/home/nic/.ssh/openstack_rsa"
    host="$1"


attempt_login() {

# assumes that $host and $user is already set
# if $key is set then try key authentication
# otherwise  if $passwd is set try password authentication

    if [[ -z "$user" ]]
      then echo "user not set!"
      exit
    fi

    if [[ -z "$host" ]]
      then echo "user not set!"
      exit
    fi

    SSHOPTIONS="-q -tt"
    SSHOPTIONS="$SSHOPTIONS -o UserKnownHostsFile=/dev/null"
    SSHOPTIONS="$SSHOPTIONS -o StrictHostKeyChecking=no"
    SSHOPTIONS="$SSHOPTIONS -F /dev/null"

    CMD="$(which ssh)"
    if [[ -n "$key" ]]
      then
        XOPTS="-i${key} -o PasswordAuthentication=no"
      elif [[ -n "$passwd" ]]
      then
        XOPTS="-o PasswordAuthentication=yes"
        which sshpass || ( echo "please install sshpass" ; exit )
        CMD="$(which sshpass) -p $passwd $CMD"
      else
        echo "attempt_login called with neither\$key nor \$passwd set"
        return 1
    fi

    # only get here if we have a key or a password

    XCMD="${CMD} ${SSHOPTIONS} ${XOPTS} -l ${user} ${host} sudo whoami"
    ruser=$(${XCMD})

    if [[ "$ruser" =~ "root" ]]
      then
        echo "attempt_login() succeeded with user ${user}"
        return 0
      else
        echo "attempt_login() failed with user ${user}"
        return 1
    fi
}

which fping && fping $host

if [[ -z $2 ]]
  then
    echo "using key from $defaultkey key"
    cloudkey="$defaultkey"
  else
    cloudkey="$2"
fi

if [[ -f "${cloudkey}" ]]
  then
    key="${cloudkey}"
    for user in cirros centos ubuntu
    do
      if attempt_login
        then
          echo "succeeded with user ${user}"
          xuser="${user}"
          break
        else
          echo "failed with user ${user}"
      fi
    done
  else
    echo "the cloud key file (${cloudkey}) was not found"
fi
if [[ -z "$xuser" ]]
  then
    echo "trying password based login"
    unset key
    passwd="<PASSWORD>"
    user="root"
    if attempt_login
      then
        echo "succeeded with user ${user}"
        xuser="${user}"
      else
        echo "failed with user ${user}"
    fi
fi

if [[ -z $xuser ]]
  then
    echo "all logins failed"
  else
    echo "login succeeded with '$xuser'"
fi
{'fraction_non_alphanumeric': 0.1347661922741795, 'fraction_numerical': 0.00261399941911124, 'mean_word_length': 2.379784102060844, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1047602', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1148, 'n_words': 355}