travis-emu.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. parse_yaml2() {
  2. local prefix=$2
  3. local s
  4. local w
  5. local fs
  6. s='[[:space:]]*'
  7. w='[a-zA-Z0-9_]*'
  8. fs="$(echo @|tr @ '\034')"
  9. sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
  10. -e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" |
  11. awk -F"$fs" '{
  12. indent = length($1)/2;
  13. if (length($2) == 0) { conj[indent]="+";} else {conj[indent]="";}
  14. vname[indent] = $2;
  15. for (i in vname) {if (i > indent) {delete vname[i]}}
  16. if (length($3) > 0) {
  17. vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
  18. printf("%s%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, conj[indent-1],$3);
  19. }
  20. }' | sed 's/_=/+=/g'
  21. }
  22. echo=printf
  23. eval $(parse_yaml2 .travis.yml config_)
  24. #parse_yaml2 .travis.yml
  25. installlength=${#config_install[@]}
  26. for (( i=0; i<${installlength}; i++ )); do
  27. printf "\033[37minstalling %d/%d \033[1m%s\033[21m:\033[0m\n" $(($i + 1)) ${installlength} "${config_install[$i]}"
  28. CMD=${config_install[$i]}
  29. if [[ ${CMD:0:1} == "(" ]] ; then
  30. sh -c "${config_install[$i]}"
  31. else
  32. ${config_install[$i]}
  33. fi
  34. if [ $? -eq 0 ] ; then
  35. printf "%s \033[92m\033[1m%s\033[21m\033[0m\n" "$CMD" "OK"
  36. else
  37. printf "%s \033[91m\033[1m%s\033[21m\033[0m\n" "$CMD" "FAILED"
  38. exit 1
  39. fi
  40. done
  41. scriptlength=${#config_script[@]}
  42. for (( i=0; i<${scriptlength}; i++ )); do
  43. printf "\033[36mtesting %d/%d \033[1m%s\033[21m:\033[0m\n" $(($i + 1)) ${scriptlength} "${config_script[$i]}"
  44. CMD=${config_script[$i]}
  45. if [[ ${CMD:0:1} == "(" ]] ; then
  46. sh -c "${config_script[$i]}"
  47. else
  48. ${config_script[$i]}
  49. fi
  50. if [ $? -eq 0 ] ; then
  51. printf "%s \033[92m\033[1m%s\033[21m\033[0m\n" "${config_script[$i]}" "OK"
  52. else
  53. printf "%s \033[91m\033[1m%s\033[21m\033[0m\n" "${config_script[$i]}" "FAILED"
  54. exit 1
  55. fi
  56. done
  57. after_scriptlength=${#config_after_script[@]}
  58. for (( i=0; i<${after_scriptlength}; i++ )); do
  59. printf "\033[35mcleaning up %d/%d \033[1m%s\033[21m\033[0m: %s\n" $(($i + 1)) ${after_scriptlength} "${config_after_script[$i]}"
  60. ${config_after_script[$i]}
  61. if [ $? -eq 0 ] ; then
  62. printf "%s \033[92m\033[1m%s\033[21m\033[0m\n" "${config_after_script[$i]}" "OK"
  63. else
  64. printf "%s \033[91m\033[1m%s\033[21m\033[0m\n" "${config_after_script[$i]}" "FAILED"
  65. exit 1
  66. fi
  67. done