Advertisement
KirboWnz

laser_status.sh

Sep 7th, 2023
1,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.38 KB | None | 0 0
  1. root@creality /usr/share [#] cat /usr/bin/laser_status.sh
  2. #!/bin/sh
  3.  
  4. FW_PATH=/usr/share/laser/fw
  5. LOG_FILE=/tmp/laser_update.log
  6. FLAG_FILE=/tmp/.laser_updating
  7.  
  8. NO_REPORT=0
  9. DO_REPORT=1
  10.  
  11. write_log()
  12. {
  13.     [ -e $LOG_FILE ] || touch $LOG_FILE
  14.     echo "[$(date "+%Y-%m-%d %H:%M:%S")] $1" >> $LOG_FILE
  15. }
  16.  
  17. update_fw()
  18. {
  19.     local fw_bin
  20.     local output
  21.     local ret
  22.  
  23.     if [ $(ls $FW_PATH/*.bin | wc -l) -eq 1 ]; then
  24.         fw_bin=$(ls $FW_PATH/*.bin)
  25.         touch $FLAG_FILE
  26.         output=$(laser_ota_util /dev/serial/by-id/creality-laser $fw_bin)
  27.         ret=$?
  28.         rm -f $FLAG_FILE && sync
  29.         if [ $ret -eq 0 ]; then
  30.             write_log "laser fw update none!"
  31.             echo $DO_REPORT
  32.         elif [ $ret -eq 1 ]; then
  33.             write_log "laser fw update success!"
  34.             echo $NO_REPORT
  35.         else
  36.             write_log "$output"
  37.             write_log "laser fw update fail, ret=$ret!"
  38.             echo $DO_REPORT
  39.         fi
  40.     else
  41.         write_log "we should keep only one laser firmware file!"
  42.         echo $DO_REPORT
  43.     fi
  44. }
  45.  
  46. #echo "MDEV=$MDEV ; ACTION=$ACTION ; DEVPATH=$DEVPATH" > /dev/console
  47.  
  48. case "${ACTION}" in
  49. add)
  50.     ret=$(update_fw)
  51.     if [ $ret -eq $DO_REPORT ]; then
  52.         ubus call laser set_state '{"laser_plugged": 1}'
  53.     fi
  54.     ;;
  55. remove)
  56.     ubus call laser set_state '{"laser_plugged": 0}'
  57.     ;;
  58. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement