OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.9 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../sysfiles/etc_rc.d_functions.in.txt
  5. # Copyright (C) 2006 - 2007 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; version 2 of the License. A copy of the
  12. # GNU General Public License can be found in the file COPYING.
  13. # --- SDE-COPYRIGHT-NOTE-END ---
  14. # http://en.wikipedia.org/wiki/ANSI_escape_code
  15. #
  16. ECHO='echo -e'
  17. ESC='\e' # 033
  18. BELL='\a' # 07
  19. ART_SUCCESS=" OK "
  20. ART_FAILURE=" FAIL"
  21. ART_NEXT=" v "
  22. COLOR_TITLE="$ESC[36m" # cyan
  23. COLOR_NORMAL="$ESC[0m" # default (no attributes)
  24. COLOR_SUCCESS="$ESC[32m" # green
  25. COLOR_FAILURE="$ESC[31m" # red
  26. MOVE_EOL="$ESC[222G" # 222 columns to the right... kind-of-eol
  27. MOVE_UP="$ESC[1A" # 1 line up (eat last \n)
  28. # ${#foo} works on bash, dash and pdksh, not on ash
  29. MOVE_LEFT_STATUS="$ESC[${#ART_SUCCESS}D" # move left the length of $ART_SUCCESS
  30. MOVE_LEFT_NEXT="$ESC[${#ART_NEXT}D" # move left the length of $ART_NEXT
  31. title() {
  32. local x=1 columns=
  33. columns=$( if ! stty size -F /dev/tty; then
  34. stty size -F /dev/console
  35. fi 2> /dev/null | cut -d' ' -f2 )
  36. [ -n "$columns" ] || columns=80
  37. # fill with dots with an "arrow" pointing down at the end.
  38. for (( x=1; x<columns; x++ )); do
  39. $ECHO -n '.'
  40. done
  41. $ECHO -n "$MOVE_LEFT_NEXT$ART_NEXT\r"
  42. # and the title
  43. $ECHO "$COLOR_TITLE$* $COLOR_NORMAL"
  44. error=0
  45. }
  46. status() {
  47. $ECHO -n "$MOVE_UP$MOVE_EOL$MOVE_LEFT_STATUS"
  48. if [ $error -eq 0 ]; then
  49. $ECHO "$COLOR_SUCCESS$ART_SUCCESS$COLOR_NORMAL"
  50. else
  51. $ECHO "$BELL$COLOR_FAILURE$ART_FAILURE$COLOR_NORMAL"
  52. fi
  53. }
  54. check() {
  55. $* || error=$?
  56. }
  57. action() {
  58. title "$1"
  59. shift
  60. $* || error=$?
  61. status
  62. }