73 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
| ##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
 | |
| ## Charger si possible les librairies de ulib depuis /etc/ulib. Sinon, charger
 | |
| ## la librairie depuis le répertoire courant. Nécessite bash.
 | |
| ##@cooked nocomments
 | |
| 
 | |
| # Ce fichier doit être *sourcé* depuis un répertoire ulib créé par ulibsync. Si
 | |
| # ce fichier n'est pas sourcé, alors le répertoire ulib doit être placé dans le
 | |
| # répertoire du script qui inclue ce fichier.
 | |
| 
 | |
| ULIBDIR="${BASH_SOURCE[0]}"
 | |
| if [ -n "$ULIBDIR" -a -f "$ULIBDIR" ]; then
 | |
|     # Fichier sourcé
 | |
|     ULIBDIR="$(dirname "$ULIBDIR")"
 | |
| else
 | |
|     # Fichier non sourcé. Tout exprimer par rapport au script courant
 | |
|     ULIBDIR="$(dirname "$0")"
 | |
|     if [ -d "$ULIBDIR/ulib" ]; then
 | |
|         ULIBDIR="$ULIBDIR/ulib"
 | |
|     elif [ -d "$ULIBDIR/lib/ulib" ]; then
 | |
|         ULIBDIR="$ULIBDIR/lib/ulib"
 | |
|     fi
 | |
| fi
 | |
| ULIBDIR="$(cd "$ULIBDIR" 2>/dev/null; pwd)"
 | |
| 
 | |
| function __ulibver_parse() {
 | |
| # copie verbatim de la fonction parseversion() du script ulib dans nutools
 | |
|     if [ -n "$2" ]; then
 | |
|         local version="${1:-${version:-000000000}}"
 | |
|         local major minor patch pversion
 | |
|     else
 | |
|         version="${1:-${version:-000000000}}"
 | |
|     fi
 | |
|     while [ ${#version} -lt 9 ]; do version="0$version"; done
 | |
|     major="${version:0:3}"; while [ ${#major} -gt 1 -a "${major#0}" != "$major" ]; do major="${major#0}"; done
 | |
|     minor="${version:3:3}"; while [ ${#minor} -gt 1 -a "${minor#0}" != "$minor" ]; do minor="${minor#0}"; done
 | |
|     patch="${version:6:3}"; while [ ${#patch} -gt 1 -a "${patch#0}" != "$patch" ]; do patch="${patch#0}"; done
 | |
|     pversion="$major.$minor.$patch"
 | |
|     [ -n "$2" ] && eval "${2}version=\$version; ${2}major=\$major; ${2}minor=\$minor; ${2}patch=\$patch; ${2}pversion=\$pversion"
 | |
| }
 | |
| function __ulibver_check() {
 | |
|     # tester si la version ulib du système est plus récente que la version ulib
 | |
|     # du répertoire courant
 | |
|     local version=000000000 major minor patch pversion
 | |
|     local sversion=000000000 smajor sminor spatch spversion
 | |
|     [ -f "$ULIBDIR/.ulibver" ] && __ulibver_parse "$(<"$ULIBDIR/.ulibver")"
 | |
|     [ -f "/etc/.ulibver" ] && __ulibver_parse "$(<"/etc/.ulibver")" s
 | |
|     # si le système n'a pas .ulibver, le test échoue
 | |
|     [ -n "$smajor" ] || return 1
 | |
|     # la version majeure doit correspondre
 | |
|     [ "$smajor" -eq "$major" ] || return 1
 | |
|     # puis tester si version mineure plus récente
 | |
|     [ "$sminor" -gt "$minor" ] && return 0
 | |
|     [ "$sminor" -lt "$minor" ] && return 1
 | |
|     # puis tester patchlevel
 | |
|     [ "$spatch" -gt "$patch" ]
 | |
| }
 | |
| 
 | |
| if [ -f /etc/ulib ] && __ulibver_check; then
 | |
|     unset -f __ulibver_parse
 | |
|     unset -f __ulibver_check
 | |
|     . /etc/ulib
 | |
| elif [ -f "$ULIBDIR/ulib" ]; then
 | |
|     unset -f __ulibver_parse
 | |
|     unset -f __ulibver_check
 | |
|     . "$ULIBDIR/ulib"
 | |
| else
 | |
|     echo "error: Unable to find neither $ULIBDIR/ulib nor /etc/ulib" 1>&2
 | |
|     exit 1
 | |
| fi
 | |
| 
 | |
| uprovide auto
 | |
| urequire DEFAULTS
 |