-
Notifications
You must be signed in to change notification settings - Fork 1
/
fwbuild.sh
executable file
·104 lines (84 loc) · 1.57 KB
/
fwbuild.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
COLORINFO=4
UPDATEFW=./updatefw
ROOTFS=squashfs-root
OUTDIR=build
# save old version
OLDVERSION=`cat squashfs-root/etc/bewan/release`
# version from last tag v*
# strip v and -0
VERSION=`git describe --long --tags --match 'v*' | sed -r 's/^v(.+)$/\1/;s/^(.*)-0-(.*)$/\1-\2/'`
# params check
SRCFW=$1
OUTFW=$2
if [ -z "$OUTFW" ] && [ ! -z "$VERSION" ]
then
OUTFW="$VERSION.bin"
fi
if [ -z "$SRCFW" ] || [ -z "$OUTFW" ]
then
echo "usage: $0 srcfw.bin [outfw.bin]"
exit 1
fi
# sanity check
if [ ! -f "$SRCFW" ]
then
echo "ERROR: $SRCFW doesn't exist"
exit 1
fi
if [ ! -d "$ROOTFS" ]
then
echo "ERROR: $ROOTFS is missing, extract it"
exit 1
fi
if [ ! -x "$UPDATEFW" ]
then
echo "ERROR: $UPDATEFW doesn't exist"
exit 1
fi
OUTFILE=$OUTDIR/$OUTFW
# already exist?
if [ -e "$OUTFILE" ]
then
echo "ERROR: $OUTFILE already exist"
exit 1
#echo "WARNING: removing $OUTFILE"
#rm -f $OUTFILE
fi
if [ ! -d "$OUTDIR" ]
then
mkdir -p $OUTDIR
fi
# update version
if [ ! -z "$VERSION" ]
then
echo "$VERSION" > squashfs-root/etc/bewan/release
fi
# build fs
FS=`dirname $OUTFILE`/`basename -s .bin $OUTFILE`.fs
./fsbuild.sh $FS
RET=$?
if [ $RET != 0 ]
then
echo "$OLDVERSION" > squashfs-root/etc/bewan/release
echo "ERROR: fs build failed"
exit 1
fi
# restore old version
echo "$OLDVERSION" > squashfs-root/etc/bewan/release
# build fw
echo "building $OUTFILE ..."
echo '------>>>'
tput setaf $COLORINFO
$UPDATEFW -u $SRCFW -s $FS -o $OUTFILE
RET=$?
tput sgr0
echo '<<<------'
if [ $RET != 0 ]
then
echo "ERROR: fw build failed"
exit 1
fi
#rm -f $FS
echo "$OUTFILE done."
exit 0