blob: 91804ec281860089ab62d87ded26a092a0cdae9a [file] [log] [blame]
Patrick Williamsf1e5d692016-03-30 15:21:19 -05001#!/bin/sh
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05003[ -z "$ENVCLEANED" ] && exec /usr/bin/env -i ENVCLEANED=1 HOME="$HOME" \
Patrick Williamsc0f7c042017-02-23 20:41:17 -06004 LC_ALL=en_US.UTF-8 \
5 TERM=$TERM \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006 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
9export PATH=`echo "$PATH" | sed -e 's/:\.//' -e 's/::/:/'`
10
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011tweakpath () {
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
22tweakpath /usr/sbin
23tweakpath /sbin
24
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025INST_ARCH=$(uname -m | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/")
26SDK_ARCH=$(echo @SDK_ARCH@ | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/")
27
Brad Bishop6e60e8b2018-02-01 10:27:11 -050028INST_GCC_VER=$(gcc --version | sed -ne 's/.* \([0-9]\+\.[0-9]\+\)\.[0-9]\+.*/\1/p')
29SDK_GCC_VER='@SDK_GCC_VER@'
30
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031verlte () {
32 [ "$1" = "`printf "$1\n$2" | sort -V | head -n1`" ]
33}
34
35verlt() {
36 [ "$1" = "$2" ] && return 1 || verlte $1 $2
37}
38
39verlt `uname -r` @OLDEST_KERNEL@
40if [ $? = 0 ]; then
41 echo "Error: The SDK needs a kernel > @OLDEST_KERNEL@"
42 exit 1
43fi
44
45if [ "$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 Williamsc0f7c042017-02-23 20:41:17 -060048 echo "Error: Incompatible SDK installer! Your host is $INST_ARCH and this SDK was built for $SDK_ARCH hosts."
Patrick Williamsc124f4f2015-09-15 14:41:29 -050049 exit 1
50 fi
51fi
52
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050053if ! 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
56fi
57
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058DEFAULT_INSTALL_DIR="@SDKPATH@"
59SUDO_EXEC=""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050060EXTRA_TAR_OPTIONS=""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050061target_sdk_dir=""
62answer=""
63relocate=1
64savescripts=0
65verbose=0
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050066publish=0
Patrick Williamsc0f7c042017-02-23 20:41:17 -060067listcontents=0
68while getopts ":yd:npDRSl" OPT; do
Patrick Williamsc124f4f2015-09-15 14:41:29 -050069 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 Williamsd8c66bc2016-06-20 12:57:21 -050079 p)
80 prepare_buildsystem="no"
81 publish=1
82 ;;
Patrick Williamsc124f4f2015-09-15 14:41:29 -050083 D)
84 verbose=1
85 ;;
86 R)
87 relocate=0
88 savescripts=1
89 ;;
90 S)
91 savescripts=1
92 ;;
Patrick Williamsc0f7c042017-02-23 20:41:17 -060093 l)
94 listcontents=1
95 ;;
Patrick Williamsc124f4f2015-09-15 14:41:29 -050096 *)
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 Williamsd8c66bc2016-06-20 12:57:21 -0500102 echo " -p Publish mode (implies -n)"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500103 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 Williamsc0f7c042017-02-23 20:41:17 -0600107 echo " -l list files that will be extracted"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500108 exit 1
109 ;;
110 esac
111done
112
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600113payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1))
114if [ "$listcontents" = "1" ] ; then
115 tail -n +$payload_offset $0| tar tvJ || exit 1
116 exit
117fi
118
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500119titlestr="@SDK_TITLE@ installer version @SDK_VERSION@"
120printf "%s\n" "$titlestr"
121printf "%${#titlestr}s\n" | tr " " "="
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122
123if [ $verbose = 1 ] ; then
124 set -x
125fi
126
127@SDK_PRE_INSTALL_COMMAND@
128
129# SDK_EXTENSIBLE is exposed from the SDK_PRE_INSTALL_COMMAND above
130if [ "$SDK_EXTENSIBLE" = "1" ]; then
131 DEFAULT_INSTALL_DIR="@SDKEXTPATH@"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500132 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 Williamsc124f4f2015-09-15 14:41:29 -0500137fi
138
139if [ "$target_sdk_dir" = "" ]; then
140 if [ "$answer" = "Y" ]; then
141 target_sdk_dir="$DEFAULT_INSTALL_DIR"
142 else
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500143 read -p "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " target_sdk_dir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500144 [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR
145 fi
146fi
147
148eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g')
149if [ -d "$target_sdk_dir" ]; then
150 target_sdk_dir=$(cd "$target_sdk_dir"; pwd)
151else
152 target_sdk_dir=$(readlink -m "$target_sdk_dir")
153fi
154
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500155# limit the length for target_sdk_dir, ensure the relocation behaviour in relocate_sdk.py has right result.
156if [ ${#target_sdk_dir} -gt 2048 ]; then
157 echo "Error: The target directory path is too long!!!"
158 exit 1
159fi
160
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500161if [ "$SDK_EXTENSIBLE" = "1" ]; then
162 # We're going to be running the build system, additional restrictions apply
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500163 if echo "$target_sdk_dir" | grep -q '[+\ @$]'; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500164 echo "The target directory path ($target_sdk_dir) contains illegal" \
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500165 "characters such as spaces, @, \$ or +. Abort!"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500166 exit 1
167 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600168 # 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 Williamsc124f4f2015-09-15 14:41:29 -0500178else
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
183fi
184
185if [ -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"
190else
191 printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed[Y/n]? "
192
193 default_answer="y"
194fi
195
196if [ "$answer" = "" ]; then
197 read answer
198 [ "$answer" = "" ] && answer="$default_answer"
199else
200 echo $answer
201fi
202
203if [ "$answer" != "Y" -a "$answer" != "y" ]; then
204 echo "Installation aborted!"
205 exit 1
206fi
207
208# Try to create the directory (this will not succeed if user doesn't have rights)
209mkdir -p $target_sdk_dir >/dev/null 2>&1
210
211# if don't have the right to access dir, gain by sudo
212if [ ! -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
231fi
232
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500233printf "Extracting SDK..."
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500234tail -n +$payload_offset $0| $SUDO_EXEC tar xJ -C $target_sdk_dir --checkpoint=.2500 $EXTRA_TAR_OPTIONS || exit 1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500235echo "done"
236
237printf "Setting it up..."
238# fix environment paths
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500239real_env_setup_script=""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500240for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500241 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 Williamsc124f4f2015-09-15 14:41:29 -0500248 $SUDO_EXEC sed -e "s:@SDKPATH@:$target_sdk_dir:g" -i $env_setup_script
249done
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500250if [ -n "$real_env_setup_script" ] ; then
251 env_setup_script="$real_env_setup_script"
252fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500253
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
258if [ $savescripts = 0 ] ; then
259 $SUDO_EXEC rm -f ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh
260fi
261
262echo "SDK has been successfully set up and is ready to be used."
263echo "Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g."
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500264for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do
265 echo " \$ . $env_setup_script"
266done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500267
268exit 0
269
270MARKER: