blob: 35d3c75506ee8ccea0078f1197d4883abda5a6dc [file] [log] [blame]
Patrick Williamsf1e5d692016-03-30 15:21:19 -05001#!/bin/sh
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
3INST_ARCH=$(uname -m | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/")
4SDK_ARCH=$(echo @SDK_ARCH@ | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/")
5
6verlte () {
7 [ "$1" = "`printf "$1\n$2" | sort -V | head -n1`" ]
8}
9
10verlt() {
11 [ "$1" = "$2" ] && return 1 || verlte $1 $2
12}
13
14verlt `uname -r` @OLDEST_KERNEL@
15if [ $? = 0 ]; then
16 echo "Error: The SDK needs a kernel > @OLDEST_KERNEL@"
17 exit 1
18fi
19
20if [ "$INST_ARCH" != "$SDK_ARCH" ]; then
21 # Allow for installation of ix86 SDK on x86_64 host
22 if [ "$INST_ARCH" != x86_64 -o "$SDK_ARCH" != ix86 ]; then
23 echo "Error: Installation machine not supported!"
24 exit 1
25 fi
26fi
27
28DEFAULT_INSTALL_DIR="@SDKPATH@"
29SUDO_EXEC=""
30target_sdk_dir=""
31answer=""
32relocate=1
33savescripts=0
34verbose=0
35while getopts ":yd:nDRS" OPT; do
36 case $OPT in
37 y)
38 answer="Y"
39 ;;
40 d)
41 target_sdk_dir=$OPTARG
42 ;;
43 n)
44 prepare_buildsystem="no"
45 ;;
46 D)
47 verbose=1
48 ;;
49 R)
50 relocate=0
51 savescripts=1
52 ;;
53 S)
54 savescripts=1
55 ;;
56 *)
57 echo "Usage: $(basename $0) [-y] [-d <dir>]"
58 echo " -y Automatic yes to all prompts"
59 echo " -d <dir> Install the SDK to <dir>"
60 echo "======== Extensible SDK only options ============"
61 echo " -n Do not prepare the build system"
62 echo "======== Advanced DEBUGGING ONLY OPTIONS ========"
63 echo " -S Save relocation scripts"
64 echo " -R Do not relocate executables"
65 echo " -D use set -x to see what is going on"
66 exit 1
67 ;;
68 esac
69done
70
Patrick Williamsf1e5d692016-03-30 15:21:19 -050071titlestr="@SDK_TITLE@ installer version @SDK_VERSION@"
72printf "%s\n" "$titlestr"
73printf "%${#titlestr}s\n" | tr " " "="
Patrick Williamsc124f4f2015-09-15 14:41:29 -050074
75if [ $verbose = 1 ] ; then
76 set -x
77fi
78
79@SDK_PRE_INSTALL_COMMAND@
80
81# SDK_EXTENSIBLE is exposed from the SDK_PRE_INSTALL_COMMAND above
82if [ "$SDK_EXTENSIBLE" = "1" ]; then
83 DEFAULT_INSTALL_DIR="@SDKEXTPATH@"
84fi
85
86if [ "$target_sdk_dir" = "" ]; then
87 if [ "$answer" = "Y" ]; then
88 target_sdk_dir="$DEFAULT_INSTALL_DIR"
89 else
Patrick Williamsf1e5d692016-03-30 15:21:19 -050090 read -p "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " target_sdk_dir
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091 [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR
92 fi
93fi
94
95eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g')
96if [ -d "$target_sdk_dir" ]; then
97 target_sdk_dir=$(cd "$target_sdk_dir"; pwd)
98else
99 target_sdk_dir=$(readlink -m "$target_sdk_dir")
100fi
101
102if [ "$SDK_EXTENSIBLE" = "1" ]; then
103 # We're going to be running the build system, additional restrictions apply
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500104 if echo "$target_sdk_dir" | grep -q '[+\ @$]'; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500105 echo "The target directory path ($target_sdk_dir) contains illegal" \
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500106 "characters such as spaces, @, \$ or +. Abort!"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107 exit 1
108 fi
109else
110 if [ -n "$(echo $target_sdk_dir|grep ' ')" ]; then
111 echo "The target directory path ($target_sdk_dir) contains spaces. Abort!"
112 exit 1
113 fi
114fi
115
116if [ -e "$target_sdk_dir/environment-setup-@REAL_MULTIMACH_TARGET_SYS@" ]; then
117 echo "The directory \"$target_sdk_dir\" already contains a SDK for this architecture."
118 printf "If you continue, existing files will be overwritten! Proceed[y/N]? "
119
120 default_answer="n"
121else
122 printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed[Y/n]? "
123
124 default_answer="y"
125fi
126
127if [ "$answer" = "" ]; then
128 read answer
129 [ "$answer" = "" ] && answer="$default_answer"
130else
131 echo $answer
132fi
133
134if [ "$answer" != "Y" -a "$answer" != "y" ]; then
135 echo "Installation aborted!"
136 exit 1
137fi
138
139# Try to create the directory (this will not succeed if user doesn't have rights)
140mkdir -p $target_sdk_dir >/dev/null 2>&1
141
142# if don't have the right to access dir, gain by sudo
143if [ ! -x $target_sdk_dir -o ! -w $target_sdk_dir -o ! -r $target_sdk_dir ]; then
144 if [ "$SDK_EXTENSIBLE" = "1" ]; then
145 echo "Unable to access \"$target_sdk_dir\", will not attempt to use" \
146 "sudo as as extensible SDK cannot be used as root."
147 exit 1
148 fi
149
150 SUDO_EXEC=$(which "sudo")
151 if [ -z $SUDO_EXEC ]; then
152 echo "No command 'sudo' found, please install sudo first. Abort!"
153 exit 1
154 fi
155
156 # test sudo could gain root right
157 $SUDO_EXEC pwd >/dev/null 2>&1
158 [ $? -ne 0 ] && echo "Sorry, you are not allowed to execute as root." && exit 1
159
160 # now that we have sudo rights, create the directory
161 $SUDO_EXEC mkdir -p $target_sdk_dir >/dev/null 2>&1
162fi
163
164payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1))
165
166printf "Extracting SDK..."
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500167tail -n +$payload_offset $0| $SUDO_EXEC tar xj -C $target_sdk_dir --checkpoint=.2500
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500168echo "done"
169
170printf "Setting it up..."
171# fix environment paths
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500172real_env_setup_script=""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500173for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500174 if grep -q 'OECORE_NATIVE_SYSROOT=' $env_setup_script; then
175 # Handle custom env setup scripts that are only named
176 # environment-setup-* so that they have relocation
177 # applied - what we want beyond here is the main one
178 # rather than the one that simply sorts last
179 real_env_setup_script="$env_setup_script"
180 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500181 $SUDO_EXEC sed -e "s:@SDKPATH@:$target_sdk_dir:g" -i $env_setup_script
182done
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500183if [ -n "$real_env_setup_script" ] ; then
184 env_setup_script="$real_env_setup_script"
185fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186
187@SDK_POST_INSTALL_COMMAND@
188
189# delete the relocating script, so that user is forced to re-run the installer
190# if he/she wants another location for the sdk
191if [ $savescripts = 0 ] ; then
192 $SUDO_EXEC rm -f ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh
193fi
194
195echo "SDK has been successfully set up and is ready to be used."
196echo "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 -0500197for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do
198 echo " \$ . $env_setup_script"
199done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500200
201exit 0
202
203MARKER: