<commit_before>log "setting system passwords for users"

ADMIN_PW=$(mdata-get admin_pw 2>/dev/null) || unset ADMIN_PW

if [ "${ADMIN_PW}" ] && \
   [ -e "$(type -p genbfpw)" ] && [ -e "$(type -p changepass)" ]; then
  if [[ ! "${ADMIN_PW}" =~ ^\$2a\$ ]]; then
    # Need to get a Blowfish hash first
    ADMIN_PW=$(genbfpw -p ${ADMIN_PW})
  fi
  echo "admin:${ADMIN_PW}" | changepass -e > /dev/null 2>&1 || \
    error "System 'admin' password change failed."
else
  passwd -N admin
fi

ROOT_PW=$(mdata-get root_pw 2>/dev/null) || unset ROOT_PW

if [ "${ROOT_PW}" ] && \
   [ -e "$(type -p genbfpw)" ] && [ -e "$(type -p changepass)" ]; then
  if [[ ! "${ROOT_PW}" =~ ^\$2a\$ ]]; then
    # Need to get a Blowfish hash first
    ROOT_PW=$(genbfpw -p ${ROOT_PW})
  fi
  echo "root:${ROOT_PW}" | changepass -e > /dev/null 2>&1 || \
    error "System 'root' password change failed."
else
  passwd -N root
fi<commit_msg>Simplify user password handling. Users are set in the USERS array (defaults to 'admin root') and used in a loop to pull respective password from metadata and set password (or remove password if not set). This way USERS can be set anywhere prior to 91-passwords.sh to change the default set of users that should be handled (setting USERS to an empty string will bypass the entire logic, which may or may not be desired).<commit_after>: ${USERS=admin root}
USERS=(${USERS})

for USER in ${USERS[@]}; do

  log "setting system password for user '${USER}'"
  PASS_VAR_LOWER=${USER}_pw
  PASS_VAR_UPPER=$(echo ${PASS_VAR_LOWER} | tr '[a-z]' '[A-Z]')

  USER_PW=${!PASS_VAR_UPPER}
  if [ ! ${USER_PW} ] && [ ${HAS_METADATA} ]; then
    USER_PW=$(mdata-get ${PASS_VAR_LOWER} 2>/dev/null) || unset USER_PW
  fi

  if [ "${USER_PW}" ] && \
     [ -e "$(type -p genbfpw)" ] && [ -e "$(type -p changepass)" ]; then
    if [[ ! "${USER_PW}" =~ ^\$2a\$ ]]; then
      # Need to get a Blowfish hash first
      USER_PW=$(genbfpw -p ${USER_PW})
    fi
    echo "${USER}:${USER_PW}" | changepass -e > /dev/null 2>&1 || \
      error "System password change for '${USER}' failed."
  else
    passwd -N ${USER}
  fi
done
{'fraction_non_alphanumeric': 0.17469310670443816, 'fraction_numerical': 0.0066100094428706326, 'mean_word_length': 3.3333333333333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '6119825', 'n_tokens_mistral': 811, 'n_tokens_neox': 755, 'n_words': 252}