diff options
Diffstat (limited to 'meta/files/toolchain-shar-extract.sh')
-rw-r--r-- | meta/files/toolchain-shar-extract.sh | 154 |
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 | |||
3 | INST_ARCH=$(uname -m | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/") | ||
4 | SDK_ARCH=$(echo @SDK_ARCH@ | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/") | ||
5 | |||
6 | verlte () { | ||
7 | [ "$1" = "`printf "$1\n$2" | sort -V | head -n1`" ] | ||
8 | } | ||
9 | |||
10 | verlt() { | ||
11 | [ "$1" = "$2" ] && return 1 || verlte $1 $2 | ||
12 | } | ||
13 | |||
14 | verlt `uname -r` @OLDEST_KERNEL@ | ||
15 | if [ $? = 0 ]; then | ||
16 | echo "Error: The SDK needs a kernel > @OLDEST_KERNEL@" | ||
17 | exit 1 | ||
18 | fi | ||
19 | |||
20 | if [ "$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 | ||
26 | fi | ||
27 | |||
28 | DEFAULT_INSTALL_DIR="@SDKPATH@" | ||
29 | SUDO_EXEC="" | ||
30 | target_sdk_dir="" | ||
31 | answer="" | ||
32 | relocate=1 | ||
33 | savescripts=0 | ||
34 | verbose=0 | ||
35 | while 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 | ||
65 | done | ||
66 | |||
67 | if [ $verbose = 1 ] ; then | ||
68 | set -x | ||
69 | fi | ||
70 | |||
71 | if [ "$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 | ||
74 | fi | ||
75 | |||
76 | eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g') | ||
77 | if [ -d "$target_sdk_dir" ]; then | ||
78 | target_sdk_dir=$(cd "$target_sdk_dir"; pwd) | ||
79 | else | ||
80 | target_sdk_dir=$(readlink -m "$target_sdk_dir") | ||
81 | fi | ||
82 | |||
83 | if [ -n "$(echo $target_sdk_dir|grep ' ')" ]; then | ||
84 | echo "The target directory path ($target_sdk_dir) contains spaces. Abort!" | ||
85 | exit 1 | ||
86 | fi | ||
87 | |||
88 | if [ -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" | ||
93 | else | ||
94 | printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed[Y/n]?" | ||
95 | |||
96 | default_answer="y" | ||
97 | fi | ||
98 | |||
99 | if [ "$answer" = "" ]; then | ||
100 | read answer | ||
101 | [ "$answer" = "" ] && answer="$default_answer" | ||
102 | else | ||
103 | echo $answer | ||
104 | fi | ||
105 | |||
106 | if [ "$answer" != "Y" -a "$answer" != "y" ]; then | ||
107 | echo "Installation aborted!" | ||
108 | exit 1 | ||
109 | fi | ||
110 | |||
111 | # Try to create the directory (this will not succeed if user doesn't have rights) | ||
112 | mkdir -p $target_sdk_dir >/dev/null 2>&1 | ||
113 | |||
114 | # if don't have the right to access dir, gain by sudo | ||
115 | if [ ! -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 | ||
128 | fi | ||
129 | |||
130 | payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1)) | ||
131 | |||
132 | printf "Extracting SDK..." | ||
133 | tail -n +$payload_offset $0| $SUDO_EXEC tar xj -C $target_sdk_dir | ||
134 | echo "done" | ||
135 | |||
136 | printf "Setting it up..." | ||
137 | # fix environment paths | ||
138 | for 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 | ||
140 | done | ||
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 | ||
146 | if [ $savescripts = 0 ] ; then | ||
147 | $SUDO_EXEC rm -f ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh | ||
148 | fi | ||
149 | |||
150 | echo "SDK has been successfully set up and is ready to be used." | ||
151 | |||
152 | exit 0 | ||
153 | |||
154 | MARKER: | ||