create-lsb-image 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. red='\E[31;40m'
  18. green='\E[32;40m'
  19. #Get current owner
  20. OWNER=`whoami`
  21. #Get group
  22. GROUP=`id -gn ${USER}`
  23. MACHINE_ARCH=`bitbake -e | sed -n 's/^MACHINE_ARCH=\"\(.*\)\"/\1/p'`
  24. DEPLOY_DIR_IMAGE=`bitbake -e | sed -n 's/^DEPLOY_DIR_IMAGE=\"\(.*\)\"/\1/p'`
  25. #Get value of varibale MACHINE_INE and DEPLOY_DIR_IMAGE
  26. LSB_IMAGE=poky-image-lsb-${MACHINE_ARCH}-test.ext3
  27. ECHO()
  28. {
  29. echo -e "${green}$@"
  30. tput sgr0
  31. }
  32. ERROR()
  33. {
  34. echo -e "${red}$@"
  35. tput sgr0
  36. exit 1
  37. }
  38. exit_check()
  39. {
  40. [ $? -ne 0 ] && exit $?
  41. }
  42. usage()
  43. {
  44. ECHO "Usage: PC\$ create-lsb-image ARCH ROOTFS_IMAGE"
  45. ECHO " ARCH: x86 or x86-64 or ppc32"
  46. ECHO " ROOTFS_IMAGE: \
  47. Name of the rootfs image with suffix \"tar.bz2\""
  48. ECHO ""
  49. ECHO "Examples:"
  50. ECHO " PC\$ creat-lsb-image \
  51. x86 poky-image-lsb-qemux86-20110317030443.rootfs.tar.bz2"
  52. exit 1
  53. }
  54. #There should be two parameters to get machine type and name of image
  55. if [ $# -ne 2 ]; then
  56. usage
  57. fi
  58. #Get list for lsb test suite
  59. case ${1} in
  60. "x86")
  61. T_ARCH=ia32
  62. P_ARCH=i486
  63. COM_PACKAGE_LIST="lsb-dist-testkit-4.1.0-5.${T_ARCH}.tar.gz"
  64. ;;
  65. "x86-64")
  66. T_ARCH=amd64
  67. P_ARCH=x86_64
  68. MACHINE_ARCH=${MACHINE_ARCH/x86_64/x86-64}
  69. COM_PACKAGE_LIST="lsb-dist-testkit-4.1.0-5.${P_ARCH}.tar.gz"
  70. ;;
  71. "ppc32")
  72. P_ARCH=ppc
  73. T_ARCH=${1}
  74. COM_PACKAGE_LIST="lsb-dist-testkit-4.1.0-5.${T_ARCH}.tar.gz"
  75. ;;
  76. *)
  77. usage
  78. ;;
  79. esac
  80. APP_PACKAGE_RPMLIST="lsb-apache-2.2.14-3.lsb4.${P_ARCH}.rpm \
  81. lsb-tcl-8.5.7-6.lsb4.${P_ARCH}.rpm \
  82. lsb-expect-5.43.0-11.lsb4.${P_ARCH}.rpm \
  83. lsb-groff-1.20.1-5.lsb4.${P_ARCH}.rpm \
  84. lsb-raptor-1.4.19-3.lsb4.${P_ARCH}.rpm \
  85. lsb-xpdf-1.01-10.lsb4.${P_ARCH}.rpm \
  86. lsb-samba-3.4.3-5.lsb4.${P_ARCH}.rpm \
  87. lsb-rsync-3.0.6-3.lsb4.${P_ARCH}.rpm"
  88. APP_PACKAGE_SOURCELIST="expect-tests.tar \
  89. tcl-tests.tar \
  90. raptor-tests.tar \
  91. test1.pdf \
  92. test2.pdf"
  93. PACKAGE_LIST="${COM_PACKAGE_LIST} \
  94. ${APP_PACKAGE_RPMLIST} \
  95. ${APP_PACKAGE_SOURCELIST}"
  96. #Version for lsb test suite
  97. RELEASE=released-4.1.0
  98. #Tools of download packages
  99. WGET="wget -c -t 5"
  100. SERVER1="\
  101. http://ftp.linuxfoundation.org/pub/lsb/bundles/${RELEASE}/dist-testkit"
  102. SERVER2="\
  103. http://ftp.linux-foundation.org/pub/lsb/app-battery/${RELEASE}/${T_ARCH}"
  104. SERVER3="http://ftp.linuxfoundation.org/pub/lsb/snapshots/appbat/tests"
  105. #Function for downloading package from URL pointed
  106. download()
  107. {
  108. for i in $@; do
  109. ECHO " -->Downloading package \"${i}\""
  110. PACKAGE_NAME=${i}
  111. suffix=${PACKAGE_NAME##*.}
  112. if [ "$suffix" = "gz" ];then
  113. ${WGET} ${SERVER1}/${i}
  114. elif [ "$suffix" = "rpm" ];then
  115. ${WGET} ${SERVER2}/${i}
  116. else
  117. ${WGET} ${SERVER3}/${i}
  118. fi
  119. done
  120. }
  121. #Check lsb image
  122. [ ! -d $DEPLOY_DIR_IMAGE ] && ERROR "\
  123. Image directory does not exist: ${DEPLOY_DIR_IMAGE}"
  124. ECHO "Entering directory $DEPLOY_DIR_IMAGE"
  125. cd $DEPLOY_DIR_IMAGE
  126. if [ ! -f ${2} ]; then
  127. ECHO "rootfs image \"${2}\" not found in ${DEPLOY_DIR_IMAGE}"
  128. ECHO "Please copy \"${2}\" to \"${DEPLOY_DIR_IMAGE}\""
  129. exit 1
  130. fi
  131. #Umount lsbtmp
  132. [ ! -d lsbtmp ] && mkdir lsbtmp
  133. #Download lsb test suite
  134. mkdir -p lsb-test-suite-${MACHINE_ARCH} || \
  135. ERROR "Couldn't find lsb test suite for ${MACHINE_ARCH}"
  136. cd lsb-test-suite-${MACHINE_ARCH}
  137. ECHO "Downloading lsb test suite, it would take some time..."
  138. download ${PACKAGE_LIST}
  139. cd ..
  140. #Creat lsb image
  141. if [ -f ${LSB_IMAGE} ];then
  142. sudo umount lsbtmp > /dev/null 2>&1
  143. ECHO "Removing old lsb image..."
  144. /bin/rm ${LSB_IMAGE} > /dev/null 2>&1
  145. fi
  146. ECHO "Creating a 8GB file for the lsb image"
  147. dd if=/dev/zero of=${LSB_IMAGE} bs=1M count=8000 > /dev/null 2>&1
  148. exit_check
  149. ECHO "Formatting ext3 image..."
  150. mkfs.ext3 -q -F ${LSB_IMAGE} > /dev/null 2>&1
  151. tune2fs -j ${LSB_IMAGE} > /dev/null 2>&1
  152. ECHO "Generating final image"
  153. [ ! -d lsbtmp ] && mkdir lsbtmp
  154. #Install file system and lsb test suite to lsb image
  155. sudo mount -o loop ${LSB_IMAGE} lsbtmp
  156. exit_check
  157. ECHO " ->Installing rootfs..."
  158. sudo tar jpxf ${2} -C lsbtmp
  159. exit_check
  160. ECHO " ->Installing lsb test suite..."
  161. cd lsb-test-suite-${MACHINE_ARCH}
  162. if [ "${1}" = "x86-64" ]; then
  163. sudo tar zpxf lsb-dist-testkit-4.1.0-5.${P_ARCH}.tar.gz -C ../lsbtmp
  164. else
  165. sudo tar zpxf lsb-dist-testkit-4.1.0-5.${T_ARCH}.tar.gz -C ../lsbtmp
  166. fi
  167. exit_check
  168. sudo mkdir ../lsbtmp/lsb-Application
  169. sudo cp *.rpm *.tar *.pdf ../lsbtmp/lsb-Application
  170. exit_check
  171. cd ..
  172. if [ -f modules-*-${MACHINE_ARCH}.tgz ];then
  173. ECHO " ->Installing moudles of driver..."
  174. sudo tar zpxf modules-*-${MACHINE_ARCH}.tgz -C lsbtmp/
  175. fi
  176. #Unmount lsbtmp
  177. sudo umount lsbtmp
  178. exit_check
  179. sudo rm -rf lsbtmp
  180. #Change file attribute
  181. sudo chown ${OWNER}:${GROUP} ${LSB_IMAGE}
  182. exit_check
  183. sudo chmod 755 ${LSB_IMAGE}
  184. exit_check
  185. #Set up link
  186. ln -sf ${LSB_IMAGE} poky-image-lsb-${MACHINE_ARCH}.ext3
  187. ECHO "The LSB test environment has been setup successfully."
  188. ECHO "Please run this image on platform ${MACHINE_ARCH}"