diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2023-01-01 17:07:37 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2023-01-01 17:07:37 -0300 |
commit | a6d0aeca708c5a6f460ec6b2d62aa3522e00ba53 (patch) | |
tree | e896a089003ee3aebcabea833642ba2f80404c18 /copy-item-to-kobo | |
parent | f375d80d17d7ab02e7045d5f2aa2eeff6192f4f6 (diff) | |
download | scripts-a6d0aeca708c5a6f460ec6b2d62aa3522e00ba53.tar.gz scripts-a6d0aeca708c5a6f460ec6b2d62aa3522e00ba53.tar.bz2 |
Feat: adds copy-item-to-kobo
Diffstat (limited to 'copy-item-to-kobo')
-rwxr-xr-x | copy-item-to-kobo | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/copy-item-to-kobo b/copy-item-to-kobo new file mode 100755 index 0000000..0650a52 --- /dev/null +++ b/copy-item-to-kobo @@ -0,0 +1,47 @@ +#!/bin/bash +# +# A mini-wrapper to copy a local item to kobo. +# + +# Parameters +BASENAME="`basename $0`" +BASEFOLDER="$HOME/data/doc" +REMOTE_BASE="/mnt/sd" +REMOTE="kobo" +PATTERN="$1" +TMPFILE="tmpwork" + +# Thanks https://serverfault.com/a/764403 +# https://serverfault.com/questions/36421/stop-ssh-login-from-printing-motd-from-the-client#38160 +function silentSsh { + local connectionString="$1" + shift + local commands="$*" + if [ -z "$commands" ]; then + commands=`cat` + fi + ssh -T $connectionString "$commands" +} + +# Check +if [ -z "$PATTERN" ]; then + echo "usage: $BASENAME <pattern>" + exit 1 +fi + +# Dispatch +show --search "$PATTERN" | while read item; do + dirname="`dirname "$item"`" + + echo "Copying $item..." + + silentSsh $REMOTE <<EOC + mkdir -p "$REMOTE_BASE/$dirname" + touch "$REMOTE_BASE/$item" +EOC + + scp "$BASEFOLDER/$item" "$REMOTE:$REMOTE_BASE/$TMPFILE" + silentSsh $REMOTE <<EOS + mv "$REMOTE_BASE/$TMPFILE" "$REMOTE_BASE/$item" +EOS +done |