root/trunk/freewrt/scripts/ib.sh

Revision 2727, 4.7 kB (checked in by tg, 1 year ago)

“echo -e” is not portable, damnit!

Line 
1 #!/bin/sh
2 #-
3 # $FreeWRT$
4 #-
5 # This file is part of the FreeWRT project. FreeWRT is copyrighted
6 # material, please see the LICENCE file in the top-level directory
7 # or at http://www.freewrt.org/licence for details.
8
9 # Copyright (c) Waldemar Brodkorb <wbx@freewrt.org>
10 # image builder script (version 0.1)
11
12 # change here the base variables
13 basedir=/srv/apache2/downloads
14 toolsdir=/var/ib/bin
15 database=/srv/database/wib_dev.db
16 usetmpfs=0
17
18 # do not change anything below
19
20 usage() {
21         echo "Usage: `basename $0` -a <arch> -b <board> -k <kernelversion> -f <filesystem> -d <device> -o <outputfile> -p <packagelist>"
22         echo "          -a cpu architecture, f.e. mipsel"
23         echo "          -b board type, f.e. brcm"
24         echo "          -k kernel version, 2.4 or 2.6"
25         echo "          -f root filesystem type, f.e. jffs2"
26         echo "          -d specific device, f.e. asus-wl500g"
27         echo "          -p package list filename"
28         echo "          -o output file for the firmware image"
29         exit 1
30 }
31
32 # check for needed applications
33 tools="mksquashfs-lzma trx addpattern mkfs.jffs2 ipkg"
34
35 for t in ${tools}
36   do
37    [ -x ${toolsdir}/${t} ] || echo "${t} application missing or not executable"
38 done
39
40 # check for sqlite
41 sqlite=$(which sqlite)
42 [ -x ${sqlite} ] || "sqlite application is missing"
43
44 # simple sql functions
45 sql() {
46         sqlite $database "select $1 from $2"
47 }
48 sqlw() {
49         sqlite $database "select $1 from $2 where $3=\"$4\""
50 }
51
52 allowed_fs=$(sql name filesystems)
53 allowed_archs=$(sql name arches)
54 allowed_boards=$(sql name boards)
55 allowed_devices=$(sql name devices)
56 allowed_os_kernels=$(sql name os_kernels)
57
58 while getopts a:b:f:k:d:o:p: option
59 do
60   case $option in
61         a)
62                 archs=$OPTARG
63                 for a in $allowed_archs
64                 do
65                         if [ $archs = $a ]
66                         then
67                                 arch=$a
68                         fi
69                 done
70                 if [ -z $arch ]
71                   then
72                         echo "unsupported architecture: $archs"
73                         exit 1
74                 fi
75                 ;;
76         b)
77                 boards=$OPTARG
78                 for b in $allowed_boards
79                 do
80                         if [ $boards = $b ]
81                         then
82                                 board=$b
83                         fi
84                 done
85                 if [ -z $board ]
86                   then
87                         echo "unsupported board: $boards"
88                         exit 1
89                 fi
90                 ;;
91         f)
92                 filesystems=$OPTARG
93                 for f in $allowed_fs
94                   do
95                         if [ $filesystems = $f ]
96                         then
97                                 fs=$f
98                         fi
99                 done
100                 if [ -z $fs ]
101                   then
102                         echo "unsupported filesystem: $filesystems"
103                         exit 1
104                 fi
105                 ;;
106         k)
107                 kernels=$OPTARG
108                 for k in $allowed_os_kernels
109                   do
110                         if [ $kernels = $k ]
111                         then
112                                 kernel=$k
113                         fi
114                 done
115                 if [ -z $kernel ]
116                   then
117                         echo "unsupported kernel version: $kernels"
118                         exit 1
119                 fi
120                 ;;
121         d)
122                 devices=$OPTARG
123                 for d in $allowed_devices
124                   do
125                         if [ $devices = $d ]
126                         then
127                                 device=$d
128                         fi
129                 done
130                 if [ -z $device ]
131                   then
132                         echo "unsupported device: $devices"
133                         exit 1
134                 fi
135                 ;;
136         o)
137                 outputfile=$OPTARG
138                 if [ -z $outputfile ]
139                 then
140                         echo "You need to set an output file"
141                         exit 1
142                 fi
143                 ;;
144         p)
145                 packagelist=$OPTARG
146                 if [ -z $packagelist ]
147                 then
148                         echo "You need to set a package list file"
149                         exit 1
150                 fi
151                 ;;
152         *)
153                 echo "$0: unknown option: $option"
154                 usage
155                 exit 1
156                 ;;
157   esac
158 done
159
160 if [ -z $1 ]
161   then
162     usage
163     exit 1
164 fi
165
166 if [ $usetmpfs = 1 ]
167   then
168    tmpdir=$(mktemp -d /dev/shm/fwrt.XXXXXX)
169 else
170    tmpdir=$(mktemp -d)
171 fi
172 mkdir -p ${tmpdir}/tmp
173 mkdir -p ${tmpdir}/root
174 echo "creating temporary dir: ${tmpdir}"
175
176 printf '%s\n%s\n' "dest root /" "option offline_root ${tmpdir}/root" >${tmpdir}/ipkg.conf
177 ipkg_command="env IPKG_TMP=${tmpdir}/tmp IPKG_INSTROOT=${tmpdir}/root IPKG_CONF_DIR=${tmpdir} ${toolsdir}/ipkg -force-defaults -force-depends"
178
179 for p in $(grep -v '^#' $packagelist)
180   do
181         $ipkg_command install $(ls ${basedir}/${board}-${kernel}/packages/${p}_*)
182 done
183
184 erase_size=$(sqlw erase_size devices name ${device})
185
186 if [ $fs = "squashfs-symlinks" -o $fs = "squashfs-overlay" ]
187   then
188         align=1024
189 else
190         align=${erase_size}
191 fi
192
193 case $device in
194         asus-wl500g)
195                 device_opts="-p WL500g -v 1.9.6.0"
196                 image_command="${toolsdir}/trx ${device_opts} -o ${outputfile} -a ${align} ${tmpdir}/root.${fs}"
197                 ;;
198         asus-wl500g-deluxe)
199                 device_opts="-p WL500gx -v 1.9.6.0"
200                 image_command="${toolsdir}/trx ${device_opts} -o ${outputfile} -a ${align} ${tmpdir}/root.${fs}"
201                 ;;
202         asus-wl500g-premium)
203                 device_opts="-p WL500gp -v 1.9.7.0"
204                 image_command="${toolsdir}/trx ${device_opts} -o ${outputfile} -a ${align} ${tmpdir}/root.${fs}"
205                 ;;
206 esac
207
208 jffs_opts="--little-endian --pad --squash-uid"
209 squashfs_opts="-le -nopad -noappend -root-owned"
210
211 case $fs in
212         jffs2)
213                 fs_command="${toolsdir}/mkfs.jffs2 -e ${erase_size} -o ${tmpdir}/root.${fs} -d ${tmpdir}/root"
214                 ;;
215         squashfs-*)
216                 fs_command="${toolsdir}/mksquashfs-lzma ${tmpdir}/root ${tmpdir}/root.${fs} ${squashfs_opts}"
217                 ;;
218 esac
219
220 echo "create root filesystem image"
221 $fs_command || echo "creating the root filesystem image failed"
222
223 echo "create firmware image"
224 $image_command || echo "failed to create firmware image"
225
226 [ -n $tmpdir ] && rm -rf $tmpdir
227 echo "successfully build firmware image: ${outputfile}"
228
Note: See TracBrowser for help on using the browser.