adt_installer_internal 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. #!/bin/bash
  2. # Yocto ADT Installer
  3. #
  4. # Copyright 2010-2011 by Intel Corp.
  5. #
  6. # Permission is hereby granted, free of charge, to any person obtaining a copy
  7. # of this software and associated documentation files (the "Software"), to deal
  8. # in the Software without restriction, including without limitation the rights
  9. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. # copies of the Software, and to permit persons to whom the Software is
  11. # furnished to do so, subject to the following conditions:
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. parse_config()
  22. {
  23. INST_ARCH=`uname -m`
  24. case $INST_ARCH in
  25. i[3-6]86)
  26. OPKG_CONFIG_FILE=$YOCTOADT_OPKG_CONF_FILE_32
  27. OECORE_NATIVE_SYSROOT="$INSTALL_FOLDER/sysroots/$INST_ARCH$SDK_VENDOR-linux/"
  28. ;;
  29. x86_64)
  30. OPKG_CONFIG_FILE=$YOCTOADT_OPKG_CONF_FILE_64
  31. OECORE_NATIVE_SYSROOT="$INSTALL_FOLDER/sysroots/x86_64$SDK_VENDOR-linux/"
  32. ;;
  33. *)
  34. echo_info "[ADT_INST] Error: Installation Machine is not supported!"
  35. exit -1
  36. ;;
  37. esac
  38. }
  39. get_sudo_app()
  40. {
  41. username=$(id -nu)
  42. # find the owner of the parent
  43. dir=$1
  44. while [ 1 ]; do
  45. if [ -d $dir ]; then
  46. owner=$(stat -c %U $dir)
  47. break
  48. else
  49. dir=$(dirname $dir)
  50. fi
  51. done
  52. if [ "$owner" = "$username" ]; then
  53. true
  54. else
  55. echo sudo
  56. fi
  57. }
  58. # this function accepts arch_type (x86, x86_64, arm, ppc, mips) as the first
  59. # argument, returning the location of the target rootfs
  60. get_target_rootfs_location() {
  61. [ -z "$1" ] && return
  62. arch_type=$1
  63. # rootfs extraction directory
  64. target_sysroot_var="\$YOCTOADT_TARGET_SYSROOT_LOC_$arch_type"
  65. target_sysroot=`eval echo $target_sysroot_var`
  66. if [ "$target_sysroot" == "" ]; then
  67. return
  68. else
  69. echo "`readlink -m $target_sysroot`"
  70. fi
  71. }
  72. #let us install a qemu-native firstly
  73. #installation step 2
  74. install_native_sdk()
  75. {
  76. echo_info "\nStart installing selected native ADT for archs: $YOCTOADT_TARGETS..."
  77. # where the packages are installed.
  78. NATIVE_INSTALL_DIR=$INSTALL_FOLDER
  79. if [ -d "$INSTALL_FOLDER" ]; then
  80. echo_info "\nNative ADT installation directory \"$INSTALL_FOLDER\" already exists! Continue installation will override its contents!"
  81. confirm_install $1
  82. fi
  83. #Now begin to install native sdk and extract qemu rootfs which needs privilege rights
  84. #depending on the install location
  85. SUDO=$(get_sudo_app $NATIVE_INSTALL_DIR)
  86. if [ -n "$SUDO" ]; then
  87. echo_info "#######################################################################"
  88. echo_info "Please note from this point on installation requires sudo password ..."
  89. echo_info "#######################################################################"
  90. fi
  91. #we need to make this directory firstly since opkg need to use it.
  92. OPKG_LOCK_DIR="$NATIVE_INSTALL_DIR/$OPKG_LIBDIR/opkg"
  93. if [ ! -d "$OPKG_LOCK_DIR" ]; then
  94. $SUDO mkdir -p $OPKG_LOCK_DIR
  95. echo_info "Successfully create directory $OPKG_LOCK_DIR. "
  96. #if user delete /opt/xxx, while dangling folders there, report error
  97. elif [ ! -d "$INSTALL_FOLDER" ]; then
  98. echo_info "\nDangling opkg cache folder $OPKG_LOCK_DIR detected. Continue installation will remove the folder!"
  99. confirm_install $1
  100. $SUDO rm -rf $OPKG_LOCK_DIR
  101. $SUDO mkdir -p $OPKG_LOCK_DIR
  102. #if user are updating installing, just let him/her go, give her/him prompt
  103. else
  104. echo_info "ADT has already been installed. Will update its contents..."
  105. fi
  106. #first update repository
  107. if [ "x$SUDO" = "x" ]; then
  108. OPKG_CMD="$LOCAL_OPKG_LOC/bin/opkg"
  109. else
  110. OPKG_CMD="sudo -E $LOCAL_OPKG_LOC/bin/opkg"
  111. fi
  112. echo_info "Updating opkg..."
  113. $OPKG_CMD -f $OPKG_CONFIG_FILE -o $NATIVE_INSTALL_DIR update &>> $YOCTOADT_INSTALL_LOG_FILE
  114. check_result
  115. echo_info "opkg update process ended..."
  116. #install below must sdk-host packages
  117. OPKG_INSTALL_CMD="$OPKG_CMD "
  118. OPKG_INSTALL_NATIVE_CMD="$OPKG_INSTALL_CMD --force-overwrite -f $OPKG_CONFIG_FILE -o $NATIVE_INSTALL_DIR install"
  119. BASE_HOSTSDK_PKGNAMES="pseudo opkg pkgconfig libtool autoconf automake"
  120. for pkg in $BASE_HOSTSDK_PKGNAMES; do
  121. echo_info "Installing ${pkg} nativesdk ...\n"
  122. $OPKG_INSTALL_NATIVE_CMD nativesdk-${pkg} &>> $YOCTOADT_INSTALL_LOG_FILE
  123. check_result
  124. done
  125. for target_type in $YOCTOADT_TARGETS; do
  126. machine_var="\$YOCTOADT_TARGET_MACHINE_$target_type"
  127. machine=`eval echo $machine_var`
  128. echo_info "Installing cross canadian packages for $machine ..."
  129. $OPKG_INSTALL_NATIVE_CMD packagegroup-cross-canadian-$machine &>> $YOCTOADT_INSTALL_LOG_FILE
  130. check_result
  131. target_sysroot=`get_target_rootfs_location $target_type`
  132. [ -z "$target_sysroot" ] && continue
  133. # get the environment setup script paths: original (the one before relocation)
  134. # and relocated
  135. env_script_original=`$OPKG_CMD -f $OPKG_CONFIG_FILE -o $NATIVE_INSTALL_DIR files meta-environment-$machine|\
  136. grep environment-setup`
  137. env_script_relocated=$INSTALL_FOLDER/${env_script_original##*/}
  138. # opkg will not install packagegroup-cross-canadian package if it was already
  139. # installed. So, the environment script is in one place or the other.
  140. [ -e "$INSTALL_FOLDER/$env_script_original" ] && env_script=$INSTALL_FOLDER/$env_script_original
  141. [ -e "$env_script_original" ] && env_script=$env_script_original
  142. [ -e "$env_script_relocated" ] && env_script=$env_script_relocated
  143. $SUDO sed -i -e "s%SDKTARGETSYSROOT=.*%SDKTARGETSYSROOT=$target_sysroot%g" $env_script
  144. done
  145. if [ "$YOCTOADT_QEMU" == "Y" ] || [ "$YOCTOADT_QEMU" == "y" ]; then
  146. echo_info "\nInstalling qemu native ..."
  147. $OPKG_INSTALL_NATIVE_CMD nativesdk-qemu &>> $YOCTOADT_INSTALL_LOG_FILE
  148. check_result
  149. $OPKG_INSTALL_NATIVE_CMD nativesdk-qemu-helper &>> $YOCTOADT_INSTALL_LOG_FILE
  150. check_result
  151. fi
  152. if [ "$YOCTOADT_NFS_UTIL" == "Y" ] || [ "$YOCTOADT_NFS_UTIL" == "y" ]; then
  153. echo_info "\nInstalling unfs ..."
  154. $OPKG_INSTALL_NATIVE_CMD nativesdk-unfs3 &>> $YOCTOADT_INSTALL_LOG_FILE
  155. check_result
  156. fi
  157. # Lose the ./opt/${DISTRO}/${SDK_VERSION} part, we don't really need to keep
  158. # the entire directory structure. We could patch opkg to do that but it's far
  159. # simpler to do that here and achieve the same result.
  160. # This is done in two steps:
  161. if [ -d $NATIVE_INSTALL_DIR/$DEFAULT_INSTALL_FOLDER ]; then
  162. # Step 1: copy ./opt/${DISTRO}/${SDK_VERSION} contents to $NATIVE_INSTALL_DIR.
  163. # We cannot use move if $NATIVE_INSTALL_DIR is not empty (for example: contains
  164. # another SDK)
  165. $SUDO cp -r $NATIVE_INSTALL_DIR/$DEFAULT_INSTALL_FOLDER/* $NATIVE_INSTALL_DIR
  166. # delete the source directory now
  167. $SUDO rm -rf $NATIVE_INSTALL_DIR/$DEFAULT_INSTALL_FOLDER/*
  168. # Step 2: Delete the ./opt/${DISTRO}/${SDK_VERSION} directories too, they should be empty
  169. dir=$NATIVE_INSTALL_DIR/$DEFAULT_INSTALL_FOLDER
  170. while [ "$dir" != "$NATIVE_INSTALL_DIR" ]; do
  171. # if the user chose / as the install folder, then we should leave /opt in place
  172. if [ "$dir" = "/opt" ]; then
  173. break
  174. fi
  175. # try to delete the directory, only if it's empty
  176. $SUDO rmdir $dir
  177. if [ $? -ne 0 ]; then
  178. break
  179. fi
  180. # go to the next directory
  181. dir=$(dirname $dir)
  182. done
  183. # Step 3: Rewrite the *.list files to contain the correct paths
  184. $SUDO find $NATIVE_INSTALL_DIR/var/lib/opkg -type f -exec sed -i -e '#^$DEFAULT_INSTALL_FOLDER#$NATIVE_INSTALL_DIR#' {} \;
  185. fi
  186. # Link the ld.so.cache file into the hosts filesystem
  187. if [ ! -f "$OECORE_NATIVE_SYSROOT/etc/ld.so.cache" ]; then
  188. echo_info "Link the ld.so.cache file into the host filesystem"
  189. $SUDO ln -s /etc/ld.so.cache $OECORE_NATIVE_SYSROOT/etc/ld.so.cache
  190. check_result
  191. fi
  192. # relocate binaries
  193. echo_info "\nRelocating binaries ..."
  194. escaped_sdkpath=$(echo $DEFAULT_INSTALL_FOLDER |sed -e "s:[\+\.]:\\\\\\\\\0:g")
  195. # We don't change the script in-place since we may want the user to re-run
  196. # adt-installer script
  197. sed -e "s:##DEFAULT_INSTALL_DIR##:$escaped_sdkpath:" scripts/relocate_sdk.py > scripts/relocate_sdk_tmp.py
  198. chmod +x scripts/relocate_sdk_tmp.py
  199. dl_path=$(find $OECORE_NATIVE_SYSROOT/lib -name "ld-linux*")
  200. executable_files=$(find $OECORE_NATIVE_SYSROOT -type f -perm /111)
  201. $SUDO scripts/relocate_sdk_tmp.py $INSTALL_FOLDER $dl_path $executable_files
  202. check_result
  203. # replace /opt/${DISTRO}/${SDK_VERSION} with the install folder in all configs
  204. env_setup_script=$(find $NATIVE_INSTALL_DIR/ -name "environment-setup-*")
  205. $SUDO sed -i -e "s:$DEFAULT_INSTALL_FOLDER:$NATIVE_INSTALL_DIR:g" $env_setup_script
  206. find $OECORE_NATIVE_SYSROOT -type f -exec file '{}' \; | grep ":.*\(ASCII\|script\|source\).*text" | \
  207. cut -d':' -f1 | xargs $SUDO sed -i -e "s:$DEFAULT_INSTALL_FOLDER:$NATIVE_INSTALL_DIR:g"
  208. # change all symlinks pointing to /opt/${DISTRO}/${SDK_VERSION}
  209. for l in $(find $NATIVE_INSTALL_DIR -type l); do
  210. $SUDO ln -sfn $(readlink $l|sed -e "s:$DEFAULT_INSTALL_FOLDER:$NATIVE_INSTALL_DIR:") $l
  211. done
  212. # find out all perl scripts in $OECORE_NATIVE_SYSROOT and modify them
  213. # replacing the host perl with SDK perl.
  214. for perl_script in $($SUDO grep -m 1 "^#!.*perl" -rl $OECORE_NATIVE_SYSROOT); do
  215. $SUDO sed -i -e "s:^#! */usr/bin/perl.*:#! /usr/bin/env perl:g" -e \
  216. "s: /usr/bin/perl: /usr/bin/env perl:g" $perl_script
  217. done
  218. echo_info "\nSuccessfully installed selected native ADT!"
  219. }
  220. #Need three input params, $1 -- arch_type(arm powerpc x86 mips) #2 -- user installation type
  221. #customer or scilent
  222. install_target()
  223. {
  224. target_sysroot=`get_target_rootfs_location $1`
  225. [ -z "$target_sysroot" ] && return 0
  226. target_sysroot_image_var="\$YOCTOADT_TARGET_SYSROOT_IMAGE_$1"
  227. target_sysroot_image=`eval echo $target_sysroot_image_var`
  228. if [ "$target_sysroot_image" == "" ]; then
  229. echo_info "[ADT_INST] Error: YOCTOADT_TARGET_SYSROOT_IMAGE_$1 selection is empty, failed to create target sysroot!"
  230. return 1
  231. fi
  232. echo_info "Installing target sysroot for arch: $1, rootfs type: $target_sysroot_image, location: $target_sysroot"
  233. target_machine_var="\$YOCTOADT_TARGET_MACHINE_$1"
  234. target_machine=`eval echo $target_machine_var`
  235. sysroot_image_name="core-image-$target_sysroot_image-$target_machine.tar.bz2"
  236. #echo_info "Extracting rootfs: $sysroot_image_name, using pseudo..."
  237. # sudo password might be needed to install the target sysroot
  238. SUDO=$(get_sudo_app $target_sysroot)
  239. $SUDO scripts/extract_rootfs $sysroot_image_name $target_sysroot $OECORE_NATIVE_SYSROOT $user_inst_type
  240. check_result
  241. }
  242. #Main part
  243. . scripts/data_define
  244. . scripts/util
  245. parse_config
  246. #secondly we will start to install native tools
  247. user_inst_type=$1
  248. install_native_sdk $user_inst_type
  249. check_result
  250. for arch_type in $YOCTOADT_TARGETS; do
  251. install_target $arch_type
  252. check_result
  253. done