runner-cbr.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/sh
  2. #
  3. # author: lotus
  4. # license: isc
  5. # site: git.zerohack.xyz/lotus/cbr-convert
  6. #
  7. # Helper file for cbr-convert.sh
  8. # don't call this on its own.
  9. LOGDIR=~/.cbr-convert
  10. LOGFILE=$LOGDIR/errors.log
  11. trap fun_catch_sigint INT
  12. # check if cbr file
  13. # cuts off extension and compares it
  14. fun_is_cbr () {
  15. L_FILE="$1"
  16. # ignore directories
  17. if [ -f "$L_FILE" ] ; then
  18. L_FILE_EXT="${L_FILE##*.}"
  19. if [ "$L_FILE_EXT" = "cbr" ] ; then
  20. unset L_FILE L_FILE_EXT
  21. return 0
  22. fi
  23. unset L_FILE_EXT
  24. fi
  25. unset L_FILE
  26. return 1
  27. }
  28. # run when ctrl-c is pressed
  29. fun_catch_sigint () {
  30. exit 0
  31. }
  32. fun_log_error () {
  33. if ! [ -d $LOGDIR ] ; then
  34. mkdir $LOGDIR
  35. fi
  36. echo "$(date): $1" | tee -a $LOGFILE
  37. exit 1
  38. }
  39. # were we called by cbr-convert?
  40. if ! [ "$1" = "secretargument" ] ; then
  41. fun_log_error "Do not call this script on its own, use cbr-convert!"
  42. elif [ "$#" -lt 2 ] ; then
  43. fun_log_error "You must pass a directory"
  44. else
  45. shift
  46. fi
  47. # does the dir we were given exist?
  48. if [ -d "$1" ] ; then
  49. cd "$1" || fun_log_error "Could not enter directory $1"
  50. echo "Working On: $1"
  51. else
  52. fun_log_error "Passed a bad dir? : $1"
  53. exit 1
  54. fi
  55. CBRS_FOUND="no"
  56. for FILE in * ; do
  57. [ -e "$FILE" ] || continue
  58. if fun_is_cbr "$FILE" ; then
  59. CBRS_FOUND="yes"
  60. echo "Converting: $FILE"
  61. DIR="${FILE%.*}"
  62. mkdir "$DIR"
  63. unar -quiet ./"$FILE" -o "$DIR" >> $LOGFILE 2>&1
  64. zip --quiet -r "$DIR".cbz "$DIR" >> $LOGFILE 2>&1
  65. rm -r "$DIR"
  66. fi
  67. done # conversion complete
  68. # put .cbr files into trash
  69. if [ "$CBRS_FOUND" = "yes" ] ; then
  70. trash-put ./*.cbr
  71. fi
  72. exit 0