Dotfiles for my tiling window manager + terminal workflow.
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.

52 lines
1.2 KiB

  1. #!/bin/bash
  2. # https://github.com/yishilin14/asc-key-to-qr-code-gif
  3. # Check requirements
  4. hash qrencode 2>/dev/null || { echo >&2 "Aborting: qrencode not installed"; exit 1; }
  5. # Check argument
  6. if [ $# -ne 2 ]; then
  7. echo "Usage: $0 <ascii armor key filename> <gif filename>"
  8. exit 1
  9. fi
  10. asc_filename=$1
  11. if [ ! -f ${asc_filename} ]; then
  12. echo "Error: ${asc_filename} not found"
  13. exit 1
  14. fi
  15. # Settings
  16. gif_filename=$2
  17. gif_delay=100
  18. qrcode_size=1732
  19. qrcode_version=30
  20. # Split the file
  21. rm -f ${asc_filename}.split*
  22. split -b ${qrcode_size} ${asc_filename} ${asc_filename}.split
  23. # Generate png
  24. for f in ${asc_filename}.split*; do
  25. qrencode -v ${qrcode_version} -o $f.png < $f
  26. rm $f
  27. done
  28. if hash zbarimg 2>/dev/null; then
  29. # Check png
  30. > ${asc_filename}.scanned
  31. for f in ${asc_filename}.split*; do
  32. printf %s "$(zbarimg --raw -q $f)" >> ${asc_filename}.scanned
  33. done
  34. printf %s "$(cat ${asc_filename})" | diff ${asc_filename}.scanned -
  35. rm ${asc_filename}.scanned
  36. else
  37. echo "Skip testing: zbarimg nout installed"
  38. fi
  39. # Convert to gif
  40. convert -delay ${gif_delay} ${asc_filename}.split* ${gif_filename}
  41. echo "Generated: ${gif_filename}"
  42. # Clean up png
  43. rm ${asc_filename}.split*