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