1
0

sysupgrade-tar.sh 1.4 KB

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