Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1 | #!/bin/sh |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | |
| 3 | INST_ARCH=$(uname -m | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/") |
| 4 | SDK_ARCH=$(echo @SDK_ARCH@ | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/") |
| 5 | |
| 6 | verlte () { |
| 7 | [ "$1" = "`printf "$1\n$2" | sort -V | head -n1`" ] |
| 8 | } |
| 9 | |
| 10 | verlt() { |
| 11 | [ "$1" = "$2" ] && return 1 || verlte $1 $2 |
| 12 | } |
| 13 | |
| 14 | verlt `uname -r` @OLDEST_KERNEL@ |
| 15 | if [ $? = 0 ]; then |
| 16 | echo "Error: The SDK needs a kernel > @OLDEST_KERNEL@" |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | if [ "$INST_ARCH" != "$SDK_ARCH" ]; then |
| 21 | # Allow for installation of ix86 SDK on x86_64 host |
| 22 | if [ "$INST_ARCH" != x86_64 -o "$SDK_ARCH" != ix86 ]; then |
| 23 | echo "Error: Installation machine not supported!" |
| 24 | exit 1 |
| 25 | fi |
| 26 | fi |
| 27 | |
| 28 | DEFAULT_INSTALL_DIR="@SDKPATH@" |
| 29 | SUDO_EXEC="" |
| 30 | target_sdk_dir="" |
| 31 | answer="" |
| 32 | relocate=1 |
| 33 | savescripts=0 |
| 34 | verbose=0 |
| 35 | while getopts ":yd:nDRS" OPT; do |
| 36 | case $OPT in |
| 37 | y) |
| 38 | answer="Y" |
| 39 | ;; |
| 40 | d) |
| 41 | target_sdk_dir=$OPTARG |
| 42 | ;; |
| 43 | n) |
| 44 | prepare_buildsystem="no" |
| 45 | ;; |
| 46 | D) |
| 47 | verbose=1 |
| 48 | ;; |
| 49 | R) |
| 50 | relocate=0 |
| 51 | savescripts=1 |
| 52 | ;; |
| 53 | S) |
| 54 | savescripts=1 |
| 55 | ;; |
| 56 | *) |
| 57 | echo "Usage: $(basename $0) [-y] [-d <dir>]" |
| 58 | echo " -y Automatic yes to all prompts" |
| 59 | echo " -d <dir> Install the SDK to <dir>" |
| 60 | echo "======== Extensible SDK only options ============" |
| 61 | echo " -n Do not prepare the build system" |
| 62 | echo "======== Advanced DEBUGGING ONLY OPTIONS ========" |
| 63 | echo " -S Save relocation scripts" |
| 64 | echo " -R Do not relocate executables" |
| 65 | echo " -D use set -x to see what is going on" |
| 66 | exit 1 |
| 67 | ;; |
| 68 | esac |
| 69 | done |
| 70 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 71 | titlestr="@SDK_TITLE@ installer version @SDK_VERSION@" |
| 72 | printf "%s\n" "$titlestr" |
| 73 | printf "%${#titlestr}s\n" | tr " " "=" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 74 | |
| 75 | if [ $verbose = 1 ] ; then |
| 76 | set -x |
| 77 | fi |
| 78 | |
| 79 | @SDK_PRE_INSTALL_COMMAND@ |
| 80 | |
| 81 | # SDK_EXTENSIBLE is exposed from the SDK_PRE_INSTALL_COMMAND above |
| 82 | if [ "$SDK_EXTENSIBLE" = "1" ]; then |
| 83 | DEFAULT_INSTALL_DIR="@SDKEXTPATH@" |
| 84 | fi |
| 85 | |
| 86 | if [ "$target_sdk_dir" = "" ]; then |
| 87 | if [ "$answer" = "Y" ]; then |
| 88 | target_sdk_dir="$DEFAULT_INSTALL_DIR" |
| 89 | else |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 90 | read -p "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " target_sdk_dir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 91 | [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR |
| 92 | fi |
| 93 | fi |
| 94 | |
| 95 | eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g') |
| 96 | if [ -d "$target_sdk_dir" ]; then |
| 97 | target_sdk_dir=$(cd "$target_sdk_dir"; pwd) |
| 98 | else |
| 99 | target_sdk_dir=$(readlink -m "$target_sdk_dir") |
| 100 | fi |
| 101 | |
| 102 | if [ "$SDK_EXTENSIBLE" = "1" ]; then |
| 103 | # We're going to be running the build system, additional restrictions apply |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 104 | if echo "$target_sdk_dir" | grep -q '[+\ @$]'; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 105 | echo "The target directory path ($target_sdk_dir) contains illegal" \ |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 106 | "characters such as spaces, @, \$ or +. Abort!" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 107 | exit 1 |
| 108 | fi |
| 109 | else |
| 110 | if [ -n "$(echo $target_sdk_dir|grep ' ')" ]; then |
| 111 | echo "The target directory path ($target_sdk_dir) contains spaces. Abort!" |
| 112 | exit 1 |
| 113 | fi |
| 114 | fi |
| 115 | |
| 116 | if [ -e "$target_sdk_dir/environment-setup-@REAL_MULTIMACH_TARGET_SYS@" ]; then |
| 117 | echo "The directory \"$target_sdk_dir\" already contains a SDK for this architecture." |
| 118 | printf "If you continue, existing files will be overwritten! Proceed[y/N]? " |
| 119 | |
| 120 | default_answer="n" |
| 121 | else |
| 122 | printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed[Y/n]? " |
| 123 | |
| 124 | default_answer="y" |
| 125 | fi |
| 126 | |
| 127 | if [ "$answer" = "" ]; then |
| 128 | read answer |
| 129 | [ "$answer" = "" ] && answer="$default_answer" |
| 130 | else |
| 131 | echo $answer |
| 132 | fi |
| 133 | |
| 134 | if [ "$answer" != "Y" -a "$answer" != "y" ]; then |
| 135 | echo "Installation aborted!" |
| 136 | exit 1 |
| 137 | fi |
| 138 | |
| 139 | # Try to create the directory (this will not succeed if user doesn't have rights) |
| 140 | mkdir -p $target_sdk_dir >/dev/null 2>&1 |
| 141 | |
| 142 | # if don't have the right to access dir, gain by sudo |
| 143 | if [ ! -x $target_sdk_dir -o ! -w $target_sdk_dir -o ! -r $target_sdk_dir ]; then |
| 144 | if [ "$SDK_EXTENSIBLE" = "1" ]; then |
| 145 | echo "Unable to access \"$target_sdk_dir\", will not attempt to use" \ |
| 146 | "sudo as as extensible SDK cannot be used as root." |
| 147 | exit 1 |
| 148 | fi |
| 149 | |
| 150 | SUDO_EXEC=$(which "sudo") |
| 151 | if [ -z $SUDO_EXEC ]; then |
| 152 | echo "No command 'sudo' found, please install sudo first. Abort!" |
| 153 | exit 1 |
| 154 | fi |
| 155 | |
| 156 | # test sudo could gain root right |
| 157 | $SUDO_EXEC pwd >/dev/null 2>&1 |
| 158 | [ $? -ne 0 ] && echo "Sorry, you are not allowed to execute as root." && exit 1 |
| 159 | |
| 160 | # now that we have sudo rights, create the directory |
| 161 | $SUDO_EXEC mkdir -p $target_sdk_dir >/dev/null 2>&1 |
| 162 | fi |
| 163 | |
| 164 | payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1)) |
| 165 | |
| 166 | printf "Extracting SDK..." |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 167 | tail -n +$payload_offset $0| $SUDO_EXEC tar xj -C $target_sdk_dir --checkpoint=.2500 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 168 | echo "done" |
| 169 | |
| 170 | printf "Setting it up..." |
| 171 | # fix environment paths |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 172 | real_env_setup_script="" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 173 | for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 174 | if grep -q 'OECORE_NATIVE_SYSROOT=' $env_setup_script; then |
| 175 | # Handle custom env setup scripts that are only named |
| 176 | # environment-setup-* so that they have relocation |
| 177 | # applied - what we want beyond here is the main one |
| 178 | # rather than the one that simply sorts last |
| 179 | real_env_setup_script="$env_setup_script" |
| 180 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 181 | $SUDO_EXEC sed -e "s:@SDKPATH@:$target_sdk_dir:g" -i $env_setup_script |
| 182 | done |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 183 | if [ -n "$real_env_setup_script" ] ; then |
| 184 | env_setup_script="$real_env_setup_script" |
| 185 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 186 | |
| 187 | @SDK_POST_INSTALL_COMMAND@ |
| 188 | |
| 189 | # delete the relocating script, so that user is forced to re-run the installer |
| 190 | # if he/she wants another location for the sdk |
| 191 | if [ $savescripts = 0 ] ; then |
| 192 | $SUDO_EXEC rm -f ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh |
| 193 | fi |
| 194 | |
| 195 | echo "SDK has been successfully set up and is ready to be used." |
| 196 | echo "Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g." |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 197 | for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do |
| 198 | echo " \$ . $env_setup_script" |
| 199 | done |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 200 | |
| 201 | exit 0 |
| 202 | |
| 203 | MARKER: |