# vim: set filetype=sh :
#   copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2007-2021)
#     license: GNU General Public License, version 3
# mylib - customized usage of shellia

err()
{
  ia_exiterr 1 "ERROR: $*"
}

info()
{
  [ "$ia_use_silent" ] && ia_log "$@" || ia_logerr "$@"
}

log()
{
  ia_log "$@"
}

# MY_ADD <cmd>
# calls "ia_add <cmd>" and may call "ia_nocheck" before
MY_ADD()
{
  [ "$(echo "$1" | grep -e "<-i>")" ] && ia_nocheck
  ia_add "$1"
}

# log to /var/log/mylib/<script-name> if no other logging is done
if ! [ "$ia_logfile" -o "$ia_log_fd" ]; then
  if [ -w /var/log/mylib ]; then
    ia_logfile="${LOG_DIR:-/var/log/mylib}/$(basename $0)"
    [ -f $ia_logfile.2 ] && mv $ia_logfile.2 $ia_logfile.3
    [ -f $ia_logfile.1 ] && mv $ia_logfile.1 $ia_logfile.2
    [ -f $ia_logfile ] && mv $ia_logfile $ia_logfile.1
  else
    echo "mylib: please create writeable directory /var/log/mylib for logfiles" >&2
  fi
fi

# prefer a local copy of ia, if it exists
[ -f ia ] && . ./ia || . /usr/share/shellia/ia
