update-nvflash | 46 ++++++++++++++++++++++------------------------ 1 files changed, 22 insertions(+), 24 deletions(-) diff --git a/update-nvflash b/update-nvflash index 843d62f..9bb0f4e 100755 --- a/update-nvflash +++ b/update-nvflash @@ -1,28 +1,27 @@ -#!/bin/bash +#!/bin/sh -efu # -mydir=${0%/*} -tmpdir=/var/tmp/nvflash.$$ +mydir=/usr/share/update-nvflash +tmpdir="$(mktemp -dt "update-nvflash.XXXXXXXXXX")" archive=tegra-linux.tar.gz source $mydir/files.conf -function nvflash_check () +nvflash_check () { test -e /usr/bin/nvflash || return 1 echo "$nvflash_sum /usr/bin/nvflash" | md5sum --quiet -c - || return 1 - test -e /usr/lib/nvflash/bootloader.bin || return 1 - echo "$bootloader_sum /usr/lib/nvflash/bootloader.bin" | md5sum --quiet -c - || return 1 + test -f /usr/lib/nvflash/fastboot.bin || return 1 + echo "$bootloader_sum /usr/lib/nvflash/fastboot.bin" | md5sum --quiet -c - || return 1 return 0 } -function nvflash_download () +nvflash_download () { - mkdir -p $tmpdir if [[ $archive_url == file:* ]]; then cp ${archive_url#file:} $tmpdir/$archive else @@ -32,7 +31,7 @@ function nvflash_download () } -function nvflash_run_extract () +nvflash_run_extract () { tar xf $tmpdir/$archive -C $tmpdir echo "$nvflash_sum $tmpdir/ldk/bootloader/nvflash" | md5sum --quiet -c - || exit 1 @@ -40,30 +39,31 @@ function nvflash_run_extract () } -function nvflash_install () +nvflash_install () { - install -p $tmpdir/ldk/bootloader/nvflash /usr/bin/ - install -p $tmpdir/ldk/bootloader/harmony/fastboot.bin /usr/lib/nvflash/ + install -m0755 -D $tmpdir/ldk/bootloader/nvflash /usr/bin/nvflash + install -m0644 -D $tmpdir/ldk/bootloader/harmony/fastboot.bin /usr/lib/nvflash/fastboot.bin } -function nvflash_clean () +nvflash_clean () { - rm -rf $tmpdir + rm -rf "$tmpdir" } +trap nvflash_clean EXIT +trap nvflash_clean HUP PIPE INT QUIT TERM -function nvflash_remove () +nvflash_remove () { - rm -f /usr/bin/nvflash - rm -f /usr/lib/nvflash/bootloader.bin + rm /usr/bin/nvflash || : + rm /usr/lib/nvflash/fastboot.bin || : } -function nvflash_update () +nvflash_update () { - nvflash_check - test $? = 0 && return + nvflash_check && return nvflash_download nvflash_run_extract @@ -72,8 +72,7 @@ function nvflash_update () } - -case "$1" in +case "${1:---help}" in --install) nvflash_update ;; @@ -81,8 +80,7 @@ case "$1" in nvflash_remove ;; --check) - nvflash_check - if [ $? = 0 ]; then + if nvflash_check; then echo "nvflash: installed - ok" else echo "nvflash: need to be installed or updated"