blob: cd0a547f86d06db673c85f62c5a22953fb6b9ed0 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/bin/bash
2
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
71echo "@SDK_TITLE@ installer version @SDK_VERSION@"
72echo "==========================================================="
73
74if [ $verbose = 1 ] ; then
75 set -x
76fi
77
78@SDK_PRE_INSTALL_COMMAND@
79
80# SDK_EXTENSIBLE is exposed from the SDK_PRE_INSTALL_COMMAND above
81if [ "$SDK_EXTENSIBLE" = "1" ]; then
82 DEFAULT_INSTALL_DIR="@SDKEXTPATH@"
83fi
84
85if [ "$target_sdk_dir" = "" ]; then
86 if [ "$answer" = "Y" ]; then
87 target_sdk_dir="$DEFAULT_INSTALL_DIR"
88 else
89 read -e -p "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " target_sdk_dir
90 [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR
91 fi
92fi
93
94eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g')
95if [ -d "$target_sdk_dir" ]; then
96 target_sdk_dir=$(cd "$target_sdk_dir"; pwd)
97else
98 target_sdk_dir=$(readlink -m "$target_sdk_dir")
99fi
100
101if [ "$SDK_EXTENSIBLE" = "1" ]; then
102 # We're going to be running the build system, additional restrictions apply
103 if echo "$target_sdk_dir" | grep -q '[+\ @]'; then
104 echo "The target directory path ($target_sdk_dir) contains illegal" \
105 "characters such as spaces, @ or +. Abort!"
106 exit 1
107 fi
108else
109 if [ -n "$(echo $target_sdk_dir|grep ' ')" ]; then
110 echo "The target directory path ($target_sdk_dir) contains spaces. Abort!"
111 exit 1
112 fi
113fi
114
115if [ -e "$target_sdk_dir/environment-setup-@REAL_MULTIMACH_TARGET_SYS@" ]; then
116 echo "The directory \"$target_sdk_dir\" already contains a SDK for this architecture."
117 printf "If you continue, existing files will be overwritten! Proceed[y/N]? "
118
119 default_answer="n"
120else
121 printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed[Y/n]? "
122
123 default_answer="y"
124fi
125
126if [ "$answer" = "" ]; then
127 read answer
128 [ "$answer" = "" ] && answer="$default_answer"
129else
130 echo $answer
131fi
132
133if [ "$answer" != "Y" -a "$answer" != "y" ]; then
134 echo "Installation aborted!"
135 exit 1
136fi
137
138# Try to create the directory (this will not succeed if user doesn't have rights)
139mkdir -p $target_sdk_dir >/dev/null 2>&1
140
141# if don't have the right to access dir, gain by sudo
142if [ ! -x $target_sdk_dir -o ! -w $target_sdk_dir -o ! -r $target_sdk_dir ]; then
143 if [ "$SDK_EXTENSIBLE" = "1" ]; then
144 echo "Unable to access \"$target_sdk_dir\", will not attempt to use" \
145 "sudo as as extensible SDK cannot be used as root."
146 exit 1
147 fi
148
149 SUDO_EXEC=$(which "sudo")
150 if [ -z $SUDO_EXEC ]; then
151 echo "No command 'sudo' found, please install sudo first. Abort!"
152 exit 1
153 fi
154
155 # test sudo could gain root right
156 $SUDO_EXEC pwd >/dev/null 2>&1
157 [ $? -ne 0 ] && echo "Sorry, you are not allowed to execute as root." && exit 1
158
159 # now that we have sudo rights, create the directory
160 $SUDO_EXEC mkdir -p $target_sdk_dir >/dev/null 2>&1
161fi
162
163payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1))
164
165printf "Extracting SDK..."
166tail -n +$payload_offset $0| $SUDO_EXEC tar xj -C $target_sdk_dir
167echo "done"
168
169printf "Setting it up..."
170# fix environment paths
171for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do
172 $SUDO_EXEC sed -e "s:@SDKPATH@:$target_sdk_dir:g" -i $env_setup_script
173done
174
175@SDK_POST_INSTALL_COMMAND@
176
177# delete the relocating script, so that user is forced to re-run the installer
178# if he/she wants another location for the sdk
179if [ $savescripts = 0 ] ; then
180 $SUDO_EXEC rm -f ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh
181fi
182
183echo "SDK has been successfully set up and is ready to be used."
184echo "Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g."
185echo " \$ . $target_sdk_dir/environment-setup-@REAL_MULTIMACH_TARGET_SYS@"
186
187exit 0
188
189MARKER: