kun

un outil de sondage - retour accueil

git clone git://bebou.netlib.re/kun
Log | Files | Refs | README |

utils.sh (1198B)


      1 red="\033[91m"
      2 green="\033[92m"
      3 blue="\033[94m"
      4 norm="\033[0m"
      5 
      6 _mark() { sed 's/^//'; }
      7 
      8 _die() { echo "$red$@$norm" | _mark >&2 ;return 1; }
      9 
     10 _success() { echo "$green$@$norm"  | _mark >&2; }
     11 
     12 _inform() { echo "$blue$@$norm" | _mark >&2; }
     13 
     14 _cmdlog() { [ -e "$logfile" ] && echo "$@" >&3; }
     15 
     16 _questionexists()   { local id;id="${1:?missing parameter}";[ -d "/tmp/kun.$id" ]; }
     17 
     18 _nameexists() {
     19 	local id name;id="${1:?missing parameter}";name="${2:?missing parameter}"
     20 	[ $(find /tmp/kun.$id/ -name "$name-*" | wc -l) -gt "0" ]
     21 }
     22 
     23 _answerexists() {
     24 	local id idrep;id="${1:?missing parameter}";idrep="${2:?missing parameter}"
     25 	[ $(find /tmp/kun.$id/ -name "*-$idrep" | wc -l) -gt "0" ]
     26 }
     27 
     28 # 2 si le sondage n'existe pas
     29 _ananswerexists() {
     30 	local id answers
     31 	id="${1:?missing parameter}"
     32 	answers=$(find /tmp/kun.$id -type f -not -name question)
     33 	[ -n "$answers" ]
     34 }
     35 
     36 # voir le fichier de log de la session en cours
     37 _showlog() {
     38 	local id
     39 	[ -z "$logfile" ] && { _die "Pas de session interactive en cours"; return 1; }
     40 	id="$(basename $logfile | cut -d'.' -f2)"
     41 	_inform "identifiant du fichier de log : $id"
     42 	cat $logfile || { _die "Problème à la lecture du fichier de log $id";return 1; }
     43 }