Phylum

Synology HP Printer Firmware Script

Sep 23rd, 2012
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.25 KB | None | 0 0
  1. # WARNING: I have very basic/limited unix/linux
  2. # scripting abilities.
  3.  
  4. # BEGIN HP 1020 PRINTER SCRIPT
  5. echo "`date` ----------------BEGIN PRINTER SCRIPT `date` --------------" >> /var/log/hp
  6. if [ "$ACTION" = "add" ]
  7. then
  8.      # OK So the action is what we expected
  9.      echo "`date` : Action is the expected result: '$ACTION'" >> /var/log/hp
  10.  
  11.      # Lets validate the product ID
  12.      HPPRODUCTID="3f0/2b17/100"
  13.      #HPPRODUCTID=03f0/4117/100
  14.  
  15.      echo "`date` : HP Product ID set to '$HPPRODUCTID'" >> /var/log/hp
  16.  
  17.      if [ "$PRODUCT" = "$HPPRODUCTID" ]
  18.      then
  19.           # OK So the product ID is what we expected
  20.           echo "`date` : Product is the expected result: '$PRODUCT'" >> /var/log/hp
  21.  
  22.           # OK So the action is what we expected
  23.           echo "`date` : Action is the expected result: '$ACTION'" >> /var/log/hp
  24.  
  25.           # Adding a pause to make sure its fully initialized before we try to upload firmware
  26.           printersleep=5
  27.           echo "`date` : Sleeping $printersleep seconds before preparing to upload firmware to printer..." >> /var/log/hp
  28.           sleep $printersleep
  29.           echo "`date` : Finished sleeping $printersleep seconds; Continuing with firmware upload." >> /var/log/hp
  30.  
  31.           # Set path to HP firmware file
  32.           HPFIRMWARE="/usr/syno/hotplug/firmware/sihp1020.dl"
  33.  
  34.           echo "`date` : Firmware path set to: '$HPFIRMWARE'" >> /var/log/hp
  35.  
  36.           # Lets make sure the firmware file not only actually
  37.           # exists in the path above, but has a size greater than zero.
  38.           # Alternatively we could use
  39.           #     -e = simply check if the file exists
  40.           #     -a = same as -e but has been deprecated and use discouraged
  41.           #     -f = make sure its a regular file, not a directory or device file
  42.           #     -r = make sure file is readable
  43.           if [ -s "$HPFIRMWARE" ]
  44.           then
  45.                 # OK So the Firmware is present!
  46.                 echo "`date` : Firmware file '$HPFIRMWARE' is present" >> /var/log/hp
  47.  
  48.                 # At this point all should be fine!
  49.                 echo "`date` : Sending firmware to printer..." >> /var/log/hp
  50.                 cat $HPFIRMWARE > /dev/usb/lp0
  51.                 echo "`date` : Finished sending firmeware to printer!" >> /var/log/hp
  52.                 #echo "`date` ----------------END PRINTER SCRIPT `date` --------------" >> /var/log/hp
  53.           else
  54.                 # Whoops - the firmware is missing it seems!
  55.                 echo "`date` : ERROR: Missing Firmware File: $HPFIRMWARE" >> /var/log/hp
  56.                 echo "`date` : Download firmware: http://oleg.wl500g.info/hplj/sihp1020.dl/ " >> /var/log/hp
  57.                 #echo "`date` ----------------END PRINTER SCRIPT `date` --------------" >> /var/log/hp
  58.           fi
  59.      else
  60.           # The device/product ID is different than we anticipated
  61.           # Check the log to see what it is
  62.           echo "`date` : WARN: Product is not '$HPPRODUCTID', its '$PRODUCT'" >> /var/log/hp
  63.      fi
  64. else
  65.      # The action is different than we anticipated
  66.      # Check the log to see what it is
  67.      echo "`date` : WARN: Action is not add, its '$ACTION'" >> /var/log/hp
  68. fi
  69. echo "`date` ----------------END PRINTER SCRIPT `date` --------------" >> /var/log/hp
Advertisement
Add Comment
Please, Sign In to add comment