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