diff options
author | Robert Yang <liezhi.yang@windriver.com> | 2018-12-28 00:58:58 -0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-01-28 16:56:31 +0000 |
commit | 79471a27018d2e766b349540693e6c196fa75869 (patch) | |
tree | ed8778dec7014740b1b7d02aa9e068d1e2797f5f | |
parent | 4b5a4b718c027f54ef0660a731f11a9d249b4af8 (diff) | |
download | openembedded-core-79471a27018d2e766b349540693e6c196fa75869.tar.gz openembedded-core-79471a27018d2e766b349540693e6c196fa75869.tar.bz2 openembedded-core-79471a27018d2e766b349540693e6c196fa75869.zip |
runqemu-gen-tapdevs: Allow run --help without sudo
Then we can get user's UID and GID rather than hardcode to 1000, e.g.:
- Without sudo
$ runqemu-gen-tapdevs --help
[snip]
$ sudo ../poky/scripts/runqemu-gen-tapdevs 15220 100 4 tmp/sysroots-components/x86_64/qemu-helper-native/usr/bin
[snip]
- With sudo
$ sudo ../poky/scripts/runqemu-gen-tapdevs --help
[snip]
$ sudo ../poky/scripts/runqemu-gen-tapdevs 15220 100 4 tmp/sysroots-components/x86_64/qemu-helper-native/usr/bin
[snip]
(From OE-Core rev: 446e7da7e56f9de3602498b5ef40e9e0f8f71837)
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Armin Kuster <akuster808@gmail.com>
-rwxr-xr-x | scripts/runqemu-gen-tapdevs | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/scripts/runqemu-gen-tapdevs b/scripts/runqemu-gen-tapdevs index 11de318c1a..869fee261d 100755 --- a/scripts/runqemu-gen-tapdevs +++ b/scripts/runqemu-gen-tapdevs @@ -22,22 +22,28 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +uid=`id -u` +gid=`id -g` +if [ -n "$SUDO_UID" ]; then + uid=$SUDO_UID +fi +if [ -n "$SUDO_GID" ]; then + gid=$SUDO_GID +fi + usage() { echo "Usage: sudo $0 <uid> <gid> <num> <staging_bindir_native>" - echo "Where <uid> is the numeric user id the tap devices will be owned by" + echo "Where <uid> is the numeric user id the tap devices will be owned by" echo "Where <gid> is the numeric group id the tap devices will be owned by" echo "<num> is the number of tap devices to create (0 to remove all)" echo "<native-sysroot-basedir> is the path to the build system's native sysroot" - echo "e.g. $ bitbake qemu-helper-native" - echo "$ sudo $0 1000 1000 4 tmp/sysroots-components/x86_64/qemu-helper-native/usr/bin" + echo "For example:" + echo "$ bitbake qemu-helper-native" + echo "$ sudo $0 $uid $gid 4 tmp/sysroots-components/x86_64/qemu-helper-native/usr/bin" + echo "" exit 1 } -if [ $EUID -ne 0 ]; then - echo "Error: This script must be run with root privileges" - exit -fi - if [ $# -ne 4 ]; then echo "Error: Incorrect number of arguments" usage @@ -54,6 +60,11 @@ if [[ ! -x "$TUNCTL" || -d "$TUNCTL" ]]; then usage fi +if [ $EUID -ne 0 ]; then + echo "Error: This script must be run with root privileges" + exit +fi + SCRIPT_DIR=`dirname $0` RUNQEMU_IFUP="$SCRIPT_DIR/runqemu-ifup" if [ ! -x "$RUNQEMU_IFUP" ]; then |