summaryrefslogtreecommitdiffstats
path: root/meta/classes/populate_sdk_base.bbclass
diff options
context:
space:
mode:
authorHongxu Jia <hongxu.jia@windriver.com>2012-11-29 08:14:35 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-12-03 14:47:55 +0000
commit1b98ab72e7104886993a81f059561c210c9d306e (patch)
tree6dbf11e094d0567c94de7fee4fff831437671678 /meta/classes/populate_sdk_base.bbclass
parentd55945c469a985e3054eaed5af1659e2cff0cc02 (diff)
downloadpoky-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/populate_sdk_base.bbclass')
-rw-r--r--meta/classes/populate_sdk_base.bbclass69
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
129DEFAULT_INSTALL_DIR="${SDKPATH}" 129DEFAULT_INSTALL_DIR="${SDKPATH}"
130COMPONENTS_LEN=$(echo ".${SDKPATH}" | sed "s/\// /g" | wc -w) 130COMPONENTS_LEN=$(echo ".${SDKPATH}" | sed "s/\// /g" | wc -w)
131SUDO_EXEC=""
132target_sdk_dir=""
133answer=""
134while 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
150done
131 151
132printf "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " 152printf "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): "
133read target_sdk_dir
134
135if [ "$target_sdk_dir" = "" ]; then 153if [ "$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
156else
157 echo "$target_sdk_dir"
137fi 158fi
138 159
139eval target_sdk_dir=$target_sdk_dir 160eval target_sdk_dir=$target_sdk_dir
@@ -153,10 +174,12 @@ else
153 174
154 default_answer="y" 175 default_answer="y"
155fi 176fi
156read answer
157 177
158if [ "$answer" = "" ]; then 178if [ "$answer" = "" ]; then
159 answer="$default_answer" 179 read answer
180 [ "$answer" = "" ] && answer="$default_answer"
181else
182 echo $answer
160fi 183fi
161 184
162if [ "$answer" != "Y" -a "$answer" != "y" ]; then 185if [ "$answer" != "Y" -a "$answer" != "y" ]; then
@@ -164,47 +187,57 @@ if [ "$answer" != "Y" -a "$answer" != "y" ]; then
164 exit 1 187 exit 1
165fi 188fi
166 189
190# create dir and don't care about the result.
167mkdir -p $target_sdk_dir >/dev/null 2>&1 191mkdir -p $target_sdk_dir >/dev/null 2>&1
168if [ $? -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 194if [ ! -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
171fi 204fi
172 205
173payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1)) 206payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1))
174 207
175printf "Extracting SDK..." 208printf "Extracting SDK..."
176tail -n +$payload_offset $0| tar xj --strip-components=$COMPONENTS_LEN -C $target_sdk_dir 209tail -n +$payload_offset $0| $SUDO_EXEC tar xj --strip-components=$COMPONENTS_LEN -C $target_sdk_dir
177echo "done" 210echo "done"
178 211
179printf "Setting it up..." 212printf "Setting it up..."
180# fix environment paths 213# fix environment paths
181for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do 214for 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
183done 216done
184 217
185# fix dynamic loader paths in all ELF SDK binaries 218# fix dynamic loader paths in all ELF SDK binaries
186native_sysroot=$(cat $env_setup_script |grep OECORE_NATIVE_SYSROOT|cut -d'=' -f2|tr -d '"') 219native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep OECORE_NATIVE_SYSROOT|cut -d'=' -f2|tr -d '"')
187dl_path=$(find $native_sysroot/lib -name "ld-linux*") 220dl_path=$($SUDO_EXEC find $native_sysroot/lib -name "ld-linux*")
188executable_files=$(find $native_sysroot -type f -perm +111) 221executable_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
190if [ $? -ne 0 ]; then 223if [ $? -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
193fi 226fi
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
196find $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}
199for l in $(find $native_sysroot -type l); do 232for 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
201done 234done
202 235
203echo done 236echo 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
207rm ${env_setup_script%/*}/relocate_sdk.py 240$SUDO_EXEC rm ${env_setup_script%/*}/relocate_sdk.py
208 241
209echo "SDK has been successfully set up and is ready to be used." 242echo "SDK has been successfully set up and is ready to be used."
210 243