2
0

sysupgrade-tar.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. board=""
  3. kernel=""
  4. rootfs=""
  5. outfile=""
  6. err=""
  7. while [ "$1" ]; do
  8. case "$1" in
  9. "--board")
  10. board="$2"
  11. shift
  12. shift
  13. continue
  14. ;;
  15. "--kernel")
  16. kernel="$2"
  17. shift
  18. shift
  19. continue
  20. ;;
  21. "--rootfs")
  22. rootfs="$2"
  23. shift
  24. shift
  25. continue
  26. ;;
  27. *)
  28. if [ ! "$outfile" ]; then
  29. outfile=$1
  30. shift
  31. continue
  32. fi
  33. ;;
  34. esac
  35. done
  36. if [ ! -n "$board" -o ! -r "$kernel" -a ! -r "$rootfs" -o ! "$outfile" ]; then
  37. echo "syntax: $0 [--board boardname] [--kernel kernelimage] [--rootfs rootfs] out"
  38. exit 1
  39. fi
  40. tmpdir="$( mktemp -d 2> /dev/null )"
  41. if [ -z "$tmpdir" ]; then
  42. # try OSX signature
  43. tmpdir="$( mktemp -t 'ubitmp' -d )"
  44. fi
  45. if [ -z "$tmpdir" ]; then
  46. exit 1
  47. fi
  48. mkdir -p "${tmpdir}/sysupgrade-${board}"
  49. echo "BOARD=${board}" > "${tmpdir}/sysupgrade-${board}/CONTROL"
  50. [ -z "${rootfs}" ] || cp "${rootfs}" "${tmpdir}/sysupgrade-${board}/root"
  51. [ -z "${kernel}" ] || cp "${kernel}" "${tmpdir}/sysupgrade-${board}/kernel"
  52. mtime=""
  53. if [ -n "$SOURCE_DATE_EPOCH" ]; then
  54. mtime="--mtime=@${SOURCE_DATE_EPOCH}"
  55. fi
  56. (cd "$tmpdir"; tar --sort=name --owner=0 --group=0 --numeric-owner -cvf sysupgrade.tar sysupgrade-${board} ${mtime})
  57. err="$?"
  58. if [ -e "$tmpdir/sysupgrade.tar" ]; then
  59. cp "$tmpdir/sysupgrade.tar" "$outfile"
  60. else
  61. err=2
  62. fi
  63. rm -rf "$tmpdir"
  64. exit $err