scripts-reco

Des scripts pour faciliter le reconditionnement de portables - retour accueil

git clone git://bebou.netlib.re/scripts-reco

Log | Files | Refs | README |

common.sh (1254B)


      1 #! /bin/sh
      2 
      3 set -e
      4 
      5 [ "$2" ] && id="$2" || id="$(mktemp -d /tmp/reco.XXX | cut -d'.' -f2)"
      6 tmpdir="/tmp/reco.$id"
      7 chmod -R 744 "$tmpdir"
      8 model_name="$(basename "$1" .sh)"
      9 trap "printf '$id' | xclip -selection clipboard" EXIT QUIT INT
     10 
     11 red="\033[91m";green="\033[92m"
     12 blue="\033[94m";norm="\033[0m"
     13 up_one_line="\033[1F";del_line="\033[0K"
     14 
     15 _ask()    {
     16 	c=""
     17 	while [ "$c" != "o" ] && [ "$c" != "n" ];do
     18 		[ "$c" != "" ] && printf "$up_one_line$del_line"
     19 		printf "$blue$@ (o/n) : $norm" >&2; read c
     20 	done
     21 	[ "$c" = "o" ] && c=ok || c=NOK
     22 }
     23 
     24 inform() { printf "$blue$@ (entrée pour commencer)$norm" >&2;read p; }
     25 inform "Identifiant du test : $id, nom : $model_name"
     26 
     27 launch_test() {
     28 	test_name="$1"
     29 	< "$tmpdir/histo" grep -q "^$1 pass" && return
     30 	. "tests/$test_name" | tee "$tmpdir/$test_name"
     31 	_ask "$test_name ok"
     32 	<<-. tee -a $tmpdir/$test_name
     33 	$test_name : $c
     34 	-------
     35 	.
     36 	< "$tmpdir/histo" sed "/^$test_name/ s/$/ pass/" > "$tmpdir/tmp"
     37 	mv "$tmpdir/tmp" "$tmpdir/histo"
     38 }
     39 
     40 end() {
     41 	[ -f "$tmpdir/histo" ] && < "$tmpdir/histo" awk -v tmp=$tmpdir '{ printf "%s/%s\n",tmp,$1 }' |
     42 		xargs cat | grep . | xclip -selection clipboard
     43 }
     44 
     45 # On lance le test
     46 [ ! -f "$tmpdir/histo" ] && < "$1" awk '/launch_test/ { print $2 }' > "$tmpdir/histo"
     47 . "$1"