diff options
author | Hongxu Jia <hongxu.jia@windriver.com> | 2012-11-29 08:14:35 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-12-03 14:47:55 +0000 |
commit | 1b98ab72e7104886993a81f059561c210c9d306e (patch) | |
tree | 6dbf11e094d0567c94de7fee4fff831437671678 /meta/classes | |
parent | d55945c469a985e3054eaed5af1659e2cff0cc02 (diff) | |
download | poky-1b98ab72e7104886993a81f059561c210c9d306e.tar.gz |
populate_sdk_base:tarball installer:add sudo prompt
1.Adds a sudo passwd prompt during installation if the
user couldn't install on the dir.
2.Adds option -d <dir> to enter dir without prompt.
3.Adds option -y for automatic yes to all prompts, a non-
interactive method.
[YOCTO# 3153]
[YOCTO# 3309]
(From OE-Core rev: e85e1aace604626914a06dab4663094d6dd9b035)
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-rw-r--r-- | meta/classes/populate_sdk_base.bbclass | 69 |
1 files changed, 51 insertions, 18 deletions
diff --git a/meta/classes/populate_sdk_base.bbclass b/meta/classes/populate_sdk_base.bbclass index f1fcde6f44..02ade52d1c 100644 --- a/meta/classes/populate_sdk_base.bbclass +++ b/meta/classes/populate_sdk_base.bbclass | |||
@@ -128,12 +128,33 @@ fi | |||
128 | 128 | ||
129 | DEFAULT_INSTALL_DIR="${SDKPATH}" | 129 | DEFAULT_INSTALL_DIR="${SDKPATH}" |
130 | COMPONENTS_LEN=$(echo ".${SDKPATH}" | sed "s/\// /g" | wc -w) | 130 | COMPONENTS_LEN=$(echo ".${SDKPATH}" | sed "s/\// /g" | wc -w) |
131 | SUDO_EXEC="" | ||
132 | target_sdk_dir="" | ||
133 | answer="" | ||
134 | while getopts ":yd:" OPT; do | ||
135 | case $OPT in | ||
136 | y) | ||
137 | answer="Y" | ||
138 | [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR | ||
139 | ;; | ||
140 | d) | ||
141 | target_sdk_dir=$OPTARG | ||
142 | ;; | ||
143 | *) | ||
144 | echo "Usage: $(basename $0) [-y] [-d <dir>]" | ||
145 | echo " -y Automatic yes to all prompts" | ||
146 | echo " -d <dir> Install the SDK to <dir>" | ||
147 | exit 1 | ||
148 | ;; | ||
149 | esac | ||
150 | done | ||
131 | 151 | ||
132 | printf "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " | 152 | printf "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " |
133 | read target_sdk_dir | ||
134 | |||
135 | if [ "$target_sdk_dir" = "" ]; then | 153 | if [ "$target_sdk_dir" = "" ]; then |
136 | target_sdk_dir=$DEFAULT_INSTALL_DIR | 154 | read target_sdk_dir |
155 | [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR | ||
156 | else | ||
157 | echo "$target_sdk_dir" | ||
137 | fi | 158 | fi |
138 | 159 | ||
139 | eval target_sdk_dir=$target_sdk_dir | 160 | eval target_sdk_dir=$target_sdk_dir |
@@ -153,10 +174,12 @@ else | |||
153 | 174 | ||
154 | default_answer="y" | 175 | default_answer="y" |
155 | fi | 176 | fi |
156 | read answer | ||
157 | 177 | ||
158 | if [ "$answer" = "" ]; then | 178 | if [ "$answer" = "" ]; then |
159 | answer="$default_answer" | 179 | read answer |
180 | [ "$answer" = "" ] && answer="$default_answer" | ||
181 | else | ||
182 | echo $answer | ||
160 | fi | 183 | fi |
161 | 184 | ||
162 | if [ "$answer" != "Y" -a "$answer" != "y" ]; then | 185 | if [ "$answer" != "Y" -a "$answer" != "y" ]; then |
@@ -164,47 +187,57 @@ if [ "$answer" != "Y" -a "$answer" != "y" ]; then | |||
164 | exit 1 | 187 | exit 1 |
165 | fi | 188 | fi |
166 | 189 | ||
190 | # create dir and don't care about the result. | ||
167 | mkdir -p $target_sdk_dir >/dev/null 2>&1 | 191 | mkdir -p $target_sdk_dir >/dev/null 2>&1 |
168 | if [ $? -ne 0 ]; then | 192 | |
169 | echo "Error: Unable to create target directory. Do you have permissions?" | 193 | # if don't have the right to access dir, gain by sudo |
170 | exit 1 | 194 | if [ ! -x $target_sdk_dir -o ! -w $target_sdk_dir -o ! -r $target_sdk_dir ]; then |
195 | SUDO_EXEC=$(which "sudo") | ||
196 | if [ -z $SUDO_EXEC ]; then | ||
197 | echo "No command 'sudo' found, please install sudo first. Abort!" | ||
198 | exit 1 | ||
199 | fi | ||
200 | |||
201 | # test sudo could gain root right | ||
202 | $SUDO_EXEC pwd >/dev/null 2>&1 | ||
203 | [ $? -ne 0 ] && echo "Sorry, you are not allowed to execute as root." && exit 1 | ||
171 | fi | 204 | fi |
172 | 205 | ||
173 | payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1)) | 206 | payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1)) |
174 | 207 | ||
175 | printf "Extracting SDK..." | 208 | printf "Extracting SDK..." |
176 | tail -n +$payload_offset $0| tar xj --strip-components=$COMPONENTS_LEN -C $target_sdk_dir | 209 | tail -n +$payload_offset $0| $SUDO_EXEC tar xj --strip-components=$COMPONENTS_LEN -C $target_sdk_dir |
177 | echo "done" | 210 | echo "done" |
178 | 211 | ||
179 | printf "Setting it up..." | 212 | printf "Setting it up..." |
180 | # fix environment paths | 213 | # fix environment paths |
181 | for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do | 214 | for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do |
182 | sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" -i $env_setup_script | 215 | $SUDO_EXEC sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" -i $env_setup_script |
183 | done | 216 | done |
184 | 217 | ||
185 | # fix dynamic loader paths in all ELF SDK binaries | 218 | # fix dynamic loader paths in all ELF SDK binaries |
186 | native_sysroot=$(cat $env_setup_script |grep OECORE_NATIVE_SYSROOT|cut -d'=' -f2|tr -d '"') | 219 | native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep OECORE_NATIVE_SYSROOT|cut -d'=' -f2|tr -d '"') |
187 | dl_path=$(find $native_sysroot/lib -name "ld-linux*") | 220 | dl_path=$($SUDO_EXEC find $native_sysroot/lib -name "ld-linux*") |
188 | executable_files=$(find $native_sysroot -type f -perm +111) | 221 | executable_files=$($SUDO_EXEC find $native_sysroot -type f -perm +111) |
189 | ${env_setup_script%/*}/relocate_sdk.py $target_sdk_dir $dl_path $executable_files | 222 | $SUDO_EXEC ${env_setup_script%/*}/relocate_sdk.py $target_sdk_dir $dl_path $executable_files |
190 | if [ $? -ne 0 ]; then | 223 | if [ $? -ne 0 ]; then |
191 | echo "SDK could not be set up. Relocate script failed. Abort!" | 224 | echo "SDK could not be set up. Relocate script failed. Abort!" |
192 | exit 1 | 225 | exit 1 |
193 | fi | 226 | fi |
194 | 227 | ||
195 | # replace ${SDKPATH} with the new prefix in all text files: configs/scripts/etc | 228 | # replace ${SDKPATH} with the new prefix in all text files: configs/scripts/etc |
196 | find $native_sysroot -type f -exec file '{}' \;|grep ":.*ASCII.*text"|cut -d':' -f1|xargs sed -i -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" | 229 | $SUDO_EXEC find $native_sysroot -type f -exec file '{}' \;|$SUDO_EXEC grep ":.*ASCII.*text"|cut -d':' -f1|$SUDO_EXEC xargs sed -i -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" |
197 | 230 | ||
198 | # change all symlinks pointing to ${SDKPATH} | 231 | # change all symlinks pointing to ${SDKPATH} |
199 | for l in $(find $native_sysroot -type l); do | 232 | for l in $($SUDO_EXEC find $native_sysroot -type l); do |
200 | ln -sfn $(readlink $l|sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:") $l | 233 | $SUDO_EXEC ln -sfn $(readlink $l|$SUDO_EXEC sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:") $l |
201 | done | 234 | done |
202 | 235 | ||
203 | echo done | 236 | echo done |
204 | 237 | ||
205 | # delete the relocating script, so that user is forced to re-run the installer | 238 | # delete the relocating script, so that user is forced to re-run the installer |
206 | # if he/she wants another location for the sdk | 239 | # if he/she wants another location for the sdk |
207 | rm ${env_setup_script%/*}/relocate_sdk.py | 240 | $SUDO_EXEC rm ${env_setup_script%/*}/relocate_sdk.py |
208 | 241 | ||
209 | echo "SDK has been successfully set up and is ready to be used." | 242 | echo "SDK has been successfully set up and is ready to be used." |
210 | 243 | ||