blob: bea6d4189a02580d8ea42ea00cc21fffde878069 [file] [log] [blame]
Patrick Williamsf1e5d692016-03-30 15:21:19 -05001#!/bin/sh
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
Andrew Geissler82c905d2020-04-13 13:39:40 -05003export LC_ALL=en_US.UTF-8
4#Make sure at least one python is installed
5INIT_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
10PATH=`$INIT_PYTHON -c 'import os; print(":".join(e for e in os.environ["PATH"].split(":") if os.path.exists(e)))'`
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050011
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012tweakpath () {
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
23tweakpath /usr/sbin
24tweakpath /sbin
25
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026INST_ARCH=$(uname -m | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/")
27SDK_ARCH=$(echo @SDK_ARCH@ | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/")
28
Andrew Geissler4c19ea12020-10-27 13:52:24 -050029INST_GCC_VER=$(gcc --version 2>/dev/null | sed -ne 's/.* \([0-9]\+\.[0-9]\+\)\.[0-9]\+.*/\1/p')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030SDK_GCC_VER='@SDK_GCC_VER@'
31
Patrick Williamsc124f4f2015-09-15 14:41:29 -050032verlte () {
33 [ "$1" = "`printf "$1\n$2" | sort -V | head -n1`" ]
34}
35
36verlt() {
37 [ "$1" = "$2" ] && return 1 || verlte $1 $2
38}
39
40verlt `uname -r` @OLDEST_KERNEL@
41if [ $? = 0 ]; then
42 echo "Error: The SDK needs a kernel > @OLDEST_KERNEL@"
43 exit 1
44fi
45
46if [ "$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 Williamsc0f7c042017-02-23 20:41:17 -060049 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 -050050 exit 1
51 fi
52fi
53
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050054if ! 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
57fi
58
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059DEFAULT_INSTALL_DIR="@SDKPATH@"
60SUDO_EXEC=""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050061EXTRA_TAR_OPTIONS=""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050062target_sdk_dir=""
63answer=""
64relocate=1
65savescripts=0
66verbose=0
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050067publish=0
Patrick Williamsc0f7c042017-02-23 20:41:17 -060068listcontents=0
69while getopts ":yd:npDRSl" OPT; do
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070 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 Williamsd8c66bc2016-06-20 12:57:21 -050080 p)
81 prepare_buildsystem="no"
82 publish=1
83 ;;
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084 D)
85 verbose=1
86 ;;
87 R)
88 relocate=0
89 savescripts=1
90 ;;
91 S)
92 savescripts=1
93 ;;
Patrick Williamsc0f7c042017-02-23 20:41:17 -060094 l)
95 listcontents=1
96 ;;
Patrick Williamsc124f4f2015-09-15 14:41:29 -050097 *)
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 Williamsd8c66bc2016-06-20 12:57:21 -0500103 echo " -p Publish mode (implies -n)"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500104 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 Williamsc0f7c042017-02-23 20:41:17 -0600108 echo " -l list files that will be extracted"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109 exit 1
110 ;;
111 esac
112done
113
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600114payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1))
115if [ "$listcontents" = "1" ] ; then
Brad Bishopc342db32019-05-15 21:57:59 -0400116 if [ @SDK_ARCHIVE_TYPE@ = "zip" ]; then
117 tail -n +$payload_offset $0 > sdk.zip
118 if unzip -l sdk.zip;then
119 rm sdk.zip
120 else
121 rm sdk.zip && exit 1
122 fi
123 else
124 tail -n +$payload_offset $0| tar tvJ || exit 1
125 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600126 exit
127fi
128
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500129titlestr="@SDK_TITLE@ installer version @SDK_VERSION@"
130printf "%s\n" "$titlestr"
131printf "%${#titlestr}s\n" | tr " " "="
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500132
133if [ $verbose = 1 ] ; then
134 set -x
135fi
136
137@SDK_PRE_INSTALL_COMMAND@
138
139# SDK_EXTENSIBLE is exposed from the SDK_PRE_INSTALL_COMMAND above
140if [ "$SDK_EXTENSIBLE" = "1" ]; then
141 DEFAULT_INSTALL_DIR="@SDKEXTPATH@"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500142 if [ "$INST_GCC_VER" = '4.8' -a "$SDK_GCC_VER" = '4.9' ] || [ "$INST_GCC_VER" = '4.8' -a "$SDK_GCC_VER" = '' ] || \
143 [ "$INST_GCC_VER" = '4.9' -a "$SDK_GCC_VER" = '' ]; then
144 echo "Error: Incompatible SDK installer! Your host gcc version is $INST_GCC_VER and this SDK was built by gcc higher version."
145 exit 1
146 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500147fi
148
149if [ "$target_sdk_dir" = "" ]; then
150 if [ "$answer" = "Y" ]; then
151 target_sdk_dir="$DEFAULT_INSTALL_DIR"
152 else
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500153 read -p "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " target_sdk_dir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154 [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR
155 fi
156fi
157
158eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g')
159if [ -d "$target_sdk_dir" ]; then
160 target_sdk_dir=$(cd "$target_sdk_dir"; pwd)
161else
162 target_sdk_dir=$(readlink -m "$target_sdk_dir")
163fi
164
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500165# limit the length for target_sdk_dir, ensure the relocation behaviour in relocate_sdk.py has right result.
166if [ ${#target_sdk_dir} -gt 2048 ]; then
167 echo "Error: The target directory path is too long!!!"
168 exit 1
169fi
170
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500171if [ "$SDK_EXTENSIBLE" = "1" ]; then
172 # We're going to be running the build system, additional restrictions apply
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500173 if echo "$target_sdk_dir" | grep -q '[+\ @$]'; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500174 echo "The target directory path ($target_sdk_dir) contains illegal" \
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500175 "characters such as spaces, @, \$ or +. Abort!"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500176 exit 1
177 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600178 # The build system doesn't work well with /tmp on NFS
179 fs_dev_path="$target_sdk_dir"
180 while [ ! -d "$fs_dev_path" ] ; do
181 fs_dev_path=`dirname $fs_dev_path`
182 done
183 fs_dev_type=`stat -f -c '%t' "$fs_dev_path"`
184 if [ "$fsdevtype" = "6969" ] ; then
185 echo "The target directory path $target_sdk_dir is on NFS, this is not possible. Abort!"
186 exit 1
187 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500188else
189 if [ -n "$(echo $target_sdk_dir|grep ' ')" ]; then
190 echo "The target directory path ($target_sdk_dir) contains spaces. Abort!"
191 exit 1
192 fi
193fi
194
195if [ -e "$target_sdk_dir/environment-setup-@REAL_MULTIMACH_TARGET_SYS@" ]; then
196 echo "The directory \"$target_sdk_dir\" already contains a SDK for this architecture."
Brad Bishop19323692019-04-05 15:28:33 -0400197 printf "If you continue, existing files will be overwritten! Proceed [y/N]? "
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500198
199 default_answer="n"
200else
Brad Bishop19323692019-04-05 15:28:33 -0400201 printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed [Y/n]? "
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500202
203 default_answer="y"
204fi
205
206if [ "$answer" = "" ]; then
207 read answer
208 [ "$answer" = "" ] && answer="$default_answer"
209else
210 echo $answer
211fi
212
213if [ "$answer" != "Y" -a "$answer" != "y" ]; then
214 echo "Installation aborted!"
215 exit 1
216fi
217
218# Try to create the directory (this will not succeed if user doesn't have rights)
219mkdir -p $target_sdk_dir >/dev/null 2>&1
220
221# if don't have the right to access dir, gain by sudo
222if [ ! -x $target_sdk_dir -o ! -w $target_sdk_dir -o ! -r $target_sdk_dir ]; then
223 if [ "$SDK_EXTENSIBLE" = "1" ]; then
224 echo "Unable to access \"$target_sdk_dir\", will not attempt to use" \
225 "sudo as as extensible SDK cannot be used as root."
226 exit 1
227 fi
228
229 SUDO_EXEC=$(which "sudo")
230 if [ -z $SUDO_EXEC ]; then
231 echo "No command 'sudo' found, please install sudo first. Abort!"
232 exit 1
233 fi
234
235 # test sudo could gain root right
236 $SUDO_EXEC pwd >/dev/null 2>&1
237 [ $? -ne 0 ] && echo "Sorry, you are not allowed to execute as root." && exit 1
238
239 # now that we have sudo rights, create the directory
240 $SUDO_EXEC mkdir -p $target_sdk_dir >/dev/null 2>&1
241fi
242
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500243printf "Extracting SDK..."
Brad Bishopc342db32019-05-15 21:57:59 -0400244if [ @SDK_ARCHIVE_TYPE@ = "zip" ]; then
245 tail -n +$payload_offset $0 > sdk.zip
246 if $SUDO_EXEC unzip $EXTRA_TAR_OPTIONS sdk.zip -d $target_sdk_dir;then
247 rm sdk.zip
248 else
249 rm sdk.zip && exit 1
250 fi
251else
Andrew Geissler82c905d2020-04-13 13:39:40 -0500252 tail -n +$payload_offset $0| $SUDO_EXEC tar mxJ -C $target_sdk_dir --checkpoint=.2500 $EXTRA_TAR_OPTIONS || exit 1
Brad Bishopc342db32019-05-15 21:57:59 -0400253fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500254echo "done"
255
256printf "Setting it up..."
257# fix environment paths
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500258real_env_setup_script=""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500259for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500260 if grep -q 'OECORE_NATIVE_SYSROOT=' $env_setup_script; then
261 # Handle custom env setup scripts that are only named
262 # environment-setup-* so that they have relocation
263 # applied - what we want beyond here is the main one
264 # rather than the one that simply sorts last
265 real_env_setup_script="$env_setup_script"
266 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500267 $SUDO_EXEC sed -e "s:@SDKPATH@:$target_sdk_dir:g" -i $env_setup_script
268done
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500269if [ -n "$real_env_setup_script" ] ; then
270 env_setup_script="$real_env_setup_script"
271fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500272
273@SDK_POST_INSTALL_COMMAND@
274
275# delete the relocating script, so that user is forced to re-run the installer
276# if he/she wants another location for the sdk
277if [ $savescripts = 0 ] ; then
278 $SUDO_EXEC rm -f ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh
279fi
280
Brad Bishop316dfdd2018-06-25 12:45:53 -0400281# Execute post-relocation script
282post_relocate="$target_sdk_dir/post-relocate-setup.sh"
283if [ -e "$post_relocate" ]; then
284 $SUDO_EXEC sed -e "s:@SDKPATH@:$target_sdk_dir:g" -i $post_relocate
285 $SUDO_EXEC /bin/sh $post_relocate "$target_sdk_dir" "@SDKPATH@"
286 $SUDO_EXEC rm -f $post_relocate
287fi
288
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500289echo "SDK has been successfully set up and is ready to be used."
290echo "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 -0500291for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do
292 echo " \$ . $env_setup_script"
293done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500294
295exit 0
296
297MARKER: