summaryrefslogtreecommitdiffstats
path: root/meta/files/toolchain-shar-extract.sh
diff options
context:
space:
mode:
Diffstat (limited to 'meta/files/toolchain-shar-extract.sh')
-rw-r--r--meta/files/toolchain-shar-extract.sh154
1 files changed, 154 insertions, 0 deletions
diff --git a/meta/files/toolchain-shar-extract.sh b/meta/files/toolchain-shar-extract.sh
new file mode 100644
index 0000000000..516aa3a142
--- /dev/null
+++ b/meta/files/toolchain-shar-extract.sh
@@ -0,0 +1,154 @@
1#!/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:DRS" OPT; do
36 case $OPT in
37 y)
38 answer="Y"
39 [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR
40 ;;
41 d)
42 target_sdk_dir=$OPTARG
43 ;;
44 D)
45 verbose=1
46 ;;
47 R)
48 relocate=0
49 savescripts=1
50 ;;
51 S)
52 savescripts=1
53 ;;
54 *)
55 echo "Usage: $(basename $0) [-y] [-d <dir>]"
56 echo " -y Automatic yes to all prompts"
57 echo " -d <dir> Install the SDK to <dir>"
58 echo "======== Advanced DEBUGGING ONLY OPTIONS ========"
59 echo " -S Save relocation scripts"
60 echo " -R Do not relocate executables"
61 echo " -D use set -x to see what is going on"
62 exit 1
63 ;;
64 esac
65done
66
67if [ $verbose = 1 ] ; then
68 set -x
69fi
70
71if [ "$target_sdk_dir" = "" ]; then
72 read -e -p "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " target_sdk_dir
73 [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR
74fi
75
76eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g')
77if [ -d "$target_sdk_dir" ]; then
78 target_sdk_dir=$(cd "$target_sdk_dir"; pwd)
79else
80 target_sdk_dir=$(readlink -m "$target_sdk_dir")
81fi
82
83if [ -n "$(echo $target_sdk_dir|grep ' ')" ]; then
84 echo "The target directory path ($target_sdk_dir) contains spaces. Abort!"
85 exit 1
86fi
87
88if [ -e "$target_sdk_dir/environment-setup-@REAL_MULTIMACH_TARGET_SYS@" ]; then
89 echo "The directory \"$target_sdk_dir\" already contains a SDK for this architecture."
90 printf "If you continue, existing files will be overwritten! Proceed[y/N]?"
91
92 default_answer="n"
93else
94 printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed[Y/n]?"
95
96 default_answer="y"
97fi
98
99if [ "$answer" = "" ]; then
100 read answer
101 [ "$answer" = "" ] && answer="$default_answer"
102else
103 echo $answer
104fi
105
106if [ "$answer" != "Y" -a "$answer" != "y" ]; then
107 echo "Installation aborted!"
108 exit 1
109fi
110
111# Try to create the directory (this will not succeed if user doesn't have rights)
112mkdir -p $target_sdk_dir >/dev/null 2>&1
113
114# if don't have the right to access dir, gain by sudo
115if [ ! -x $target_sdk_dir -o ! -w $target_sdk_dir -o ! -r $target_sdk_dir ]; then
116 SUDO_EXEC=$(which "sudo")
117 if [ -z $SUDO_EXEC ]; then
118 echo "No command 'sudo' found, please install sudo first. Abort!"
119 exit 1
120 fi
121
122 # test sudo could gain root right
123 $SUDO_EXEC pwd >/dev/null 2>&1
124 [ $? -ne 0 ] && echo "Sorry, you are not allowed to execute as root." && exit 1
125
126 # now that we have sudo rights, create the directory
127 $SUDO_EXEC mkdir -p $target_sdk_dir >/dev/null 2>&1
128fi
129
130payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1))
131
132printf "Extracting SDK..."
133tail -n +$payload_offset $0| $SUDO_EXEC tar xj -C $target_sdk_dir
134echo "done"
135
136printf "Setting it up..."
137# fix environment paths
138for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do
139 $SUDO_EXEC sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" -i $env_setup_script
140done
141
142@SDK_POST_INSTALL_COMMAND@
143
144# delete the relocating script, so that user is forced to re-run the installer
145# if he/she wants another location for the sdk
146if [ $savescripts = 0 ] ; then
147 $SUDO_EXEC rm -f ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh
148fi
149
150echo "SDK has been successfully set up and is ready to be used."
151
152exit 0
153
154MARKER: