##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
## Fonctions de base: initialisation de l'environnement
##@cooked nocomments
uprovide base.init

# Emplacement du script courant
if [ -n "$UTOOLS_HAVE_SCRIPTVARS" ]; then
    # ne pas mettre à jour script, scriptname, scriptdir. Ils ont déjà été
    # calculés
    :
elif [ "$0" == "-bash" ]; then
    scriptname=
    scriptdir=
    script=
elif [ ! -f "$0" -a -f "${0#-}" ]; then
    scriptname="$(basename -- "${0#-}")"
    scriptdir="$(dirname -- "${0#-}")"
    scriptdir="$(cd "$scriptdir"; pwd)"
    script="$scriptdir/$scriptname"
else
    scriptname="$(basename -- "$0")"
    scriptdir="$(dirname -- "$0")"
    scriptdir="$(cd "$scriptdir"; pwd)"
    script="$scriptdir/$scriptname"
fi
: "${ULIBDIR:=$scriptdir}"

# Repertoire temporaire
[ -z "$TMPDIR" -a -d "$HOME/tmp" ] && TMPDIR="$HOME/tmp"
export TMPDIR="${TMPDIR:-${TMP:-${TEMP:-/tmp}}}"

# User
[ -z "$USER" -a -n "$LOGNAME" ] && export USER="$LOGNAME"

# Le fichier nutoolsrc doit être chargé systématiquement
[ -f /etc/debian_chroot ] && UTOOLS_CHROOT=1
[ -f /etc/nutoolsrc ] && . /etc/nutoolsrc
[ -f ~/.nutoolsrc ] && . ~/.nutoolsrc

# Type de système sur lequel tourne le script
UNAME_SYSTEM=`uname -s`
[ "${UNAME_SYSTEM#CYGWIN}" != "$UNAME_SYSTEM" ] && UNAME_SYSTEM=Cygwin
[ "${UNAME_SYSTEM#MINGW32}" != "$UNAME_SYSTEM" ] && UNAME_SYSTEM=Mingw
UNAME_MACHINE=`uname -m`
if [ -n "$UTOOLS_CHROOT" ]; then
    # Dans un chroot, il est possible de forcer les valeurs
    [ -n "$UTOOLS_UNAME_SYSTEM" ] && eval "UNAME_SYSTEM=$UTOOLS_UNAME_SYSTEM"
    [ -n "$UTOOLS_UNAME_MACHINE" ] && eval "UNAME_MACHINE=$UTOOLS_UNAME_MACHINE"
fi
