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