# GreenOS shell environment variables for config mode
# should be sourced from /etc/default/greenos

# note that session environment is now handled separately.
# (see /etc/bash_completion.d/20greenos-cfg)

{
declare -x -r GREENOS_CFG_GROUP_NAME=greenoscfg
declare -x -r HISTIGNORE="*password*:*-secret*"
} 2>/dev/null || :

# don't set level if already set
if [ -n "$GREENOS_USER_LEVEL_DIR" ]; then
  return
fi
{
is_admin=0
is_users=0
GREENOS_LEVEL_GROUP_ADMIN=greenoscfg
GREENOS_LEVEL_GROUP_USERS=frrvty
local -a groups=( $(id -Gn) )
for g in "${groups[@]}"; do
  if [ "$g" == "$GREENOS_LEVEL_GROUP_ADMIN" ]; then
    is_admin=1
  fi
  if [ "$g" == "$GREENOS_LEVEL_GROUP_USERS" ]; then
    is_users=1
  fi
done
# root is also admin
if [ "$(id -u)" == 0 ]; then
  is_admin=1
fi
# check level from high to low
if [ $is_admin == 1 ]; then
  declare -x -r GREENOS_USER_LEVEL_DIR=${greenos_sysconfdir}/shell/level/admin
else
  # no need to check is_users since there are only 2 levels for now
  declare -x -r GREENOS_USER_LEVEL_DIR=${greenos_sysconfdir}/shell/level/users
  declare -x -r LESSSECURE=1
  alias more=less
fi
} 2>/dev/null || :

