# There's a bug introduced by the solution of bug 8834:
# if you said "n" to $SHADOW_CONV, you ended up with the state pw/grpunconv
# left on dispelling old shadow.
# Introducing the temporary SHADOW_RECONV to support fixing that situation.

if [[ "$SHADOW_CONV" == n ]] && [[ -z "$SHADOW_RECONV" ]]; then
  message "Checking passwd for shadowness (there could have been an unwanted run of pwunconv/grpunconv, see bug #8834)." &&
  if ! grep -q '^root:x:' "$INSTALL_ROOT/etc/passwd"; then
    message "${PROBLEM_COLOR}Your passwd file contains password hashes, resuggesting conversion to shadow." &&
    message "${MESSAGE_COLOR}You can still say n to the upcoming query but make sure to run pwconv / grpconv yourself if you want existing passwords shadowed." &&
    config_query SHADOW_RECONV "One-time query: convert/fix accounts (with installed shadow utils) this time" n
  fi
else
  config_query SHADOW_CONV "Attempt to convert/fix accounts (with installed shadow utils)" n
fi &&
if [[ "$SHADOW_CONV" == y ]] || [[ "$SHADOW_RECONV" == y ]]; then
  message "OK, checking your user and group accounts" &&
  grpck -r ||
  {
    message "there are problems with group... runinng grpck 
interactively" &&
    grpck
  }
  pwck -q -r ||
  {
    message "there are problems with passwd... runinng pwpck 
interactively" &&
    pwck
  }
fi
# the tools give negative return even after successfully fixing stuff
true &&
# We are asking the user for the home directory base she likes.
# No TRACK_ROOT or anything, this is separate from the question where spell files reside or are executed from!
# Just a plain path as user chooses.
local default_home=/home/users &&
local old_home=$(grep '^HOME=' $INSTALL_ROOT/etc/default/useradd 2>/dev/null | sed 's/HOME=//') &&
if [[ -n "$old_home" ]]; then
  default_home=$old_home
fi &&
config_query_string SHADOW_HOME "base directory for user homes:" "$default_home"
