source: freewrt/scripts/ib.sh@ e840b97

Last change on this file since e840b97 was eab0bcd, checked in by Thorsten Glaser <tg@…>, 19 years ago

these shall not be executable nor use absolute pathnames,
since perl doesn't always live in /usr/bin (e.g. NetBSD®)

git-svn-id: svn://www.freewrt.org/trunk/freewrt@2585 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 4.7 KB
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
13basedir=/srv/apache2/downloads
14toolsdir=/var/ib/bin
15database=/srv/database/wib_dev.db
16usetmpfs=0
17
18# do not change anything below
19
20usage() {
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
33tools="mksquashfs-lzma trx addpattern mkfs.jffs2 ipkg"
34
35for t in ${tools}
36 do
37 [ -x ${toolsdir}/${t} ] || echo "${t} application missing or not executable"
38done
39
40# check for sqlite
41sqlite=$(which sqlite)
42[ -x ${sqlite} ] || "sqlite application is missing"
43
44# simple sql functions
45sql() {
46 sqlite $database "select $1 from $2"
47}
48sqlw() {
49 sqlite $database "select $1 from $2 where $3=\"$4\""
50}
51
52allowed_fs=$(sql name filesystems)
53allowed_archs=$(sql name arches)
54allowed_boards=$(sql name boards)
55allowed_devices=$(sql name devices)
56allowed_os_kernels=$(sql name os_kernels)
57
58while getopts a:b:f:k:d:o:p: option
59do
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
158done
159
160if [ -z $1 ]
161 then
162 usage
163 exit 1
164fi
165
166if [ $usetmpfs = 1 ]
167 then
168 tmpdir=$(mktemp -d /dev/shm/fwrt.XXXXXX)
169else
170 tmpdir=$(mktemp -d)
171fi
172mkdir -p ${tmpdir}/tmp
173mkdir -p ${tmpdir}/root
174echo "creating temporary dir: ${tmpdir}"
175
176echo -e "dest root /\noption offline_root ${tmpdir}/root" > ${tmpdir}/ipkg.conf
177ipkg_command="env IPKG_TMP=${tmpdir}/tmp IPKG_INSTROOT=${tmpdir}/root IPKG_CONF_DIR=${tmpdir} ${toolsdir}/ipkg -force-defaults -force-depends"
178
179for p in $(grep -v '^#' $packagelist)
180 do
181 $ipkg_command install $(ls ${basedir}/${board}-${kernel}/packages/${p}_*)
182done
183
184erase_size=$(sqlw erase_size devices name ${device})
185
186if [ $fs = "squashfs-symlinks" -o $fs = "squashfs-overlay" ]
187 then
188 align=1024
189else
190 align=${erase_size}
191fi
192
193case $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 ;;
206esac
207
208jffs_opts="--little-endian --pad --squash-uid"
209squashfs_opts="-le -nopad -noappend -root-owned"
210
211case $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 ;;
218esac
219
220echo "create root filesystem image"
221$fs_command || echo "creating the root filesystem image failed"
222
223echo "create firmware image"
224$image_command || echo "failed to create firmware image"
225
226[ -n $tmpdir ] && rm -rf $tmpdir
227echo "successfully build firmware image: ${outputfile}"
228
Note: See TracBrowser for help on using the repository browser.