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