Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
Repush: Changed grep regex to work for OSX users + Fixed potential pu…
Browse files Browse the repository at this point in the history
…sh error regarding args

Signed-off-by: Patrick Pedersen <ctx.xda@gmail.com>
  • Loading branch information
CTXz committed Oct 21, 2018
1 parent f56fa91 commit ea17b03
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions host/repush.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,24 @@ function uuid_of_root_file {
# $? - 1: transfer succeeded | 0: transfer failed
function push {

file_cmd_output="$(file -F '|' "$f")"
if echo "$file_cmd_output" | grep -qoP "(?<=\| )(PDF)"; then
file_cmd_output="$(file -F '|' "$1")"

if [ ! -z "$(echo "$file_cmd_output" | grep -o "| PDF")" ]; then
extension="pdf"
else
extension="epub"
fi

# Create placeholder
placeholder="/tmp/repush/$(basename "$f")"
placeholder="/tmp/repush/$(basename "$1")"
touch "$placeholder"

while true; do
if curl --connect-timeout 2 --silent --output /dev/null --form file=@"\"$placeholder\"" http://"$WEBUI_ADDRESS"/upload; then

# Wait for metadata to be generated
while true; do
uuid_of_root_file "$(basename "$f")"
uuid_of_root_file "$(basename "$1")"
if [ ! -z "$RET_UUID" ]; then
break
fi
Expand All @@ -159,7 +160,7 @@ function push {
# Replace placeholder with document
retry=""
while true; do
scp "$f" root@"$SSH_ADDRESS":"/home/root/.local/share/remarkable/xochitl/$RET_UUID.$extension"
scp "$1" root@"$SSH_ADDRESS":"/home/root/.local/share/remarkable/xochitl/$RET_UUID.$extension"

if [ $? -ne 0 ]; then
read -r -p "Failed to replace placeholder! Retry? [Y/n]: " retry
Expand All @@ -178,7 +179,7 @@ function push {

else
retry=""
echo "$f: Failed"
echo "$1: Failed"
read -r -p "Failed to push file! Retry? [Y/n]: " retry

if [[ $retry == "n" || $retry == "N" ]]; then
Expand Down Expand Up @@ -231,10 +232,11 @@ fi

# Check file validity
for f in "$@"; do
file_cmd_output="$(file -F '|' "$f")"
if [ ! -f "$f" ]; then
echo "No such file: $f"
exit -1
elif ! file -F '|' "$f" | grep -qoP "(?<=\| )(PDF|EPUB)"; then
elif [[ -z "$(echo "$file_cmd_output" | grep -o "| PDF")" && -z "$(echo "$file_cmd_output" | grep -o "| EPUB")" ]]; then
echo "Unsupported file format: $f"
echo "Only PDFs and EPUBs are supported"
exit -1
Expand Down

0 comments on commit ea17b03

Please sign in to comment.