maj bash
This commit is contained in:
parent
5f15e1ea8c
commit
2e8d0ac010
2
.udir
2
.udir
|
@ -9,7 +9,7 @@ uinc_options=()
|
|||
uinc_args=()
|
||||
preconfig_scripts=()
|
||||
configure_variables=(dest)
|
||||
configure_dest_for=(lib/profile.d/nucore)
|
||||
configure_dest_for=(lib/profile.d/nulib)
|
||||
config_scripts=(lib/uinst/conf)
|
||||
install_profiles=true
|
||||
profiledir=lib/profile.d
|
||||
|
|
|
@ -7,9 +7,9 @@ function: local_args "Afficher des commandes pour rendre locales des variables u
|
|||
Cela permet d'utiliser parse_args() à l'intérieur d'une fonction."
|
||||
function local_args() {
|
||||
echo "local args"
|
||||
echo "local NUCORE_ARGS_ONERROR_RETURN=1"
|
||||
echo "local NUCORE_VERBOSITY=\"\$NUCORE_VERBOSITY\""
|
||||
echo "local NUCORE_INTERACTION=\"\$NUCORE_INTERACTION\""
|
||||
echo "local NULIB_ARGS_ONERROR_RETURN=1"
|
||||
echo "local NULIB_VERBOSITY=\"\$NULIB_VERBOSITY\""
|
||||
echo "local NULIB_INTERACTION=\"\$NULIB_INTERACTION\""
|
||||
}
|
||||
|
||||
function: parse_args "Analyser les arguments de la ligne de commande à partir des définitions du tableau args
|
||||
|
@ -98,9 +98,9 @@ action
|
|||
optdesc
|
||||
: description de l'option. cette valeur est facultative"
|
||||
function parse_args() {
|
||||
[ -z "$NUCORE_NO_DISABLE_SET_X" ] && [[ $- == *x* ]] && { set +x; local NUCORE_ARGS_SET_X=1; }
|
||||
[ -z "$NULIB_NO_DISABLE_SET_X" ] && [[ $- == *x* ]] && { set +x; local NULIB_ARGS_SET_X=1; }
|
||||
local __r=
|
||||
local __DIE='[ -n "$NUCORE_ARGS_ONERROR_RETURN" ] && return 1 || die'
|
||||
local __DIE='[ -n "$NULIB_ARGS_ONERROR_RETURN" ] && return 1 || die'
|
||||
|
||||
if ! is_array args; then
|
||||
eerror "Invalid args definition: args must be defined"
|
||||
|
@ -122,7 +122,7 @@ function parse_args() {
|
|||
__DEFS=("$@")
|
||||
__parse_args || __r=1
|
||||
fi
|
||||
[ -n "$NUCORE_ARGS_SET_X" ] && set -x
|
||||
[ -n "$NULIB_ARGS_SET_X" ] && set -x
|
||||
if [ -n "$__r" ]; then
|
||||
eval "$__DIE"
|
||||
fi
|
||||
|
|
|
@ -413,12 +413,12 @@ function upvars() {
|
|||
|
||||
function: set_debug "Passer en mode DEBUG"
|
||||
function set_debug() {
|
||||
export NUCORE_DEBUG=1
|
||||
export NULIB_DEBUG=1
|
||||
}
|
||||
|
||||
function: is_debug "Tester si on est en mode DEBUG"
|
||||
function is_debug() {
|
||||
[ -n "$NUCORE_DEBUG" ]
|
||||
[ -n "$NULIB_DEBUG" ]
|
||||
}
|
||||
|
||||
function: lawk "Lancer GNUawk avec la librairie 'base'"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
##@cooked nocomments
|
||||
module: base.init "Fonctions de base: initialiser l'environnement"
|
||||
|
||||
if [ -z "$NUCORE_NO_INIT_ENV" ]; then
|
||||
if [ -z "$NULIB_NO_INIT_ENV" ]; then
|
||||
# Emplacement du script courant
|
||||
if [ "$0" == "-bash" ]; then
|
||||
MYNAME=
|
||||
|
@ -19,7 +19,7 @@ if [ -z "$NUCORE_NO_INIT_ENV" ]; then
|
|||
MYDIR="$(cd "$MYDIR"; pwd)"
|
||||
MYSELF="$MYDIR/$MYNAME"
|
||||
fi
|
||||
[ -n "$NUCOREDIR" ] || NUCOREDIR="$MYDIR"
|
||||
[ -n "$NULIBDIR" ] || NULIBDIR="$MYDIR"
|
||||
|
||||
# Repertoire temporaire
|
||||
[ -z "$TMPDIR" -a -d "$HOME/tmp" ] && TMPDIR="$HOME/tmp"
|
||||
|
@ -29,20 +29,20 @@ if [ -z "$NUCORE_NO_INIT_ENV" ]; then
|
|||
# User
|
||||
[ -z "$USER" -a -n "$LOGNAME" ] && export USER="$LOGNAME"
|
||||
|
||||
# Le fichier nucorerc doit être chargé systématiquement
|
||||
[ -f /etc/debian_chroot ] && NUCORE_CHROOT=1
|
||||
[ -f /etc/nucorerc ] && . /etc/nucorerc
|
||||
[ -f ~/.nucorerc ] && . ~/.nucorerc
|
||||
# Le fichier nulibrc doit être chargé systématiquement
|
||||
[ -f /etc/debian_chroot ] && NULIB_CHROOT=1
|
||||
[ -f /etc/nulibrc ] && . /etc/nulibrc
|
||||
[ -f ~/.nulibrc ] && . ~/.nulibrc
|
||||
|
||||
# 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 "$NUCORE_CHROOT" ]; then
|
||||
if [ -n "$NULIB_CHROOT" ]; then
|
||||
# Dans un chroot, il est possible de forcer les valeurs
|
||||
[ -n "$NUCORE_UNAME_SYSTEM" ] && eval "UNAME_SYSTEM=$NUCORE_UNAME_SYSTEM"
|
||||
[ -n "$NUCORE_UNAME_MACHINE" ] && eval "UNAME_MACHINE=$NUCORE_UNAME_MACHINE"
|
||||
[ -n "$NULIB_UNAME_SYSTEM" ] && eval "UNAME_SYSTEM=$NULIB_UNAME_SYSTEM"
|
||||
[ -n "$NULIB_UNAME_MACHINE" ] && eval "UNAME_MACHINE=$NULIB_UNAME_MACHINE"
|
||||
fi
|
||||
|
||||
# Nom d'hôte respectivement avec et sans domaine
|
||||
|
|
|
@ -4,17 +4,17 @@ module: base.input "Fonctions de base: saisie"
|
|||
|
||||
function toienc() {
|
||||
# $1 étant une variable contenant une chaine encodée dans l'encoding d'entrée $2
|
||||
# (qui vaut par défaut $NUCORE_INPUT_ENCODING), transformer cette chaine en
|
||||
# (qui vaut par défaut $NULIB_INPUT_ENCODING), transformer cette chaine en
|
||||
# utf-8
|
||||
local __var="$1" __from="${2:-$NUCORE_INPUT_ENCODING}"
|
||||
if [ "$__from" != "NUCORE__UTF8" ]; then
|
||||
local __var="$1" __from="${2:-$NULIB_INPUT_ENCODING}"
|
||||
if [ "$__from" != "NULIB__UTF8" ]; then
|
||||
_setv "$__var" "$(iconv -f "$__from" -t utf-8 <<<"${!__var}")"
|
||||
fi
|
||||
}
|
||||
|
||||
function uread() {
|
||||
# Lire une valeur sur stdin et la placer dans la variable $1. On assume que la
|
||||
# valeur en entrée est encodée dans $NUCORE_INPUT_ENCODING
|
||||
# valeur en entrée est encodée dans $NULIB_INPUT_ENCODING
|
||||
[ $# -gt 0 ] || set -- REPLY
|
||||
local __var
|
||||
read "$@"
|
||||
|
@ -165,7 +165,7 @@ function read_value() {
|
|||
# affichée, ce qui la rend appropriée pour la lecture d'un mot de passe.
|
||||
local -a __rv_opts; local __rv_readline=1 __rv_showdef=1 __rv_nl=
|
||||
__rv_opts=()
|
||||
[ -n "$NUCORE_NO_READLINE" ] && __rv_readline=
|
||||
[ -n "$NULIB_NO_READLINE" ] && __rv_readline=
|
||||
__rv_read "$@"
|
||||
}
|
||||
|
||||
|
|
|
@ -2,16 +2,16 @@
|
|||
##@cooked nocomments
|
||||
module: base.output "Fonctions de base: affichage"
|
||||
|
||||
NUCORE__TAB=$'\t'
|
||||
NUCORE__LATIN1=iso-8859-1
|
||||
NUCORE__LATIN9=iso-8859-15
|
||||
NUCORE__UTF8=utf-8
|
||||
NULIB__TAB=$'\t'
|
||||
NULIB__LATIN1=iso-8859-1
|
||||
NULIB__LATIN9=iso-8859-15
|
||||
NULIB__UTF8=utf-8
|
||||
|
||||
if [ ! -x "$(which iconv 2>/dev/null)" ]; then
|
||||
function iconv() { cat; }
|
||||
fi
|
||||
|
||||
function nucore__lang_encoding() {
|
||||
function nulib__lang_encoding() {
|
||||
case "${LANG,,}" in
|
||||
*@euro) echo "iso-8859-15";;
|
||||
*.utf-8|*.utf8) echo "utf-8";;
|
||||
|
@ -19,7 +19,7 @@ function nucore__lang_encoding() {
|
|||
esac
|
||||
}
|
||||
|
||||
function nucore__norm_encoding() {
|
||||
function nulib__norm_encoding() {
|
||||
local enc="${1,,}"
|
||||
enc="${enc//[-_]/}"
|
||||
case "$enc" in
|
||||
|
@ -30,16 +30,16 @@ function nucore__norm_encoding() {
|
|||
esac
|
||||
}
|
||||
|
||||
function nucore__init_encoding() {
|
||||
local default_encoding="$(nucore__lang_encoding)"
|
||||
function nulib__init_encoding() {
|
||||
local default_encoding="$(nulib__lang_encoding)"
|
||||
[ -n "$default_encoding" ] || default_encoding=utf-8
|
||||
[ -n "$NUCORE_OUTPUT_ENCODING" ] || NUCORE_OUTPUT_ENCODING="$default_encoding"
|
||||
NUCORE_OUTPUT_ENCODING="$(nucore__norm_encoding "$NUCORE_OUTPUT_ENCODING")"
|
||||
[ -n "$NUCORE_INPUT_ENCODING" ] || NUCORE_INPUT_ENCODING="$NUCORE_OUTPUT_ENCODING"
|
||||
NUCORE_INPUT_ENCODING="$(nucore__norm_encoding "$NUCORE_INPUT_ENCODING")"
|
||||
[ -n "$NULIB_OUTPUT_ENCODING" ] || NULIB_OUTPUT_ENCODING="$default_encoding"
|
||||
NULIB_OUTPUT_ENCODING="$(nulib__norm_encoding "$NULIB_OUTPUT_ENCODING")"
|
||||
[ -n "$NULIB_INPUT_ENCODING" ] || NULIB_INPUT_ENCODING="$NULIB_OUTPUT_ENCODING"
|
||||
NULIB_INPUT_ENCODING="$(nulib__norm_encoding "$NULIB_INPUT_ENCODING")"
|
||||
}
|
||||
[ -n "$NUCORE_LANG" -a -z "$LANG" ] && export NUCORE_LANG LANG="$NUCORE_LANG"
|
||||
nucore__init_encoding
|
||||
[ -n "$NULIB_LANG" -a -z "$LANG" ] && export NULIB_LANG LANG="$NULIB_LANG"
|
||||
nulib__init_encoding
|
||||
|
||||
function noerror() {
|
||||
# lancer la commande "$@" et masquer son code de retour
|
||||
|
@ -83,9 +83,9 @@ function err_isatty() {
|
|||
|
||||
function tooenc() {
|
||||
# $1 étant une chaine encodée en utf-8, l'afficher dans l'encoding de sortie $2
|
||||
# qui vaut par défaut $NUCORE_OUTPUT_ENCODING
|
||||
local value="$1" to="${2:-$NUCORE_OUTPUT_ENCODING}"
|
||||
if [ "$to" == "$NUCORE__UTF8" ]; then
|
||||
# qui vaut par défaut $NULIB_OUTPUT_ENCODING
|
||||
local value="$1" to="${2:-$NULIB_OUTPUT_ENCODING}"
|
||||
if [ "$to" == "$NULIB__UTF8" ]; then
|
||||
recho "$value"
|
||||
else
|
||||
iconv -f -utf-8 -t "$to" <<<"$value"
|
||||
|
@ -95,9 +95,9 @@ function uecho() { tooenc "$*"; }
|
|||
|
||||
function tooenc_() {
|
||||
# $1 étant une chaine encodée en utf-8, l'afficher sans passer à la ligne dans
|
||||
# l'encoding de sortie $2 qui vaut par défaut $NUCORE_OUTPUT_ENCODING
|
||||
local value="$1" to="${2:-$NUCORE_OUTPUT_ENCODING}"
|
||||
if [ "$to" == "$NUCORE__UTF8" ]; then
|
||||
# l'encoding de sortie $2 qui vaut par défaut $NULIB_OUTPUT_ENCODING
|
||||
local value="$1" to="${2:-$NULIB_OUTPUT_ENCODING}"
|
||||
if [ "$to" == "$NULIB__UTF8" ]; then
|
||||
recho_ "$value"
|
||||
else
|
||||
recho_ "$value" | iconv -f utf-8 -t "$to"
|
||||
|
@ -106,34 +106,34 @@ function tooenc_() {
|
|||
function uecho_() { tooenc_ "$*"; }
|
||||
|
||||
# faut-il dater les messages de etitle, estep, ebegin?
|
||||
# Faire NUCORE_EDATE=1 en début de script pour activer cette fonctionnalité
|
||||
export NUCORE_EDATE
|
||||
function __edate() { [ -n "$NUCORE_EDATE" ] && date +"[%d/%m/%Y-%H:%M:%S] "; }
|
||||
# Faire NULIB_EDATE=1 en début de script pour activer cette fonctionnalité
|
||||
export NULIB_EDATE
|
||||
function __edate() { [ -n "$NULIB_EDATE" ] && date +"[%d/%m/%Y-%H:%M:%S] "; }
|
||||
|
||||
export NUCORE_ELOG_OVERWRITE
|
||||
export NULIB_ELOG_OVERWRITE
|
||||
function __set_no_colors() { :; }
|
||||
function elogto() {
|
||||
# Activer NUCORE_EDATE et rediriger STDOUT et STDERR vers le fichier $1
|
||||
# Activer NULIB_EDATE et rediriger STDOUT et STDERR vers le fichier $1
|
||||
# Si deux fichiers sont spécifiés, rediriger STDOUT vers $1 et STDERR vers $2
|
||||
# Si aucun fichier n'est spécifié, ne pas faire de redirection
|
||||
# Si la redirection est activée, forcer l'utilisation de l'encoding UTF8
|
||||
# Si NUCORE_ELOG_OVERWRITE=1, alors le fichier en sortie est écrasé. Sinon, les
|
||||
# Si NULIB_ELOG_OVERWRITE=1, alors le fichier en sortie est écrasé. Sinon, les
|
||||
# lignes en sortie lui sont ajoutées
|
||||
NUCORE_EDATE=1
|
||||
NULIB_EDATE=1
|
||||
if [ -n "$1" -a -n "$2" ]; then
|
||||
LANG=fr_FR.UTF8
|
||||
NUCORE_OUTPUT_ENCODING="$NUCORE__UTF8"
|
||||
NULIB_OUTPUT_ENCODING="$NULIB__UTF8"
|
||||
__set_no_colors 1
|
||||
if [ -n "$NUCORE_ELOG_OVERWRITE" ]; then
|
||||
if [ -n "$NULIB_ELOG_OVERWRITE" ]; then
|
||||
exec >"$1" 2>"$2"
|
||||
else
|
||||
exec >>"$1" 2>>"$2"
|
||||
fi
|
||||
elif [ -n "$1" ]; then
|
||||
LANG=fr_FR.UTF8
|
||||
NUCORE_OUTPUT_ENCODING="$NUCORE__UTF8"
|
||||
NULIB_OUTPUT_ENCODING="$NULIB__UTF8"
|
||||
__set_no_colors 1
|
||||
if [ -n "$NUCORE_ELOG_OVERWRITE" ]; then
|
||||
if [ -n "$NULIB_ELOG_OVERWRITE" ]; then
|
||||
exec >"$1" 2>&1
|
||||
else
|
||||
exec >>"$1" 2>&1
|
||||
|
@ -142,35 +142,35 @@ function elogto() {
|
|||
}
|
||||
|
||||
# variables utilisées pour l'affichage indenté des messages et des titres
|
||||
# NUCORE__ESTACK est la liste des invocations de 'ebegin' et 'etitle' en cours
|
||||
# NUCORE__TLEVEL est l'indentation à appliquer avant d'afficher le message
|
||||
export NUCORE__ESTACK NUCORE__TLEVEL
|
||||
# NULIB__ESTACK est la liste des invocations de 'ebegin' et 'etitle' en cours
|
||||
# NULIB__TLEVEL est l'indentation à appliquer avant d'afficher le message
|
||||
export NULIB__ESTACK NULIB__TLEVEL
|
||||
function __indent() {
|
||||
# indenter les lignes de $1, sauf la première
|
||||
if [ "${1/
|
||||
/}" != "$1" ]; then
|
||||
sed "2,\$s/^/${NUCORE__TLEVEL}/g" <<<"$1"
|
||||
sed "2,\$s/^/${NULIB__TLEVEL}/g" <<<"$1"
|
||||
else
|
||||
recho "$1"
|
||||
fi
|
||||
}
|
||||
# fonctions à surcharger pour modifier la façon dont les messages sont affichés
|
||||
function __eerror() { tooenc "$(__edate)${NUCORE__TLEVEL}ERROR $(__indent "$1")"; }
|
||||
function __ewarn() { tooenc "$(__edate)${NUCORE__TLEVEL}WARNING $(__indent "$1")"; }
|
||||
function __enote() { tooenc "$(__edate)${NUCORE__TLEVEL}NOTE $(__indent "$1")"; }
|
||||
function __eerror() { tooenc "$(__edate)${NULIB__TLEVEL}ERROR $(__indent "$1")"; }
|
||||
function __ewarn() { tooenc "$(__edate)${NULIB__TLEVEL}WARNING $(__indent "$1")"; }
|
||||
function __enote() { tooenc "$(__edate)${NULIB__TLEVEL}NOTE $(__indent "$1")"; }
|
||||
function __ebanner() {
|
||||
local maxi="${COLUMNS:-80}"
|
||||
local -a lines
|
||||
local psfix line
|
||||
|
||||
psfix="$(__edate)${NUCORE__TLEVEL}"
|
||||
psfix="$(__edate)${NULIB__TLEVEL}"
|
||||
while [ ${#psfix} -lt $maxi ]; do psfix="$psfix="; done
|
||||
|
||||
tooenc "$psfix"
|
||||
maxi=$(($maxi - 1))
|
||||
array_xsplitl lines "$1"
|
||||
for line in "" "${lines[@]}" ""; do
|
||||
line="$(__edate)${NUCORE__TLEVEL}= $line"
|
||||
line="$(__edate)${NULIB__TLEVEL}= $line"
|
||||
if [ ${#line} -le $maxi ]; then
|
||||
while [ ${#line} -lt $maxi ]; do line="$line "; done
|
||||
line="$line="
|
||||
|
@ -179,24 +179,24 @@ function __ebanner() {
|
|||
done
|
||||
tooenc "$psfix"
|
||||
}
|
||||
function __eimportant() { tooenc "$(__edate)${NUCORE__TLEVEL}IMPORTANT $(__indent "$1")"; }
|
||||
function __eattention() { tooenc "$(__edate)${NUCORE__TLEVEL}ATTENTION $(__indent "$1")"; }
|
||||
function __einfo() { tooenc "$(__edate)${NUCORE__TLEVEL}INFO $(__indent "$1")"; }
|
||||
function __eecho() { tooenc "$(__edate)${NUCORE__TLEVEL}$(__indent "$1")"; }
|
||||
function __eecho_() { tooenc_ "$(__edate)${NUCORE__TLEVEL}$(__indent "$1")"; }
|
||||
function __edebug() { tooenc "$(__edate)${NUCORE__TLEVEL}DEBUG $(__indent "$1")"; }
|
||||
function __estep() { tooenc "$(__edate)${NUCORE__TLEVEL}. $(__indent "$1")"; }
|
||||
function __estepe() { tooenc "$(__edate)${NUCORE__TLEVEL}.E $(__indent "$1")"; }
|
||||
function __estepw() { tooenc "$(__edate)${NUCORE__TLEVEL}.W $(__indent "$1")"; }
|
||||
function __estepn() { tooenc "$(__edate)${NUCORE__TLEVEL}.N $(__indent "$1")"; }
|
||||
function __estepi() { tooenc "$(__edate)${NUCORE__TLEVEL}.I $(__indent "$1")"; }
|
||||
function __estep_() { tooenc_ "$(__edate)${NUCORE__TLEVEL}. $(__indent "$1")"; }
|
||||
function __estepe_() { tooenc_ "$(__edate)${NUCORE__TLEVEL}.E $(__indent "$1")"; }
|
||||
function __estepw_() { tooenc_ "$(__edate)${NUCORE__TLEVEL}.W $(__indent "$1")"; }
|
||||
function __estepn_() { tooenc_ "$(__edate)${NUCORE__TLEVEL}.N $(__indent "$1")"; }
|
||||
function __estepi_() { tooenc_ "$(__edate)${NUCORE__TLEVEL}.I $(__indent "$1")"; }
|
||||
function __etitle() { tooenc "$(__edate)${NUCORE__TLEVEL}=== $(__indent "$1")"; }
|
||||
function __ebegin() { tooenc_ "$(__edate)${NUCORE__TLEVEL}. $(__indent "$1"): "; }
|
||||
function __eimportant() { tooenc "$(__edate)${NULIB__TLEVEL}IMPORTANT $(__indent "$1")"; }
|
||||
function __eattention() { tooenc "$(__edate)${NULIB__TLEVEL}ATTENTION $(__indent "$1")"; }
|
||||
function __einfo() { tooenc "$(__edate)${NULIB__TLEVEL}INFO $(__indent "$1")"; }
|
||||
function __eecho() { tooenc "$(__edate)${NULIB__TLEVEL}$(__indent "$1")"; }
|
||||
function __eecho_() { tooenc_ "$(__edate)${NULIB__TLEVEL}$(__indent "$1")"; }
|
||||
function __edebug() { tooenc "$(__edate)${NULIB__TLEVEL}DEBUG $(__indent "$1")"; }
|
||||
function __estep() { tooenc "$(__edate)${NULIB__TLEVEL}. $(__indent "$1")"; }
|
||||
function __estepe() { tooenc "$(__edate)${NULIB__TLEVEL}.E $(__indent "$1")"; }
|
||||
function __estepw() { tooenc "$(__edate)${NULIB__TLEVEL}.W $(__indent "$1")"; }
|
||||
function __estepn() { tooenc "$(__edate)${NULIB__TLEVEL}.N $(__indent "$1")"; }
|
||||
function __estepi() { tooenc "$(__edate)${NULIB__TLEVEL}.I $(__indent "$1")"; }
|
||||
function __estep_() { tooenc_ "$(__edate)${NULIB__TLEVEL}. $(__indent "$1")"; }
|
||||
function __estepe_() { tooenc_ "$(__edate)${NULIB__TLEVEL}.E $(__indent "$1")"; }
|
||||
function __estepw_() { tooenc_ "$(__edate)${NULIB__TLEVEL}.W $(__indent "$1")"; }
|
||||
function __estepn_() { tooenc_ "$(__edate)${NULIB__TLEVEL}.N $(__indent "$1")"; }
|
||||
function __estepi_() { tooenc_ "$(__edate)${NULIB__TLEVEL}.I $(__indent "$1")"; }
|
||||
function __etitle() { tooenc "$(__edate)${NULIB__TLEVEL}=== $(__indent "$1")"; }
|
||||
function __ebegin() { tooenc_ "$(__edate)${NULIB__TLEVEL}. $(__indent "$1"): "; }
|
||||
function __edoto() { echo_ "."; }
|
||||
function __edotw() { echo_ "w"; }
|
||||
function __edotx() { echo_ "x"; }
|
||||
|
@ -230,14 +230,14 @@ function check_verbosity() {
|
|||
function get_verbosity_option() { :;}
|
||||
|
||||
# note: toutes les fonctions d'affichage e* écrivent sur stderr
|
||||
NUCORE__EPENDING=
|
||||
NULIB__EPENDING=
|
||||
function eflush() {
|
||||
# Afficher les messages en attente
|
||||
if [ -n "$NUCORE__EPENDING" ]; then recho "$NUCORE__EPENDING" 1>&2; NUCORE__EPENDING=; fi
|
||||
if [ -n "$NULIB__EPENDING" ]; then recho "$NULIB__EPENDING" 1>&2; NULIB__EPENDING=; fi
|
||||
}
|
||||
function eclearp() {
|
||||
# Supprimer les message en attente
|
||||
NUCORE__EPENDING=
|
||||
NULIB__EPENDING=
|
||||
}
|
||||
function eerror() {
|
||||
# Afficher un message d'erreur
|
||||
|
@ -429,11 +429,11 @@ function __t_etitle() {
|
|||
local __t_title="$1"; shift
|
||||
local __t_s=0
|
||||
# etitle
|
||||
[ -n "$NUCORE__ESTACK" ] && NUCORE__TLEVEL="${NUCORE__TLEVEL} "
|
||||
NUCORE__ESTACK="$NUCORE__ESTACK:t"
|
||||
[ -n "$NULIB__ESTACK" ] && NULIB__TLEVEL="${NULIB__TLEVEL} "
|
||||
NULIB__ESTACK="$NULIB__ESTACK:t"
|
||||
if show_info; then
|
||||
if [ -n "$__t_deferred" ]; then
|
||||
NUCORE__EPENDING="${NUCORE__EPENDING:+$NUCORE__EPENDING
|
||||
NULIB__EPENDING="${NULIB__EPENDING:+$NULIB__EPENDING
|
||||
}$(__etitle "$__t_title")"
|
||||
else
|
||||
eflush
|
||||
|
@ -512,7 +512,7 @@ function ebegin() {
|
|||
local __b_msg="$1"; shift
|
||||
local __b_s=0
|
||||
# ebegin
|
||||
NUCORE__ESTACK="$NUCORE__ESTACK:b"
|
||||
NULIB__ESTACK="$NULIB__ESTACK:b"
|
||||
if show_info; then
|
||||
eflush
|
||||
__ebegin "$__b_msg" 1>&2
|
||||
|
@ -597,11 +597,11 @@ function eend() {
|
|||
# par le titre.
|
||||
local s=$?
|
||||
if [ "$1" == "-c" ]; then
|
||||
NUCORE__ESTACK=
|
||||
NUCORE__TLEVEL=
|
||||
elif [ "${NUCORE__ESTACK%:b}" != "$NUCORE__ESTACK" ]; then
|
||||
NULIB__ESTACK=
|
||||
NULIB__TLEVEL=
|
||||
elif [ "${NULIB__ESTACK%:b}" != "$NULIB__ESTACK" ]; then
|
||||
# terminer ebegin
|
||||
NUCORE__ESTACK="${NUCORE__ESTACK%:b}"
|
||||
NULIB__ESTACK="${NULIB__ESTACK%:b}"
|
||||
show_info || return
|
||||
eflush
|
||||
[ -n "$1" ] && s="$1"
|
||||
|
@ -610,10 +610,10 @@ function eend() {
|
|||
else
|
||||
__eendx 1>&2
|
||||
fi
|
||||
elif [ "${NUCORE__ESTACK%:t}" != "$NUCORE__ESTACK" ]; then
|
||||
elif [ "${NULIB__ESTACK%:t}" != "$NULIB__ESTACK" ]; then
|
||||
# terminer etitle -s
|
||||
NUCORE__ESTACK="${NUCORE__ESTACK%:t}"
|
||||
NUCORE__TLEVEL="${NUCORE__TLEVEL% }"
|
||||
NULIB__ESTACK="${NULIB__ESTACK%:t}"
|
||||
NULIB__TLEVEL="${NULIB__TLEVEL% }"
|
||||
fi
|
||||
}
|
||||
function __elinedots() {
|
||||
|
|
|
@ -55,11 +55,11 @@ function mktempd() {
|
|||
mktemp -d "${1:-"$TMPDIR/tmp.XXXXXX"}"
|
||||
}
|
||||
|
||||
function ac__forgetall() { NUCORE__AC_FILES=(); }
|
||||
function ac__forgetall() { NULIB__AC_FILES=(); }
|
||||
ac__forgetall
|
||||
function ac__trap() {
|
||||
local file
|
||||
for file in "${NUCORE__AC_FILES[@]}"; do
|
||||
for file in "${NULIB__AC_FILES[@]}"; do
|
||||
[ -e "$file" ] && rm -rf "$file" 2>/dev/null
|
||||
done
|
||||
ac__forgetall
|
||||
|
@ -72,7 +72,7 @@ programme"
|
|||
function autoclean() {
|
||||
local file
|
||||
for file in "$@"; do
|
||||
[ -n "$file" ] && NUCORE__AC_FILES=("${NUCORE__AC_FILES[@]}" "$file")
|
||||
[ -n "$file" ] && NULIB__AC_FILES=("${NULIB__AC_FILES[@]}" "$file")
|
||||
done
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ par ac_set_tmpfile() ou ac_set_tmpdir()"
|
|||
function ac_clean() {
|
||||
local file acfile found
|
||||
local -a acfiles
|
||||
for acfile in "${NUCORE__AC_FILES[@]}"; do
|
||||
for acfile in "${NULIB__AC_FILES[@]}"; do
|
||||
found=
|
||||
for file in "$@"; do
|
||||
if [ "$file" == "$acfile" ]; then
|
||||
|
@ -99,7 +99,7 @@ function ac_clean() {
|
|||
done
|
||||
[ -z "$found" ] && acfiles=("${acfiles[@]}" "$acfile")
|
||||
done
|
||||
NUCORE__AC_FILES=("${acfiles[@]}")
|
||||
NULIB__AC_FILES=("${acfiles[@]}")
|
||||
}
|
||||
|
||||
function: ac_set_tmpfile "\
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||
##@cooked nocomments
|
||||
# shim pour les fonctions de nucore.sh au cas où ce module n'est pas chargée
|
||||
if [ -z "$NUCOREDIR" -o "$NUCOREDIR" != "$NUCOREINIT" ]; then
|
||||
# shim pour les fonctions de nulib.sh au cas où ce module n'est pas chargée
|
||||
if [ -z "$NULIBDIR" -o "$NULIBDIR" != "$NULIBINIT" ]; then
|
||||
function module:() { :; }
|
||||
function function:() { :; }
|
||||
function require:() { :; }
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||
##@cooked nocomments
|
||||
##@require nucore.sh
|
||||
##@require nulib.sh
|
||||
##@require base
|
||||
module: git "Fonctions pour faciliter l'utilisation de git"
|
||||
require: nucore base
|
||||
require: nulib base
|
||||
|
||||
function: git_geturl ""
|
||||
function git_geturl() {
|
||||
|
@ -15,7 +15,7 @@ function git_have_annex() {
|
|||
[ -n "$(git config --get annex.uuid)" ]
|
||||
}
|
||||
|
||||
NUCORE_GIT_FUNCTIONS=(
|
||||
NULIB_GIT_FUNCTIONS=(
|
||||
git_check_gitvcs git_ensure_gitvcs
|
||||
git_list_branches git_list_rbranches
|
||||
git_have_branch git_have_rbranch
|
||||
|
@ -25,7 +25,7 @@ NUCORE_GIT_FUNCTIONS=(
|
|||
git_is_ancestor git_should_ff git_should_push
|
||||
git_is_merged
|
||||
)
|
||||
NUCORE_GIT_FUNCTIONS_MAP=(
|
||||
NULIB_GIT_FUNCTIONS_MAP=(
|
||||
cg:git_check_gitvcs eg:git_ensure_gitvcs
|
||||
lbs:git_list_branches rbs:git_list_rbranches
|
||||
hlb:git_have_branch hrb:git_have_rbranch
|
||||
|
@ -148,7 +148,7 @@ function git_ensure_branch() {
|
|||
# créer une nouvelle branche du nom spécifié
|
||||
git_have_branch "$source" || return 2
|
||||
git branch "$branch" "$source" || return 2
|
||||
if [ -z "$NUCORE_GIT_OFFLINE" ]; then
|
||||
if [ -z "$NULIB_GIT_OFFLINE" ]; then
|
||||
git_have_remote "$origin" && git_track_branch "$branch" "$origin"
|
||||
fi
|
||||
fi
|
||||
|
@ -219,16 +219,16 @@ function git_is_merged() {
|
|||
################################################################################
|
||||
# git annex
|
||||
|
||||
NUCORE_GIT_SSH_WRAPPER=
|
||||
NULIB_GIT_SSH_WRAPPER=
|
||||
function: git_annex_use_ssh_wrapper ""
|
||||
function git_annex_use_ssh_wrapper() {
|
||||
[ -n "$NUCORE_GIT_SSH_WRAPPER" ] && return
|
||||
NUCORE_GIT_FORCE_PATH="$PATH"
|
||||
NUCORE_GIT_FORCE_SSH="${GIT_SSH:-ssh}"
|
||||
export NUCORE_GIT_FORCE_PATH NUCORE_GIT_FORCE_SSH
|
||||
base_delpath "$NUCOREDIR/ssh-wrapper" NUCORE_GIT_FORCE_PATH
|
||||
base_inspath "$NUCOREDIR/ssh-wrapper" PATH
|
||||
NUCORE_GIT_SSH_WRAPPER=1
|
||||
[ -n "$NULIB_GIT_SSH_WRAPPER" ] && return
|
||||
NULIB_GIT_FORCE_PATH="$PATH"
|
||||
NULIB_GIT_FORCE_SSH="${GIT_SSH:-ssh}"
|
||||
export NULIB_GIT_FORCE_PATH NULIB_GIT_FORCE_SSH
|
||||
base_delpath "$NULIBDIR/ssh-wrapper" NULIB_GIT_FORCE_PATH
|
||||
base_inspath "$NULIBDIR/ssh-wrapper" PATH
|
||||
NULIB_GIT_SSH_WRAPPER=1
|
||||
}
|
||||
|
||||
function: git_annex_initial "sur le dépôt \$1 fraichement cloné, vérifier s'il faut faire git annex init. Si oui, l'initialiser avec le nom d'hôte, et récupérer tous les fichiers annexés
|
||||
|
@ -274,7 +274,7 @@ function git_annex_initial() {
|
|||
function: git_commit ""
|
||||
function git_commit() {
|
||||
local all=auto allnew push=auto nopush args
|
||||
setyesval nopush "$NUCORE_GIT_OFFLINE"
|
||||
setyesval nopush "$NULIB_GIT_OFFLINE"
|
||||
[ -n "$nopush" ] && push=
|
||||
parse_opts + "${PRETTYOPTS[@]}" \
|
||||
-a,--all all=1 \
|
||||
|
|
|
@ -49,7 +49,7 @@ function get_color() {
|
|||
}
|
||||
function __set_no_colors() {
|
||||
if [ -z "$1" ]; then
|
||||
if [ -n "$NUCORE_NO_COLORS" ]; then NO_COLORS=1
|
||||
if [ -n "$NULIB_NO_COLORS" ]; then NO_COLORS=1
|
||||
elif out_isatty && err_isatty; then NO_COLORS=
|
||||
else NO_COLORS=1
|
||||
fi
|
||||
|
@ -65,22 +65,22 @@ function __set_no_colors() {
|
|||
}
|
||||
__set_no_colors
|
||||
|
||||
function __eerror() { local p; [ -z "$NO_COLORS" ] && p="E" || p="ERROR"; tooenc "$(__edate)${NUCORE__TLEVEL}${COULEUR_ROUGE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __ewarn() { local p; [ -z "$NO_COLORS" ] && p="W" || p="WARNING"; tooenc "$(__edate)${NUCORE__TLEVEL}${COULEUR_JAUNE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __enote() { local p; [ -z "$NO_COLORS" ] && p="N" || p="NOTE"; tooenc "$(__edate)${NUCORE__TLEVEL}${COULEUR_VERTE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __eerror() { local p; [ -z "$NO_COLORS" ] && p="E" || p="ERROR"; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_ROUGE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __ewarn() { local p; [ -z "$NO_COLORS" ] && p="W" || p="WARNING"; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_JAUNE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __enote() { local p; [ -z "$NO_COLORS" ] && p="N" || p="NOTE"; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_VERTE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __ebanner() {
|
||||
local maxi="${COLUMNS:-80}"
|
||||
local -a lines
|
||||
local psfix line
|
||||
|
||||
psfix="$(__edate)${NUCORE__TLEVEL}"
|
||||
psfix="$(__edate)${NULIB__TLEVEL}"
|
||||
while [ ${#psfix} -lt $maxi ]; do psfix="$psfix="; done
|
||||
|
||||
tooenc "$COULEUR_ROUGE$psfix"
|
||||
maxi=$(($maxi - 1))
|
||||
array_xsplitl lines "$1"
|
||||
for line in "" "${lines[@]}" ""; do
|
||||
line="$(__edate)${NUCORE__TLEVEL}= $line"
|
||||
line="$(__edate)${NULIB__TLEVEL}= $line"
|
||||
if [ ${#line} -le $maxi ]; then
|
||||
while [ ${#line} -lt $maxi ]; do line="$line "; done
|
||||
line="$line="
|
||||
|
@ -89,22 +89,22 @@ function __ebanner() {
|
|||
done
|
||||
tooenc "$psfix$COULEUR_NORMALE"
|
||||
}
|
||||
function __eimportant() { local p; [ -z "$NO_COLORS" ] && p="!" || p="IMPORTANT"; tooenc "$(__edate)${NUCORE__TLEVEL}${COULEUR_ROUGE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __eattention() { local p; [ -z "$NO_COLORS" ] && p="*" || p="ATTENTION"; tooenc "$(__edate)${NUCORE__TLEVEL}${COULEUR_JAUNE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __einfo() { local p; [ -z "$NO_COLORS" ] && p="I" || p="INFO"; tooenc "$(__edate)${NUCORE__TLEVEL}${COULEUR_BLEUE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __edebug() { local p; [ -z "$NO_COLORS" ] && p="D" || p="DEBUG"; tooenc "$(__edate)${NUCORE__TLEVEL}${COULEUR_BLANCHE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estep() { local p; [ -z "$NO_COLORS" ] && p="." || p="."; tooenc "$(__edate)${NUCORE__TLEVEL}${COULEUR_BLANCHE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepe() { local p; [ -z "$NO_COLORS" ] && p="." || p=".E"; tooenc "$(__edate)${NUCORE__TLEVEL}${COULEUR_ROUGE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepw() { local p; [ -z "$NO_COLORS" ] && p="." || p=".W"; tooenc "$(__edate)${NUCORE__TLEVEL}${COULEUR_JAUNE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepn() { local p; [ -z "$NO_COLORS" ] && p="." || p=".N"; tooenc "$(__edate)${NUCORE__TLEVEL}${COULEUR_VERTE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepi() { local p; [ -z "$NO_COLORS" ] && p="." || p=".I"; tooenc "$(__edate)${NUCORE__TLEVEL}${COULEUR_BLEUE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estep_() { local p; [ -z "$NO_COLORS" ] && p="." || p="."; tooenc_ "$(__edate)${NUCORE__TLEVEL}${COULEUR_BLANCHE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepe_() { local p; [ -z "$NO_COLORS" ] && p="." || p=".E"; tooenc_ "$(__edate)${NUCORE__TLEVEL}${COULEUR_ROUGE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepw_() { local p; [ -z "$NO_COLORS" ] && p="." || p=".W"; tooenc_ "$(__edate)${NUCORE__TLEVEL}${COULEUR_JAUNE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepn_() { local p; [ -z "$NO_COLORS" ] && p="." || p=".N"; tooenc_ "$(__edate)${NUCORE__TLEVEL}${COULEUR_VERTE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepi_() { local p; [ -z "$NO_COLORS" ] && p="." || p=".I"; tooenc_ "$(__edate)${NUCORE__TLEVEL}${COULEUR_BLEUE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __etitle() { local p; [ -z "$NO_COLORS" ] && p="T" || p="==="; tooenc "$(__edate)${NUCORE__TLEVEL}${COULEUR_BLEUE}${p} $(get_color _)$(__indent "$1")${COULEUR_NORMALE}"; }
|
||||
function __ebegin() { local p; [ -z "$NO_COLORS" ] && p="." || p="."; tooenc_ "$(__edate)${NUCORE__TLEVEL}${COULEUR_BLANCHE}${p}${COULEUR_NORMALE} $(__indent "$1"): "; }
|
||||
function __eimportant() { local p; [ -z "$NO_COLORS" ] && p="!" || p="IMPORTANT"; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_ROUGE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __eattention() { local p; [ -z "$NO_COLORS" ] && p="*" || p="ATTENTION"; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_JAUNE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __einfo() { local p; [ -z "$NO_COLORS" ] && p="I" || p="INFO"; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_BLEUE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __edebug() { local p; [ -z "$NO_COLORS" ] && p="D" || p="DEBUG"; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_BLANCHE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estep() { local p; [ -z "$NO_COLORS" ] && p="." || p="."; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_BLANCHE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepe() { local p; [ -z "$NO_COLORS" ] && p="." || p=".E"; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_ROUGE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepw() { local p; [ -z "$NO_COLORS" ] && p="." || p=".W"; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_JAUNE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepn() { local p; [ -z "$NO_COLORS" ] && p="." || p=".N"; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_VERTE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepi() { local p; [ -z "$NO_COLORS" ] && p="." || p=".I"; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_BLEUE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estep_() { local p; [ -z "$NO_COLORS" ] && p="." || p="."; tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_BLANCHE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepe_() { local p; [ -z "$NO_COLORS" ] && p="." || p=".E"; tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_ROUGE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepw_() { local p; [ -z "$NO_COLORS" ] && p="." || p=".W"; tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_JAUNE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepn_() { local p; [ -z "$NO_COLORS" ] && p="." || p=".N"; tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_VERTE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __estepi_() { local p; [ -z "$NO_COLORS" ] && p="." || p=".I"; tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_BLEUE}${p}${COULEUR_NORMALE} $(__indent "$1")"; }
|
||||
function __etitle() { local p; [ -z "$NO_COLORS" ] && p="T" || p="==="; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_BLEUE}${p} $(get_color _)$(__indent "$1")${COULEUR_NORMALE}"; }
|
||||
function __ebegin() { local p; [ -z "$NO_COLORS" ] && p="." || p="."; tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_BLANCHE}${p}${COULEUR_NORMALE} $(__indent "$1"): "; }
|
||||
function __edoto() { echo_ "."; }
|
||||
function __edotw() { echo_ "${COULEUR_JAUNE}w${COULEUR_NORMALE}"; }
|
||||
function __edotx() { echo_ "${COULEUR_ROUGE}x${COULEUR_NORMALE}"; }
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#!/bin/bash
|
||||
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||
source "$(dirname -- "$0")/../src/nucore.sh" || exit 1
|
||||
source "$(dirname -- "$0")/../src/nulib.sh" || exit 1
|
||||
require: tests
|
||||
#NUCORE_NO_DISABLE_SET_X=1
|
||||
#NULIB_NO_DISABLE_SET_X=1
|
||||
|
||||
function pa() {
|
||||
unset count fixed mopt dmopt oopt doopt autoinc autoval a1 a2 a3 a4
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||
source "$(dirname -- "$0")/../src/nucore.sh" || exit 1
|
||||
#NUCORE_NO_DISABLE_SET_X=1
|
||||
source "$(dirname -- "$0")/../src/nulib.sh" || exit 1
|
||||
#NULIB_NO_DISABLE_SET_X=1
|
||||
|
||||
eerror "erreur"
|
||||
ewarn "warning"
|
||||
|
|
|
@ -7,5 +7,5 @@ source "$(dirname -- "$0")/../load.sh" || exit 1
|
|||
cd "$MYDIR/.."
|
||||
[ -n "$1" ] && dest="$1" || dest="$(pwd)"
|
||||
|
||||
estep "Maj /etc/nucore.sh"
|
||||
sed "s|@@""dest""@@|$dest|g" load.sh >/etc/nucore.sh
|
||||
estep "Maj /etc/nulib.sh"
|
||||
sed "s|@@""dest""@@|$dest|g" load.sh >/etc/nulib.sh
|
||||
|
|
136
load.sh
136
load.sh
|
@ -1,20 +1,20 @@
|
|||
##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||
## Charger nucore et rendre disponible les modules bash, awk, php et python
|
||||
## Charger nulib et rendre disponible les modules bash, awk, php et python
|
||||
##@cooked nocomments
|
||||
# Ce fichier doit être sourcé en premier. Si ce fichier n'est pas sourcé, alors
|
||||
# le répertoire nucore doit être disponible dans le répertoire du script qui
|
||||
# le répertoire nulib doit être disponible dans le répertoire du script qui
|
||||
# inclue ce fichier.
|
||||
# Une fois ce fichier sourcé, les autres modules peuvent être importés avec
|
||||
# require:() e.g.
|
||||
# source /etc/nucore.sh || exit 1
|
||||
# source /etc/nulib.sh || exit 1
|
||||
# require: other_modules
|
||||
# ou pour une copie locale de nucore:
|
||||
# source "$(dirname "$0")/nucore/load.sh" || exit 1
|
||||
# ou pour une copie locale de nulib:
|
||||
# source "$(dirname "$0")/nulib/load.sh" || exit 1
|
||||
# require: other_modules
|
||||
|
||||
# vérifier version minimum de bash
|
||||
if [ "x$BASH" = "x" ]; then
|
||||
echo "ERROR: nucore: this script requires bash"
|
||||
echo "ERROR: nulib: this script requires bash"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
@ -27,68 +27,68 @@ function inspathm() { local _qdir="${1//\//\\/}"; eval "export ${2:-PATH}; "'[ "
|
|||
function inspath() { delpath "$@"; inspathm "$@"; }
|
||||
|
||||
if [ ${BASH_VERSINFO[0]} -ge 5 -o \( ${BASH_VERSINFO[0]} -eq 4 -a ${BASH_VERSINFO[1]} -ge 1 \) ]; then :
|
||||
elif [ -n "$NUCORE_IGNORE_BASH_VERSION" ]; then :
|
||||
else die "nucore: bash 4.1+ is required"
|
||||
elif [ -n "$NULIB_IGNORE_BASH_VERSION" ]; then :
|
||||
else die "nulib: bash 4.1+ is required"
|
||||
fi
|
||||
|
||||
# Calculer emplacement de nucore
|
||||
NUCOREDIR="@@dest@@"
|
||||
if [ "$NUCOREDIR" = "@@""dest""@@" ]; then
|
||||
# Calculer emplacement de nulib
|
||||
NULIBDIR="@@dest@@"
|
||||
if [ "$NULIBDIR" = "@@""dest""@@" ]; then
|
||||
# La valeur "@@"dest"@@" n'est remplacée que dans la copie de ce script
|
||||
# faite dans /etc. Sinon, il faut toujours faire le calcul. Cela permet de
|
||||
# déplacer la librairie n'importe où sur le disque, ce qui est
|
||||
# particulièrement intéressant quand on fait du déploiement.
|
||||
NUCOREDIR="${BASH_SOURCE[0]}"
|
||||
if [ -f "$NUCOREDIR" -a "$(basename -- "$NUCOREDIR")" == load.sh ]; then
|
||||
# Fichier sourcé depuis nucore/
|
||||
NUCORE_SOURCED=1
|
||||
NUCOREDIR="$(dirname -- "$NUCOREDIR")"
|
||||
elif [ -f "$NUCOREDIR" -a "$(basename -- "$NUCOREDIR")" == nucore.sh ]; then
|
||||
# Fichier sourcé depuis nucore/bash/src
|
||||
NUCORE_SOURCED=1
|
||||
NUCOREDIR="$(dirname -- "$NUCOREDIR")/../.."
|
||||
NULIBDIR="${BASH_SOURCE[0]}"
|
||||
if [ -f "$NULIBDIR" -a "$(basename -- "$NULIBDIR")" == load.sh ]; then
|
||||
# Fichier sourcé depuis nulib/
|
||||
NULIB_SOURCED=1
|
||||
NULIBDIR="$(dirname -- "$NULIBDIR")"
|
||||
elif [ -f "$NULIBDIR" -a "$(basename -- "$NULIBDIR")" == nulib.sh ]; then
|
||||
# Fichier sourcé depuis nulib/bash/src
|
||||
NULIB_SOURCED=1
|
||||
NULIBDIR="$(dirname -- "$NULIBDIR")/../.."
|
||||
else
|
||||
# Fichier non sourcé. Tout exprimer par rapport au script courant
|
||||
NUCORE_SOURCED=
|
||||
NUCOREDIR="$(dirname -- "$0")"
|
||||
if [ -d "$NUCOREDIR/nucore" ]; then
|
||||
NUCOREDIR="$NUCOREDIR/nucore"
|
||||
elif [ -d "$NUCOREDIR/lib/nucore" ]; then
|
||||
NUCOREDIR="$NUCOREDIR/lib/nucore"
|
||||
NULIB_SOURCED=
|
||||
NULIBDIR="$(dirname -- "$0")"
|
||||
if [ -d "$NULIBDIR/nulib" ]; then
|
||||
NULIBDIR="$NULIBDIR/nulib"
|
||||
elif [ -d "$NULIBDIR/lib/nulib" ]; then
|
||||
NULIBDIR="$NULIBDIR/lib/nulib"
|
||||
fi
|
||||
fi
|
||||
elif [ "${BASH_SOURCE[0]}" = /etc/nucore.sh ]; then
|
||||
# Fichier chargé depuis /etc/nucore.sh
|
||||
NUCORE_SOURCED=1
|
||||
elif [ "${BASH_SOURCE[0]}" = /etc/nulib.sh ]; then
|
||||
# Fichier chargé depuis /etc/nulib.sh
|
||||
NULIB_SOURCED=1
|
||||
fi
|
||||
NUCOREDIR="$(cd "$NUCOREDIR" 2>/dev/null; pwd)"
|
||||
NUCOREDIRS=("$NUCOREDIR/bash/src")
|
||||
NULIBDIR="$(cd "$NULIBDIR" 2>/dev/null; pwd)"
|
||||
NULIBDIRS=("$NULIBDIR/bash/src")
|
||||
|
||||
# marqueur pour vérifier que nucore a réellement été chargé. il faut avoir $NUCOREINIT == $NUCOREDIR
|
||||
# marqueur pour vérifier que nulib a réellement été chargé. il faut avoir $NULIBINIT == $NULIBDIR
|
||||
# utilisé par le module base qui doit pouvoir être inclus indépendamment
|
||||
NUCOREINIT="$NUCOREDIR"
|
||||
NULIBINIT="$NULIBDIR"
|
||||
|
||||
## Modules bash
|
||||
NUCORE_LOADED_MODULES=(nucore)
|
||||
NUCORE_DEFAULT_MODULES=(base pretty sysinfos)
|
||||
NULIB_LOADED_MODULES=(nulib)
|
||||
NULIB_DEFAULT_MODULES=(base pretty sysinfos)
|
||||
|
||||
# Si cette variable est non vide, require: recharge toujours le module, même
|
||||
# s'il a déjà été chargé. Cette valeur n'est pas transitive: il faut toujours
|
||||
# recharger explicitement tous les modules désirés
|
||||
NUCORE_FORCE_RELOAD=
|
||||
NULIB_FORCE_RELOAD=
|
||||
|
||||
function nucore__define_functions() {
|
||||
function nucore_check_loaded() {
|
||||
function nulib__define_functions() {
|
||||
function nulib_check_loaded() {
|
||||
local module
|
||||
for module in "${NUCORE_LOADED_MODULES[@]}"; do
|
||||
for module in "${NULIB_LOADED_MODULES[@]}"; do
|
||||
[ "$module" == "$1" ] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
function module:() {
|
||||
NUCORE_MODULE="$1"
|
||||
if ! nucore_check_loaded "$1"; then
|
||||
NUCORE_LOADED_MODULES+=("$1")
|
||||
NULIB_MODULE="$1"
|
||||
if ! nulib_check_loaded "$1"; then
|
||||
NULIB_LOADED_MODULES+=("$1")
|
||||
fi
|
||||
}
|
||||
function function:() {
|
||||
|
@ -96,64 +96,64 @@ function nucore__define_functions() {
|
|||
}
|
||||
}
|
||||
|
||||
function nucore__require:() {
|
||||
local nr__module nr__nucoredir nr__found
|
||||
function nulib__require:() {
|
||||
local nr__module nr__nulibdir nr__found
|
||||
[ $# -gt 0 ] || set DEFAULTS
|
||||
|
||||
# sauvegarder valeurs globales
|
||||
local nr__orig_module="$NUCORE_MODULE"
|
||||
NUCORE_MODULE=
|
||||
local nr__orig_module="$NULIB_MODULE"
|
||||
NULIB_MODULE=
|
||||
|
||||
# garder une copie de la valeur originale et casser la transitivité
|
||||
local nr__force_reload="$NUCORE_FORCE_RELOAD"
|
||||
local NUCORE_FORCE_RELOAD
|
||||
local nr__force_reload="$NULIB_FORCE_RELOAD"
|
||||
local NULIB_FORCE_RELOAD
|
||||
|
||||
for nr__module in "$@"; do
|
||||
nr__found=
|
||||
for nr__nucoredir in "${NUCOREDIRS[@]}"; do
|
||||
if [ -f "$nr__nucoredir/$nr__module.sh" ]; then
|
||||
for nr__nulibdir in "${NULIBDIRS[@]}"; do
|
||||
if [ -f "$nr__nulibdir/$nr__module.sh" ]; then
|
||||
nr__found=1
|
||||
if [ -n "$nr__force_reload" ] || ! nucore_check_loaded "$nr__module"; then
|
||||
NUCORE_LOADED_MODULES+=("$nr__module")
|
||||
source "$nr__nucoredir/$nr__module.sh" || die
|
||||
if [ -n "$nr__force_reload" ] || ! nulib_check_loaded "$nr__module"; then
|
||||
NULIB_LOADED_MODULES+=("$nr__module")
|
||||
source "$nr__nulibdir/$nr__module.sh" || die
|
||||
fi
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z "$nr__found" -a "$nr__module" == DEFAULTS ]; then
|
||||
for nr__module in "${NUCORE_DEFAULT_MODULES[@]}"; do
|
||||
if [ -f "$nr__nucoredir/$nr__module.sh" ]; then
|
||||
for nr__module in "${NULIB_DEFAULT_MODULES[@]}"; do
|
||||
if [ -f "$nr__nulibdir/$nr__module.sh" ]; then
|
||||
nr__found=1
|
||||
if [ -n "$nr__force_reload" ] || ! nucore_check_loaded "$nr__module"; then
|
||||
NUCORE_LOADED_MODULES+=("$nr__module")
|
||||
source "$nr__nucoredir/$nr__module.sh" || die
|
||||
if [ -n "$nr__force_reload" ] || ! nulib_check_loaded "$nr__module"; then
|
||||
NULIB_LOADED_MODULES+=("$nr__module")
|
||||
source "$nr__nulibdir/$nr__module.sh" || die
|
||||
fi
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
[ -n "$nr__found" ] || die "nucore: unable to find module $nr__module in (${NUCOREDIRS[*]})"
|
||||
[ -n "$nr__found" ] || die "nulib: unable to find module $nr__module in (${NULIBDIRS[*]})"
|
||||
done
|
||||
|
||||
# restaurer valeurs globales
|
||||
NUCORE_MODULE="$nr__orig_module"
|
||||
NULIB_MODULE="$nr__orig_module"
|
||||
}
|
||||
|
||||
function require:() {
|
||||
[ -z "$NUCORE_NO_DISABLE_SET_X" ] && [[ $- == *x* ]] && { set +x; local NUCORE_REQUIRE_SET_X=1; }; if [ -n "$NUCORE_REQUIRE_SET_X" ]; then [ -n "$NUCORE_REQUIRE_SET_X_RL1" ] || local NUCORE_REQUIRE_SET_X_RL1; local NUCORE_REQUIRE_SET_X_RL2=$RANDOM; [ -n "$NUCORE_REQUIRE_SET_X_RL1" ] || NUCORE_REQUIRE_SET_X_RL1=$NUCORE_REQUIRE_SET_X_RL2; fi # désactiver set -x de manière réentrante
|
||||
nucore__define_functions
|
||||
nucore__require: "$@"
|
||||
[ -n "$NUCORE_REQUIRE_SET_X" -a "$NUCORE_REQUIRE_SET_X_RL1" == "$NUCORE_REQUIRE_SET_X_RL2" ] && set -x
|
||||
[ -z "$NULIB_NO_DISABLE_SET_X" ] && [[ $- == *x* ]] && { set +x; local NULIB_REQUIRE_SET_X=1; }; if [ -n "$NULIB_REQUIRE_SET_X" ]; then [ -n "$NULIB_REQUIRE_SET_X_RL1" ] || local NULIB_REQUIRE_SET_X_RL1; local NULIB_REQUIRE_SET_X_RL2=$RANDOM; [ -n "$NULIB_REQUIRE_SET_X_RL1" ] || NULIB_REQUIRE_SET_X_RL1=$NULIB_REQUIRE_SET_X_RL2; fi # désactiver set -x de manière réentrante
|
||||
nulib__define_functions
|
||||
nulib__require: "$@"
|
||||
[ -n "$NULIB_REQUIRE_SET_X" -a "$NULIB_REQUIRE_SET_X_RL1" == "$NULIB_REQUIRE_SET_X_RL2" ] && set -x
|
||||
return 0
|
||||
}
|
||||
|
||||
## Autres modules
|
||||
[ -d "$NUCOREDIR/awk/src" ] && inspath "$NUCOREDIR/awk/src" AWKPATH; export AWKPATH
|
||||
[ -d "$NUCOREDIR/python3/src" ] && inspath "$NUCOREDIR/python3/src" PYTHONPATH; export PYTHONPATH
|
||||
[ -d "$NULIBDIR/awk/src" ] && inspath "$NULIBDIR/awk/src" AWKPATH; export AWKPATH
|
||||
[ -d "$NULIBDIR/python3/src" ] && inspath "$NULIBDIR/python3/src" PYTHONPATH; export PYTHONPATH
|
||||
|
||||
## Auto import DEFAULTS
|
||||
nucore__define_functions
|
||||
if [ -n "$NUCORE_SOURCED" -a -z "$NUCORE_NO_IMPORT_DEFAULTS" ]; then
|
||||
nulib__define_functions
|
||||
if [ -n "$NULIB_SOURCED" -a -z "$NULIB_NO_IMPORT_DEFAULTS" ]; then
|
||||
require: DEFAULTS
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue