custom 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2019 Clementine Computing LLC.
  4. #
  5. # This file is part of PopuFare.
  6. #
  7. # PopuFare is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # PopuFare is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. func="$1"
  21. param="$2"
  22. echo "$0 , $func , $param ." >> /tmp/custom.log
  23. if [[ "$func" == "dim" ]] ; then
  24. infofn="/tmp/kiosk.info"
  25. export DISPLAY=':0'
  26. export XAUTHORITY='/home/pi/.Xauthority'
  27. if [[ -e "/tmp/kiosk.info" ]] ; then
  28. disp=`grep DISPLAY $infofn | cut -f2 -d'='`
  29. auth=`grep XAUTHORITY $infofn | cut -f2 -d'='`
  30. export DISPLAY="$disp"
  31. export XAUTHORITY="$auth"
  32. fi
  33. /usr/bin/xset dpms force off
  34. elif [[ "$func" == "undim" ]] ; then
  35. infofn="/tmp/kiosk.info"
  36. export DISPLAY=':0'
  37. export XAUTHORITY='/home/pi/.Xauthority'
  38. if [[ -e "/tmp/kiosk.info" ]] ; then
  39. disp=`grep DISPLAY $infofn | cut -f2 -d'='`
  40. auth=`grep XAUTHORITY $infofn | cut -f2 -d'='`
  41. export DISPLAY="$disp"
  42. export XAUTHORITY="$auth"
  43. fi
  44. /usr/bin/xset s noblank
  45. /usr/bin/xset s off
  46. /usr/bin/xset -dpms
  47. elif [[ "$func" == "interface" ]] ; then
  48. if [[ "$param" == "up" ]]; then
  49. /sbin/ip link set eth0 up
  50. elif [[ "$param" == "down" ]] ; then
  51. /sbin/ip link set eth0 down
  52. fi
  53. elif [[ "$func" == "ts_calibrate" ]] ; then
  54. /usr/bin/ts_calibrate
  55. elif [[ "$func" == "volume" ]] ; then
  56. vol=100
  57. if [[ "$param" != "" ]] ; then vol=`printf "%2d" "$param" 2> /dev/null` ; fi
  58. chan=`amixer controls | grep Volume | head -n1 | cut -f1 -d',' | cut -f2 -d'='`
  59. amixer cset numid=$chan -- ${vol}% > /dev/null
  60. elif [[ "$func" == "say" ]] ; then
  61. echo "$param" | espeak --stdin --stdout | aplay 2> /dev/null
  62. elif [[ "$func" == "getconfig" ]] ; then
  63. cfgfn="/home/bus/config/popufare.config"
  64. if [[ -e $cfgfn ]] ; then
  65. cat $cfgfn | tr '\n' ' '
  66. else
  67. echo "file-not-found"
  68. fi
  69. elif [[ "$func" == "setconfig" ]] ; then
  70. cfgfn="/home/bus/config/popufare.config"
  71. _v=`echo "$param" | tr '=' ' ' | grep -P -o 'volume (\d+)' | cut -f2 -d' '`
  72. _b=`echo "$param" | tr '=' ' ' | grep -P -o 'brightness (\d+)' | cut -f2 -d' '`
  73. _d=`echo "$param" | tr '=' ' ' | grep -P -o 'showdimclock (\d+)' | cut -f2 -d' '`
  74. if [[ "$_v" == "" ]] ; then _v=100; fi
  75. if [[ "$_b" == "" ]] ; then _b=100; fi
  76. if [[ "$_d" == "" ]] ; then _d="0"; fi
  77. _t=`mktemp`
  78. echo -e "volume=$_v\nbrightness=$_b\nshowdimclock=$_d\n" > $_t
  79. mv $_t $cfgfn
  80. cat $cfgfn | tr '\n' ' '
  81. elif [[ "$func" == "reboot" ]] ; then
  82. /sbin/reboot
  83. fi
  84. exit 0