-
Notifications
You must be signed in to change notification settings - Fork 20
Several improvements #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
daef3ff
9f789c0
316135d
b74c121
10b7d27
f120a9d
8c0c2bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,28 +70,74 @@ REMARKABLE_HOST=${REMARKABLE_HOST:-remarkable} | |
REMARKABLE_XOCHITL_DIR=${REMARKABLE_XOCHITL_DIR:-.local/share/remarkable/xochitl/} | ||
TARGET_DIR="${REMARKABLE_HOST}:${REMARKABLE_XOCHITL_DIR}" | ||
|
||
# Function to show help | ||
show_help () | ||
{ | ||
echo "Transfer PDF or EPUB document(s) to a reMarkable tablet." | ||
echo "usage: $(basename $0) [options] path-to-file [path-to-file]..." | ||
echo " -h --help print this usage information and exit" | ||
echo " -q --quiet don't print progress information" | ||
echo " -r --toggle-restart toggle whether to restart the tablet (default is given by RESTART_XOCHITL_DEFAULT)" | ||
echo " --uuids-file write the list of uploaded files and their UUIDs to a file" | ||
echo "See also comments/documentation at start of the script." | ||
} | ||
|
||
# Check if we have something to do | ||
if [ $# -lt 1 ]; then | ||
echo "Transfer PDF or EPUB document(s) to a reMarkable tablet." | ||
echo "See comments/documentation at start of script." | ||
echo "usage: $(basename $0) [ -r ] path-to-file [path-to-file]..." | ||
show_help | ||
exit 1 | ||
fi | ||
|
||
RESTART_XOCHITL_DEFAULT=${RESTART_XOCHITL_DEFAULT:-0} | ||
RESTART_XOCHITL=${RESTART_XOCHITL_DEFAULT} | ||
if [ "$1" = "-r" ] ; then | ||
shift | ||
if [ $RESTART_XOCHITL_DEFAULT -eq 0 ] ; then | ||
echo Switching | ||
RESTART_XOCHITL=1 | ||
else | ||
RESTART_XOCHITL=0 | ||
|
||
BE_QUIET=0 | ||
SCP_OPTIONS= | ||
UUIDS_FILE= | ||
|
||
# Print progess information | ||
log () { | ||
if [ $BE_QUIET -eq 0 ]; then | ||
echo "$@" | ||
fi | ||
fi | ||
} | ||
|
||
|
||
# Parse arguments | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would using getopt(1) be easier? or are there linux/osx compatibility issues? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was not aware of getopt(1). Looking at the docs now, it indeed could have saved a little bit of work. I will not attempt change to getopt(1), as it does not seem to offer huge advantages. However, I will keep it in mind when I write argument-parsing next time. |
||
while :; do | ||
case $1 in | ||
-q|--quiet) | ||
shift | ||
BE_QUIET=1 | ||
SCP_OPTIONS="-q" | ||
;; | ||
-h|--help) | ||
show_help | ||
exit 0 | ||
;; | ||
-r|--toggle-restart) | ||
shift | ||
if [ $RESTART_XOCHITL_DEFAULT -eq 0 ] ; then | ||
RESTART_XOCHITL=1 | ||
else | ||
RESTART_XOCHITL=0 | ||
fi | ||
;; | ||
--uuids-file=?*) | ||
UUIDS_FILE=${1#*=} | ||
shift | ||
;; | ||
*) # No more optional arguments | ||
break | ||
esac | ||
done | ||
|
||
# Create directory where we prepare the files as the reMarkable expects them | ||
tmpdir=$(mktemp -d) | ||
if [ $? -ne 0 ]; then | ||
echo "Cannot create a temporary directory. Exiting." | ||
exit 1 | ||
fi | ||
|
||
# Loop over the command line arguments, | ||
# which we expect are paths to the files to be transferred | ||
|
@@ -170,20 +216,25 @@ EOF | |
|
||
else | ||
echo "Unknown extension: $extension, skipping $filename" | ||
rm -rf ${tmpdir}/* | ||
rm -rf ${tmpdir:?}/* | ||
continue | ||
fi | ||
|
||
# Transfer files | ||
echo "Transferring $filename as $uuid" | ||
scp -r ${tmpdir}/* "${TARGET_DIR}" | ||
rm -rf ${tmpdir}/* | ||
log "Transferring $filename as $uuid" | ||
scp -r ${SCP_OPTIONS} ${tmpdir}/* "${TARGET_DIR}" | ||
|
||
# If successful, record the uuid to supplied file | ||
[ $? -eq 0 ] && [ -n "${UUIDS_FILE}" ] && echo "${uuid} ${filename}" >> ${UUIDS_FILE} | ||
|
||
# Clean up | ||
rm -rf ${tmpdir:?}/* | ||
done | ||
|
||
rm -rf ${tmpdir} | ||
rm -rf ${tmpdir:?} | ||
|
||
if [ $RESTART_XOCHITL -eq 1 ] ; then | ||
echo "Restarting Xochitl..." | ||
log "Restarting Xochitl..." | ||
ssh ${REMARKABLE_HOST} "systemctl restart xochitl" | ||
echo "Done." | ||
log "Done." | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"toggle-restart" and "restart the tablet" could be confusing/misleading, since
systemctl restart xochitl
is just restarting the UI service and not rebooting the tablet. for many people "restarting" a device is a reboot or power cycle.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. What do you suggest instead? Saying "restart the tablet's UI" would be accurate but unenlightening, as it does not explain the purpose behind the restart. One could say "refresh the document database on the tablet" but does not explain that the whole UI will refresh.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm just doing a drive-by comment since it's really up to @adaerr -- but FWIW i'd say that rather be technically-correct (but possibly confusing), be user-focused and use terminology that explains the effects visible to the user rather than how it's accomplished. so my suggestion is something like
--make-visible
or--show-docs-now
or something along those lines, and the extended help comment would explain by saying "make the transferred document visible in the UI now (rather than after next reboot / xfer with --make-visible)" or something similar.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestions. I feel that it would still be quite weird to have
-r
short options to expand to--toggle-make-visible
, and the latter is quite a mouthful. And we must have-r
be named-r
and act as a toggle, or we break backward-compatibility. I leave to @adaerr to make the final call.