reHackable / scripts

[ THIS PROJECT IS CURRENTLY ON HALT :( ] A set of bash scripts that may enhance your reMarkable experience
GNU General Public License v3.0
235 stars 29 forks source link

repush: uppercase extension PDF does not work #21

Open karenerobinson opened 4 years ago

karenerobinson commented 4 years ago

I said this elsewhere, but thank you for this script.

I have it working to send pdf files from my mac to my tablet, and I'm very happy about that. I can't send epub files, per https://github.com/reHackable/scripts/issues/14 (which is fine with me)

Also, I can only send files that are .pdf, not .PDF. if I send a .PDF file, a blank pdf is created in the root directory on reMarkable with the lower-case filename, and the script seems caught in an infinite loop.

Likely this should be caught by the error-catching code that I removed on my machine since my grep does not have -P

#  elif [ -z $is_directory ] && ! echo "$1" | grep -qP "\.pdf$" && ! echo "$1" | grep -qP "\.epub$" ; then
#    echo "repush: File extension invalid or missing: $1"
#    return 0

The first thing I tried was naively rewriting the above to only check for "pdf" (since I disabled the epub issue to get up and running on a mac with no -P option in grep)

    # added by krobinso
  elif [ -z $is_directory ] && ! echo "$1" | grep -q ".pdf" && ! echo "$1"; then
    echo "repush: File extension invalid or missing: $1"
    return 0
    # end addition
#  elif [ -z $is_directory ] && ! echo "$1" | grep -qP "\.pdf$" && ! echo "$1" | grep -qP "\.epub$" ; then
#    echo "repush: File extension invalid or missing: $1"
#    return 0
#******

The result of this is somewhat interesting: when I send a file like filename.PDF,

vdrummer commented 4 years ago

Perl regexes are not needed here, so I just removed the -P and added case insensitivity. I could only test it on 1.7, though.

karenerobinson commented 4 years ago

Thanks, this renders my edits unnecessary, I can push .pdf files now. my reMarkable says it's on on 2.0.2.0. bash is 3.2.57(1)-release

for what it's worth I still can't push .PDF files: I try to push schematiccap.PDF and I get a blank file on the remarkable called schematiccap.pdf (it appears, it has a cloud-download icon, then it gets a checkmark - so I assume it finishes). But the repush.sh script never finishes, I eventually ctrl-C to exit it.

KER-MBP-6:Downloads$ echo "${BASH_VERSION}"
3.2.57(1)-release
KER-MBP-6:host$ ls sch*
schematic.pdf       schematiccap.PDF

KER-MBP-6:host$ bash repush.sh schematiccap.PDF 
^C
KER-MBP-6:host$ bash repush.sh schematic.pdf 
schematic.pdf                                                                                     100%   31KB   3.8MB/s   00:00    
Exit request sent.
repush: Successfully transferred 1 out of 1 files

IMG_10201

vdrummer commented 4 years ago

I just tried again with 1.7. The name on my device has an uppercase suffix (-> ".PDF"). Maybe 2.0 changes suffixes to lower case. If that's the case, the script wouldn't be able to leave the loop in line 362.

I don't have 2.0, so all I can do is guess, unfortunately. You could try changing the suffix of the name that is used internally to lowercase. That way, even if the web interface changes the case of the file name, repush won't get stuck. Just replace line 341 (the definition of placeholder_basename) with placeholder_basename="$(basename "$1" | sed 's/PDF$/pdf/')"

If that actually solves the problem, I will write a more general version and submit yet another PR.