From 154d15b890eb9eb0d5e527b0f3b9693ac1e22573 Mon Sep 17 00:00:00 2001 From: Rien Maertens Date: Fri, 3 Apr 2020 12:15:53 +0200 Subject: [PATCH 1/3] Apply shellcheck and shfmt --- .editorconfig | 7 +++++++ reStream.sh | 42 ++++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..60c6401 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +[*.sh] +indent_style = space +indent_size = 4 + +shell_variant = posix +binary_next_line = true +switch_case_indent = true diff --git a/reStream.sh b/reStream.sh index efafff6..319c375 100755 --- a/reStream.sh +++ b/reStream.sh @@ -7,11 +7,11 @@ landscape=true # rotate 90 degrees to the right # loop through arguments and process them while [ $# -gt 0 ]; do case "$1" in - -p|--portrait) + -p | --portrait) landscape=false shift ;; - -d|--destination) + -d | --destination) ssh_host="$2" shift shift @@ -19,6 +19,7 @@ while [ $# -gt 0 ]; do *) echo "Usage: $0 [-p] [-d ]" exit 1 + ;; esac done @@ -28,10 +29,13 @@ height=1872 bytes_per_pixel=2 loop_wait="true" loglevel="info" -ssh_cmd="ssh -o ConnectTimeout=1 "$ssh_host"" + +ssh_cmd() { + ssh -o ConnectTimeout=1 "$ssh_host" "$@" +} # check if we are able to reach the remarkable -if ! $ssh_cmd true; then +if ! ssh_cmd true; then echo "$ssh_host unreachable" exit 1 fi @@ -44,12 +48,11 @@ fallback_to_gzip() { sleep 2 } - # check if lz4 is present on remarkable -if $ssh_cmd "[ -f /opt/bin/lz4 ]"; then +if ssh_cmd "[ -f /opt/bin/lz4 ]"; then compress="/opt/bin/lz4" -elif $ssh_cmd "[ -f ~/lz4 ]"; then - compress="~/lz4" +elif ssh_cmd "[ -f ~/lz4 ]"; then + compress="\$HOME/lz4" fi # gracefully degrade to gzip if is not present on remarkable or host @@ -63,11 +66,8 @@ else decompress="lz4 -d" fi - - - # calculte how much bytes the window is -window_bytes="$(($width*$height*$bytes_per_pixel))" +window_bytes="$((width * height * bytes_per_pixel))" # rotate 90 degrees if landscape=true landscape_param="$($landscape && echo '-vf transpose=1')" @@ -80,12 +80,14 @@ read_loop="while $head_fb0; do $loop_wait; done | $compress" set -e # stop if an error occurs -$ssh_cmd "$read_loop" \ +# shellcheck disable=SC2086 +ssh_cmd "$read_loop" \ | $decompress \ - | ffplay -vcodec rawvideo \ - -loglevel "$loglevel" \ - -f rawvideo \ - -pixel_format gray16le \ - -video_size "$width,$height" \ - $landscape_param \ - -i - + | ffplay \ + -vcodec rawvideo \ + -loglevel "$loglevel" \ + -f rawvideo \ + -pixel_format gray16le \ + -video_size "$width,$height" \ + $landscape_param \ + -i - From 1dfb28028d496db8bdeba93f1fbdaae442813f14 Mon Sep 17 00:00:00 2001 From: Rien Maertens Date: Fri, 3 Apr 2020 12:16:16 +0200 Subject: [PATCH 2/3] Add GitHub workflow --- .github/workflows/check.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/check.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..cc49cab --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,27 @@ +name: Check + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + check: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: Shell Linter + run: docker run -v $GITHUB_WORKSPACE:/mnt -w /mnt koalaman/shellcheck reStream.sh + + - name: Shell Formatter + run: docker run -v $GITHUB_WORKSPACE:/mnt -w /mnt mvdan/shfmt -d reStream.sh From 52d0187d7ef473c09b5942dcdcd8bb8f533fc19c Mon Sep 17 00:00:00 2001 From: Rien Maertens Date: Mon, 6 Apr 2020 23:19:54 +0200 Subject: [PATCH 3/3] Don't use ~ in commands --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d28ab54..9fdd6d9 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,8 @@ and compiling `lz4` from source with the toolchain enabled, or you can use the statically linked binary I have already built and put in this repo. Copy the `lz4` program to your reMarkable with -`scp lz4.arm.static root@10.11.99.1:~/lz4`, make it executable with -`ssh root@10.11.99.1 'chmod +x ~/lz4'` and you're ready to go. +`scp lz4.arm.static root@10.11.99.1:/home/root/lz4`, make it executable with +`ssh root@10.11.99.1 'chmod +x /home/root/lz4'` and you're ready to go. ## Troubleshooting