aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChen Qi <Qi.Chen@windriver.com>2014-10-27 19:57:51 +0800
committerChen Qi <Qi.Chen@windriver.com>2014-10-27 20:14:16 +0800
commit48e14f7ea380f0e38c906fab7e9b4b4226f38ba6 (patch)
treeb69ccc0bbff7c2638b6deb3ce09dbda3fac451d5
parent4143f3b0ce0d0c52f5b0babc1bb16ac0ac9610eb (diff)
downloadopenembedded-core-contrib-ChenQi/SDK-installation.tar.gz
toolchain-shar-template.sh: fix installation of SDKChenQi/SDK-installation
Previously, the installation of our SDK is not consistent. For example, there's a user with user name 'test' and group name 'test', and the user has sudo privilege. First, the user tries to install the SDK to his own home directory /home/test, and the SDK files are installed with 'test' as their owner. Then, the user tries to install the SDK to /opt/ directory which is owned by root, and the SDK files are installed with 'root' as their owner. We can see from the above example the same SDK would result in different installation results only because the installation directories are different. In fact, in the second use case above, the user has to use the `sudo' command every time whenever he/she wants to perform some action with the SDK. This patch fixes the above problems by installing the SDK with the current user as the owner of the installed files. Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
-rw-r--r--meta/files/toolchain-shar-template.sh31
1 files changed, 20 insertions, 11 deletions
diff --git a/meta/files/toolchain-shar-template.sh b/meta/files/toolchain-shar-template.sh
index 02035d4539..592795c5e8 100644
--- a/meta/files/toolchain-shar-template.sh
+++ b/meta/files/toolchain-shar-template.sh
@@ -94,24 +94,33 @@ if [ "$answer" != "Y" -a "$answer" != "y" ]; then
exit 1
fi
-# Try to create the directory (this will not succeed if user doesn't have rights)
+# Create directory under current user/group
+USERID=`id -u`
+GROUPID=`id -g`
mkdir -p $target_sdk_dir >/dev/null 2>&1
-
-# if don't have the right to access dir, gain by sudo
-if [ ! -x $target_sdk_dir -o ! -w $target_sdk_dir -o ! -r $target_sdk_dir ]; then
+if [ ! -x $target_sdk_dir -o ! -w $target_sdk_dir -o ! -r $target_sdk_dir ]; then
SUDO_EXEC=$(which "sudo")
if [ -z $SUDO_EXEC ]; then
- echo "No command 'sudo' found, please install sudo first. Abort!"
+ echo "Error: Creating $target_sdk_dir needs sudo privilege, please install sudo or change your installation location. Abort!"
exit 1
fi
-
- # test sudo could gain root right
+ # make sure sudo could gain root privilege
$SUDO_EXEC pwd >/dev/null 2>&1
- [ $? -ne 0 ] && echo "Sorry, you are not allowed to execute as root." && exit 1
-
- # now that we have sudo rights, create the directory
- $SUDO_EXEC mkdir -p $target_sdk_dir >/dev/null 2>&1
+ [ $? -ne 0 ] && echo "Error: Creating $target_sdk_dir failed. Please make sure you have sudo privilege." && exit 1
+ # create directory and change its owner and group
+ $SUDO_EXEC mkdir -p $target_sdk_dir
+ $SUDO_EXEC chown ${USERID}:${GROUPID} $target_sdk_dir
fi
+# Make sure the created directory has the same UID/GID as the current user
+FUID=`stat -c '%u' $target_sdk_dir`
+FGID=`stat -c '%g' $target_sdk_dir`
+if [ $USERID != $FUID -o $GROUPID != $FGID ]; then
+ echo "Error: $target_sdk_dir doesn't have the corret UID/GID. Abort!"
+ exit 1
+fi
+
+# From now on, we don't need to use sudo anymore
+SUDO_EXEC=""
payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1))