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