blob: 9295ddc8695c0d01dde859cccd4f58231e63de75 [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
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011INST_ARCH=$(uname -m | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/")
12SDK_ARCH=$(echo @SDK_ARCH@ | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/")
13
14verlte () {
15 [ "$1" = "`printf "$1\n$2" | sort -V | head -n1`" ]
16}
17
18verlt() {
19 [ "$1" = "$2" ] && return 1 || verlte $1 $2
20}
21
22verlt `uname -r` @OLDEST_KERNEL@
23if [ $? = 0 ]; then
24 echo "Error: The SDK needs a kernel > @OLDEST_KERNEL@"
25 exit 1
26fi
27
28if [ "$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 Williamsc0f7c042017-02-23 20:41:17 -060031 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 -050032 exit 1
33 fi
34fi
35
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050036if ! 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
39fi
40
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041DEFAULT_INSTALL_DIR="@SDKPATH@"
42SUDO_EXEC=""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050043EXTRA_TAR_OPTIONS=""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044target_sdk_dir=""
45answer=""
46relocate=1
47savescripts=0
48verbose=0
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050049publish=0
Patrick Williamsc0f7c042017-02-23 20:41:17 -060050listcontents=0
51while getopts ":yd:npDRSl" OPT; do
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052 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 Williamsd8c66bc2016-06-20 12:57:21 -050062 p)
63 prepare_buildsystem="no"
64 publish=1
65 ;;
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066 D)
67 verbose=1
68 ;;
69 R)
70 relocate=0
71 savescripts=1
72 ;;
73 S)
74 savescripts=1
75 ;;
Patrick Williamsc0f7c042017-02-23 20:41:17 -060076 l)
77 listcontents=1
78 ;;
Patrick Williamsc124f4f2015-09-15 14:41:29 -050079 *)
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 Williamsd8c66bc2016-06-20 12:57:21 -050085 echo " -p Publish mode (implies -n)"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086 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 Williamsc0f7c042017-02-23 20:41:17 -060090 echo " -l list files that will be extracted"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091 exit 1
92 ;;
93 esac
94done
95
Patrick Williamsc0f7c042017-02-23 20:41:17 -060096payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1))
97if [ "$listcontents" = "1" ] ; then
98 tail -n +$payload_offset $0| tar tvJ || exit 1
99 exit
100fi
101
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500102titlestr="@SDK_TITLE@ installer version @SDK_VERSION@"
103printf "%s\n" "$titlestr"
104printf "%${#titlestr}s\n" | tr " " "="
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500105
106if [ $verbose = 1 ] ; then
107 set -x
108fi
109
110@SDK_PRE_INSTALL_COMMAND@
111
112# SDK_EXTENSIBLE is exposed from the SDK_PRE_INSTALL_COMMAND above
113if [ "$SDK_EXTENSIBLE" = "1" ]; then
114 DEFAULT_INSTALL_DIR="@SDKEXTPATH@"
115fi
116
117if [ "$target_sdk_dir" = "" ]; then
118 if [ "$answer" = "Y" ]; then
119 target_sdk_dir="$DEFAULT_INSTALL_DIR"
120 else
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500121 read -p "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " target_sdk_dir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122 [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR
123 fi
124fi
125
126eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g')
127if [ -d "$target_sdk_dir" ]; then
128 target_sdk_dir=$(cd "$target_sdk_dir"; pwd)
129else
130 target_sdk_dir=$(readlink -m "$target_sdk_dir")
131fi
132
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500133# limit the length for target_sdk_dir, ensure the relocation behaviour in relocate_sdk.py has right result.
134if [ ${#target_sdk_dir} -gt 2048 ]; then
135 echo "Error: The target directory path is too long!!!"
136 exit 1
137fi
138
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500139if [ "$SDK_EXTENSIBLE" = "1" ]; then
140 # We're going to be running the build system, additional restrictions apply
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500141 if echo "$target_sdk_dir" | grep -q '[+\ @$]'; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500142 echo "The target directory path ($target_sdk_dir) contains illegal" \
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500143 "characters such as spaces, @, \$ or +. Abort!"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500144 exit 1
145 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600146 # 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 Williamsc124f4f2015-09-15 14:41:29 -0500156else
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
161fi
162
163if [ -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"
168else
169 printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed[Y/n]? "
170
171 default_answer="y"
172fi
173
174if [ "$answer" = "" ]; then
175 read answer
176 [ "$answer" = "" ] && answer="$default_answer"
177else
178 echo $answer
179fi
180
181if [ "$answer" != "Y" -a "$answer" != "y" ]; then
182 echo "Installation aborted!"
183 exit 1
184fi
185
186# Try to create the directory (this will not succeed if user doesn't have rights)
187mkdir -p $target_sdk_dir >/dev/null 2>&1
188
189# if don't have the right to access dir, gain by sudo
190if [ ! -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
209fi
210
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500211printf "Extracting SDK..."
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500212tail -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 -0500213echo "done"
214
215printf "Setting it up..."
216# fix environment paths
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500217real_env_setup_script=""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500218for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500219 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 Williamsc124f4f2015-09-15 14:41:29 -0500226 $SUDO_EXEC sed -e "s:@SDKPATH@:$target_sdk_dir:g" -i $env_setup_script
227done
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500228if [ -n "$real_env_setup_script" ] ; then
229 env_setup_script="$real_env_setup_script"
230fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500231
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
236if [ $savescripts = 0 ] ; then
237 $SUDO_EXEC rm -f ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh
238fi
239
240echo "SDK has been successfully set up and is ready to be used."
241echo "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 -0500242for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do
243 echo " \$ . $env_setup_script"
244done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500245
246exit 0
247
248MARKER: