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