watchdog.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. set -e
  3. version=1
  4. function print_centered {
  5. [[ $# == 0 ]] && return 1
  6. declare -i TERM_COLS="$(tput cols)"
  7. declare -i str_len="${#1}"
  8. [[ $str_len -ge $TERM_COLS ]] && {
  9. echo "$1";
  10. return 0;
  11. }
  12. declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))"
  13. [[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" "
  14. filler=""
  15. for (( i = 0; i < filler_len; i++ )); do
  16. filler="${filler}${ch}"
  17. done
  18. printf "%s%s%s" "$filler" "$1" "$filler"
  19. [[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}"
  20. printf "\n"
  21. return 0
  22. }
  23. print_centered "$(tput setaf 9)"
  24. print_centered " _ _ _ _ _ ____ "
  25. print_centered "| | | |___| |_ ___| |_| \ ___ ___ "
  26. print_centered "| | | | .'| _| _| | | | . | . |"
  27. print_centered "|_____|__,|_| |___|_|_|____/|___|_ |"
  28. print_centered " |___|"
  29. echo -n "$(tput setaf 7)"
  30. print_centered "Watchdog hardware v1.0"
  31. if [ -f /tmp/watchdog.1 ];then rm /tmp/watchdog.1;fi
  32. cat <<'EOF'>> /tmp/watchdog.1
  33. #Watchdog
  34. SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="watchdog"
  35. EOF
  36. if [ -f /tmp/watchdog.2 ];then rm /tmp/watchdog.2;fi
  37. cat <<'EOF'>> /tmp/watchdog.2
  38. #!/bin/bash
  39. timing=18
  40. stty -F /dev/watchdog ispeed 9600 ospeed 9600 -ignpar cs8 -cstopb -echo
  41. echo -n -e "\x$timing" >/dev/watchdog
  42. EOF
  43. chmod +x /tmp/watchdog.2
  44. sudo mv /tmp/watchdog.2 /usr/local/bin/wd_control.sh
  45. sudo mv /tmp/watchdog.1 /etc/udev/rules.d/10-watchdog.rules
  46. if ! grep "wd_control.sh" /etc/crontab >/dev/null
  47. then
  48. sudo cp /etc/crontab /tmp/crontab
  49. sudo chmod 777 /tmp/crontab
  50. echo "" >>/tmp/crontab
  51. echo "* * * * * root /usr/local/bin/wd_control.sh" >> /tmp/crontab
  52. sudo chmod 644 /tmp/crontab
  53. sudo mv /tmp/crontab /etc/
  54. fi
  55. sudo /etc/init.d/cron restart >/dev/null
  56. sleep 1
  57. print_centered "Installation Done..."
  58. print_centered ""