blob: 397be111989fa11a86be6fac7a0d221c3dc12ce3 [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" \
4 http_proxy="$http_proxy" https_proxy="$https_proxy" ftp_proxy="$ftp_proxy" \
5 no_proxy="$no_proxy" all_proxy="$all_proxy" GIT_PROXY_COMMAND="$GIT_PROXY_COMMAND" "$0" "$@"
6[ -f /etc/environment ] && . /etc/environment
7export PATH=`echo "$PATH" | sed -e 's/:\.//' -e 's/::/:/'`
8
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009INST_ARCH=$(uname -m | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/")
10SDK_ARCH=$(echo @SDK_ARCH@ | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/")
11
12verlte () {
13 [ "$1" = "`printf "$1\n$2" | sort -V | head -n1`" ]
14}
15
16verlt() {
17 [ "$1" = "$2" ] && return 1 || verlte $1 $2
18}
19
20verlt `uname -r` @OLDEST_KERNEL@
21if [ $? = 0 ]; then
22 echo "Error: The SDK needs a kernel > @OLDEST_KERNEL@"
23 exit 1
24fi
25
26if [ "$INST_ARCH" != "$SDK_ARCH" ]; then
27 # Allow for installation of ix86 SDK on x86_64 host
28 if [ "$INST_ARCH" != x86_64 -o "$SDK_ARCH" != ix86 ]; then
29 echo "Error: Installation machine not supported!"
30 exit 1
31 fi
32fi
33
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050034if ! xz -V > /dev/null 2>&1; then
35 echo "Error: xz is required for installation of this SDK, please install it first"
36 exit 1
37fi
38
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039DEFAULT_INSTALL_DIR="@SDKPATH@"
40SUDO_EXEC=""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050041EXTRA_TAR_OPTIONS=""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042target_sdk_dir=""
43answer=""
44relocate=1
45savescripts=0
46verbose=0
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050047publish=0
48while getopts ":yd:npDRS" OPT; do
Patrick Williamsc124f4f2015-09-15 14:41:29 -050049 case $OPT in
50 y)
51 answer="Y"
52 ;;
53 d)
54 target_sdk_dir=$OPTARG
55 ;;
56 n)
57 prepare_buildsystem="no"
58 ;;
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050059 p)
60 prepare_buildsystem="no"
61 publish=1
62 ;;
Patrick Williamsc124f4f2015-09-15 14:41:29 -050063 D)
64 verbose=1
65 ;;
66 R)
67 relocate=0
68 savescripts=1
69 ;;
70 S)
71 savescripts=1
72 ;;
73 *)
74 echo "Usage: $(basename $0) [-y] [-d <dir>]"
75 echo " -y Automatic yes to all prompts"
76 echo " -d <dir> Install the SDK to <dir>"
77 echo "======== Extensible SDK only options ============"
78 echo " -n Do not prepare the build system"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050079 echo " -p Publish mode (implies -n)"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080 echo "======== Advanced DEBUGGING ONLY OPTIONS ========"
81 echo " -S Save relocation scripts"
82 echo " -R Do not relocate executables"
83 echo " -D use set -x to see what is going on"
84 exit 1
85 ;;
86 esac
87done
88
Patrick Williamsf1e5d692016-03-30 15:21:19 -050089titlestr="@SDK_TITLE@ installer version @SDK_VERSION@"
90printf "%s\n" "$titlestr"
91printf "%${#titlestr}s\n" | tr " " "="
Patrick Williamsc124f4f2015-09-15 14:41:29 -050092
93if [ $verbose = 1 ] ; then
94 set -x
95fi
96
97@SDK_PRE_INSTALL_COMMAND@
98
99# SDK_EXTENSIBLE is exposed from the SDK_PRE_INSTALL_COMMAND above
100if [ "$SDK_EXTENSIBLE" = "1" ]; then
101 DEFAULT_INSTALL_DIR="@SDKEXTPATH@"
102fi
103
104if [ "$target_sdk_dir" = "" ]; then
105 if [ "$answer" = "Y" ]; then
106 target_sdk_dir="$DEFAULT_INSTALL_DIR"
107 else
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500108 read -p "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " target_sdk_dir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109 [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR
110 fi
111fi
112
113eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g')
114if [ -d "$target_sdk_dir" ]; then
115 target_sdk_dir=$(cd "$target_sdk_dir"; pwd)
116else
117 target_sdk_dir=$(readlink -m "$target_sdk_dir")
118fi
119
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500120# limit the length for target_sdk_dir, ensure the relocation behaviour in relocate_sdk.py has right result.
121if [ ${#target_sdk_dir} -gt 2048 ]; then
122 echo "Error: The target directory path is too long!!!"
123 exit 1
124fi
125
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500126if [ "$SDK_EXTENSIBLE" = "1" ]; then
127 # We're going to be running the build system, additional restrictions apply
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500128 if echo "$target_sdk_dir" | grep -q '[+\ @$]'; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500129 echo "The target directory path ($target_sdk_dir) contains illegal" \
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500130 "characters such as spaces, @, \$ or +. Abort!"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500131 exit 1
132 fi
133else
134 if [ -n "$(echo $target_sdk_dir|grep ' ')" ]; then
135 echo "The target directory path ($target_sdk_dir) contains spaces. Abort!"
136 exit 1
137 fi
138fi
139
140if [ -e "$target_sdk_dir/environment-setup-@REAL_MULTIMACH_TARGET_SYS@" ]; then
141 echo "The directory \"$target_sdk_dir\" already contains a SDK for this architecture."
142 printf "If you continue, existing files will be overwritten! Proceed[y/N]? "
143
144 default_answer="n"
145else
146 printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed[Y/n]? "
147
148 default_answer="y"
149fi
150
151if [ "$answer" = "" ]; then
152 read answer
153 [ "$answer" = "" ] && answer="$default_answer"
154else
155 echo $answer
156fi
157
158if [ "$answer" != "Y" -a "$answer" != "y" ]; then
159 echo "Installation aborted!"
160 exit 1
161fi
162
163# Try to create the directory (this will not succeed if user doesn't have rights)
164mkdir -p $target_sdk_dir >/dev/null 2>&1
165
166# if don't have the right to access dir, gain by sudo
167if [ ! -x $target_sdk_dir -o ! -w $target_sdk_dir -o ! -r $target_sdk_dir ]; then
168 if [ "$SDK_EXTENSIBLE" = "1" ]; then
169 echo "Unable to access \"$target_sdk_dir\", will not attempt to use" \
170 "sudo as as extensible SDK cannot be used as root."
171 exit 1
172 fi
173
174 SUDO_EXEC=$(which "sudo")
175 if [ -z $SUDO_EXEC ]; then
176 echo "No command 'sudo' found, please install sudo first. Abort!"
177 exit 1
178 fi
179
180 # test sudo could gain root right
181 $SUDO_EXEC pwd >/dev/null 2>&1
182 [ $? -ne 0 ] && echo "Sorry, you are not allowed to execute as root." && exit 1
183
184 # now that we have sudo rights, create the directory
185 $SUDO_EXEC mkdir -p $target_sdk_dir >/dev/null 2>&1
186fi
187
188payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1))
189
190printf "Extracting SDK..."
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500191tail -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 -0500192echo "done"
193
194printf "Setting it up..."
195# fix environment paths
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500196real_env_setup_script=""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500197for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500198 if grep -q 'OECORE_NATIVE_SYSROOT=' $env_setup_script; then
199 # Handle custom env setup scripts that are only named
200 # environment-setup-* so that they have relocation
201 # applied - what we want beyond here is the main one
202 # rather than the one that simply sorts last
203 real_env_setup_script="$env_setup_script"
204 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500205 $SUDO_EXEC sed -e "s:@SDKPATH@:$target_sdk_dir:g" -i $env_setup_script
206done
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500207if [ -n "$real_env_setup_script" ] ; then
208 env_setup_script="$real_env_setup_script"
209fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500210
211@SDK_POST_INSTALL_COMMAND@
212
213# delete the relocating script, so that user is forced to re-run the installer
214# if he/she wants another location for the sdk
215if [ $savescripts = 0 ] ; then
216 $SUDO_EXEC rm -f ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh
217fi
218
219echo "SDK has been successfully set up and is ready to be used."
220echo "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 -0500221for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do
222 echo " \$ . $env_setup_script"
223done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500224
225exit 0
226
227MARKER: