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