diff options
author | Xiaofeng Yan <xiaofeng.yan@windriver.com> | 2011-04-22 15:27:30 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-04-24 22:50:44 +0100 |
commit | 40f226e6d448cafaf97887437a92c9bff8e70fcf (patch) | |
tree | e7dee4de11bfafc9a7b9e91b7732413877f04602 /scripts/create-lsb-image | |
parent | 91556f80461897914698ad96020b1441391df9ec (diff) | |
download | poky-40f226e6d448cafaf97887437a92c9bff8e70fcf.tar.gz |
create-lsb-image:Rename creat-lsb-image and fix some bugs
Rename creat-lsb-image to create-lsb-image
Fix some fuctions for more practical
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/create-lsb-image')
-rwxr-xr-x | scripts/create-lsb-image | 228 |
1 files changed, 228 insertions, 0 deletions
diff --git a/scripts/create-lsb-image b/scripts/create-lsb-image new file mode 100755 index 0000000000..94cb337678 --- /dev/null +++ b/scripts/create-lsb-image | |||
@@ -0,0 +1,228 @@ | |||
1 | #!/bin/bash | ||
2 | # | ||
3 | # Copyright (C) 2010-2011 Wind River Systems, Inc. | ||
4 | # | ||
5 | # This program is free software; you can redistribute it and/or modify | ||
6 | # it under the terms of the GNU General Public License version 2 as | ||
7 | # published by the Free Software Foundation. | ||
8 | # | ||
9 | # This program is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
12 | # See the GNU General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU General Public License | ||
15 | # along with this program; if not, write to the Free Software | ||
16 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
17 | |||
18 | |||
19 | red='\E[31;40m' | ||
20 | green='\E[32;40m' | ||
21 | |||
22 | #Get current owner | ||
23 | OWNER=`whoami` | ||
24 | #Get group | ||
25 | GROUP=`id -gn ${USER}` | ||
26 | MACHINE_ARCH=`bitbake -e | sed -n 's/^MACHINE_ARCH=\"\(.*\)\"/\1/p'` | ||
27 | DEPLOY_DIR_IMAGE=`bitbake -e | sed -n 's/^DEPLOY_DIR_IMAGE=\"\(.*\)\"/\1/p'` | ||
28 | #Get value of varibale MACHINE_INE and DEPLOY_DIR_IMAGE | ||
29 | LSB_IMAGE=poky-image-lsb-${MACHINE_ARCH}-test.ext3 | ||
30 | |||
31 | ECHO() | ||
32 | { | ||
33 | echo -e "${green}$@" | ||
34 | tput sgr0 | ||
35 | } | ||
36 | |||
37 | ERROR() | ||
38 | { | ||
39 | echo -e "${red}$@" | ||
40 | tput sgr0 | ||
41 | exit 1 | ||
42 | } | ||
43 | |||
44 | exit_check() | ||
45 | { | ||
46 | [ $? -ne 0 ] && exit $? | ||
47 | } | ||
48 | |||
49 | usage() | ||
50 | { | ||
51 | ECHO "Usage: PC\$ create-lsb-image ARCH ROOTFS_IMAGE" | ||
52 | ECHO " ARCH: x86 or x86-64 or ppc32" | ||
53 | ECHO " ROOTFS_IMAGE: \ | ||
54 | Name of the rootfs image with suffix \"tar.bz2\"" | ||
55 | |||
56 | |||
57 | ECHO "" | ||
58 | ECHO "Examples:" | ||
59 | ECHO " PC\$ creat-lsb-image \ | ||
60 | x86 poky-image-lsb-qemux86-20110317030443.rootfs.tar.bz2" | ||
61 | exit 1 | ||
62 | } | ||
63 | |||
64 | #There should be two parameters to get machine type and name of image | ||
65 | if [ $# -ne 2 ]; then | ||
66 | usage | ||
67 | fi | ||
68 | |||
69 | #Get list for lsb test suite | ||
70 | case ${1} in | ||
71 | "x86") | ||
72 | T_ARCH=ia32 | ||
73 | P_ARCH=i486 | ||
74 | COM_PACKAGE_LIST="lsb-dist-testkit-4.1.0-5.${T_ARCH}.tar.gz" | ||
75 | ;; | ||
76 | "x86-64") | ||
77 | T_ARCH=amd64 | ||
78 | P_ARCH=x86_64 | ||
79 | MACHINE_ARCH=${MACHINE_ARCH/x86_64/x86-64} | ||
80 | COM_PACKAGE_LIST="lsb-dist-testkit-4.1.0-5.${P_ARCH}.tar.gz" | ||
81 | ;; | ||
82 | "ppc32") | ||
83 | P_ARCH=ppc | ||
84 | T_ARCH=${ARCH} | ||
85 | COM_PACKAGE_LIST="lsb-dist-testkit-4.1.0-5.${T_ARCH}.tar.gz" | ||
86 | ;; | ||
87 | *) | ||
88 | usage | ||
89 | ;; | ||
90 | esac | ||
91 | |||
92 | APP_PACKAGE_RPMLIST="lsb-apache-2.2.14-3.lsb4.${P_ARCH}.rpm \ | ||
93 | lsb-tcl-8.5.7-6.lsb4.${P_ARCH}.rpm \ | ||
94 | lsb-expect-5.43.0-11.lsb4.${P_ARCH}.rpm \ | ||
95 | lsb-groff-1.20.1-5.lsb4.${P_ARCH}.rpm \ | ||
96 | lsb-raptor-1.4.19-3.lsb4.${P_ARCH}.rpm \ | ||
97 | lsb-xpdf-1.01-10.lsb4.${P_ARCH}.rpm \ | ||
98 | lsb-samba-3.4.3-5.lsb4.${P_ARCH}.rpm \ | ||
99 | lsb-rsync-3.0.6-3.lsb4.${P_ARCH}.rpm" | ||
100 | |||
101 | APP_PACKAGE_SOURCELIST="expect-tests.tar \ | ||
102 | tcl-tests.tar \ | ||
103 | raptor-tests.tar \ | ||
104 | test1.pdf \ | ||
105 | test2.pdf" | ||
106 | |||
107 | PACKAGE_LIST="${COM_PACKAGE_LIST} \ | ||
108 | ${APP_PACKAGE_RPMLIST} \ | ||
109 | ${APP_PACKAGE_SOURCELIST}" | ||
110 | |||
111 | #Version for lsb test suite | ||
112 | RELEASE=released-4.1.0 | ||
113 | #Tools of download packages | ||
114 | WGET="wget -c -t 5" | ||
115 | SERVER1="\ | ||
116 | http://ftp.linuxfoundation.org/pub/lsb/bundles/${RELEASE}/dist-testkit" | ||
117 | SERVER2="\ | ||
118 | http://ftp.linux-foundation.org/pub/lsb/app-battery/${RELEASE}/${T_ARCH}" | ||
119 | SERVER3="http://ftp.linuxfoundation.org/pub/lsb/snapshots/appbat/tests" | ||
120 | |||
121 | |||
122 | #Function for downloading package from URL pointed | ||
123 | download() | ||
124 | { | ||
125 | |||
126 | for i in $@; do | ||
127 | ECHO " -->Downloading package \"${i}\"" | ||
128 | PACKAGE_NAME=${i} | ||
129 | suffix=${PACKAGE_NAME##*.} | ||
130 | if [ "$suffix" = "gz" ];then | ||
131 | ${WGET} ${SERVER1}/${i} | ||
132 | elif [ "$suffix" = "rpm" ];then | ||
133 | ${WGET} ${SERVER2}/${i} | ||
134 | else | ||
135 | ${WGET} ${SERVER3}/${i} | ||
136 | fi | ||
137 | done | ||
138 | } | ||
139 | |||
140 | #Check lsb image | ||
141 | [ ! -d $DEPLOY_DIR_IMAGE ] && ERROR "\ | ||
142 | Image directory does not exist: ${DEPLOY_DIR_IMAGE}" | ||
143 | |||
144 | ECHO "Entering directory $DEPLOY_DIR_IMAGE" | ||
145 | cd $DEPLOY_DIR_IMAGE | ||
146 | |||
147 | if [ ! -f ${2} ]; then | ||
148 | ECHO "rootfs image \"${2}\" not found in ${DEPLOY_DIR_IMAGE}" | ||
149 | ECHO "Please copy \"${2}\" to \"${DEPLOY_DIR_IMAGE}\"" | ||
150 | exit 1 | ||
151 | fi | ||
152 | |||
153 | #Umount lsbtmp | ||
154 | [ ! -d lsbtmp ] && mkdir lsbtmp | ||
155 | |||
156 | #Download lsb test suite | ||
157 | mkdir -p lsb-test-suite-${MACHINE_ARCH} || \ | ||
158 | ERROR "Couldn't find lsb test suite for ${MACHINE_ARCH}" | ||
159 | cd lsb-test-suite-${MACHINE_ARCH} | ||
160 | ECHO "Downloading lsb test suite, it would take some time..." | ||
161 | download ${PACKAGE_LIST} | ||
162 | |||
163 | cd .. | ||
164 | |||
165 | #Creat lsb image | ||
166 | if [ -f ${LSB_IMAGE} ];then | ||
167 | sudo umount lsbtmp > /dev/null 2>&1 | ||
168 | ECHO "Removing old lsb image..." | ||
169 | /bin/rm ${LSB_IMAGE} > /dev/null 2>&1 | ||
170 | fi | ||
171 | |||
172 | ECHO "Creating a 8GB file for the lsb image" | ||
173 | dd if=/dev/zero of=${LSB_IMAGE} bs=1M count=8000 > /dev/null 2>&1 | ||
174 | exit_check | ||
175 | |||
176 | ECHO "Formatting ext3 image..." | ||
177 | mkfs.ext3 -q -F ${LSB_IMAGE} > /dev/null 2>&1 | ||
178 | tune2fs -j ${LSB_IMAGE} > /dev/null 2>&1 | ||
179 | |||
180 | |||
181 | ECHO "Generating final image" | ||
182 | [ ! -d lsbtmp ] && mkdir lsbtmp | ||
183 | |||
184 | |||
185 | #Install file system and lsb test suite to lsb image | ||
186 | sudo mount -o loop ${LSB_IMAGE} lsbtmp | ||
187 | exit_check | ||
188 | |||
189 | ECHO " ->Installing rootfs..." | ||
190 | sudo tar jpxf ${2} -C lsbtmp | ||
191 | exit_check | ||
192 | |||
193 | ECHO " ->Installing lsb test suite..." | ||
194 | cd lsb-test-suite-${MACHINE_ARCH} | ||
195 | if [ "${1}" = "x86-64" ]; then | ||
196 | sudo tar zpxf lsb-dist-testkit-4.1.0-5.${P_ARCH}.tar.gz -C ../lsbtmp | ||
197 | else | ||
198 | sudo tar zpxf lsb-dist-testkit-4.1.0-5.${T_ARCH}.tar.gz -C ../lsbtmp | ||
199 | fi | ||
200 | exit_check | ||
201 | |||
202 | sudo mkdir ../lsbtmp/lsb-Application | ||
203 | sudo cp *.rpm *.tar *.pdf ../lsbtmp/lsb-Application | ||
204 | exit_check | ||
205 | cd .. | ||
206 | |||
207 | if [ -f modules-*-${MACHINE_ARCH}.tgz ];then | ||
208 | ECHO " ->Installing moudles of driver..." | ||
209 | sudo tar zpxf modules-*-${MACHINE_ARCH}.tgz -C lsbtmp/ | ||
210 | fi | ||
211 | |||
212 | |||
213 | #Unmount lsbtmp | ||
214 | sudo umount lsbtmp | ||
215 | exit_check | ||
216 | sudo rm -rf lsbtmp | ||
217 | |||
218 | #Change file attribute | ||
219 | sudo chown ${OWNER}:${GROUP} ${LSB_IMAGE} | ||
220 | exit_check | ||
221 | sudo chmod 755 ${LSB_IMAGE} | ||
222 | exit_check | ||
223 | |||
224 | #Set up link | ||
225 | ln -sf ${LSB_IMAGE} poky-image-lsb-${MACHINE_ARCH}.ext3 | ||
226 | |||
227 | ECHO "The LSB test environment has been setup successfully." | ||
228 | ECHO "Please run this image on platform ${MACHINE_ARCH}" | ||