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