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-03 12:35:53 +0000 |
commit | c5ffdcbe371014bde25f0ab3955d502fa854c1dc (patch) | |
tree | abc2a7cb8d876f8d526472435dd8248b24375265 | |
parent | 154432841fc576da33606b75cc2790a6e9ab9d0a (diff) | |
download | poky-c5ffdcbe371014bde25f0ab3955d502fa854c1dc.tar.gz |
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>
-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 @@ | |||
22 | # with this program; if not, write to the Free Software Foundation, Inc., | 22 | # with this program; if not, write to the Free Software Foundation, Inc., |
23 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 23 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
24 | 24 | ||
25 | uid=`id -u` | ||
26 | gid=`id -g` | ||
27 | if [ -n "$SUDO_UID" ]; then | ||
28 | uid=$SUDO_UID | ||
29 | fi | ||
30 | if [ -n "$SUDO_GID" ]; then | ||
31 | gid=$SUDO_GID | ||
32 | fi | ||
33 | |||
25 | usage() { | 34 | usage() { |
26 | echo "Usage: sudo $0 <uid> <gid> <num> <staging_bindir_native>" | 35 | echo "Usage: sudo $0 <uid> <gid> <num> <staging_bindir_native>" |
27 | echo "Where <uid> is the numeric user id the tap devices will be owned by" | 36 | echo "Where <uid> is the numeric user id the tap devices will be owned by" |
28 | echo "Where <gid> is the numeric group id the tap devices will be owned by" | 37 | echo "Where <gid> is the numeric group id the tap devices will be owned by" |
29 | echo "<num> is the number of tap devices to create (0 to remove all)" | 38 | echo "<num> is the number of tap devices to create (0 to remove all)" |
30 | echo "<native-sysroot-basedir> is the path to the build system's native sysroot" | 39 | echo "<native-sysroot-basedir> is the path to the build system's native sysroot" |
31 | echo "e.g. $ bitbake qemu-helper-native" | 40 | echo "For example:" |
32 | echo "$ sudo $0 1000 1000 4 tmp/sysroots-components/x86_64/qemu-helper-native/usr/bin" | 41 | echo "$ bitbake qemu-helper-native" |
42 | echo "$ sudo $0 $uid $gid 4 tmp/sysroots-components/x86_64/qemu-helper-native/usr/bin" | ||
43 | echo "" | ||
33 | exit 1 | 44 | exit 1 |
34 | } | 45 | } |
35 | 46 | ||
36 | if [ $EUID -ne 0 ]; then | ||
37 | echo "Error: This script must be run with root privileges" | ||
38 | exit | ||
39 | fi | ||
40 | |||
41 | if [ $# -ne 4 ]; then | 47 | if [ $# -ne 4 ]; then |
42 | echo "Error: Incorrect number of arguments" | 48 | echo "Error: Incorrect number of arguments" |
43 | usage | 49 | usage |
@@ -54,6 +60,11 @@ if [[ ! -x "$TUNCTL" || -d "$TUNCTL" ]]; then | |||
54 | usage | 60 | usage |
55 | fi | 61 | fi |
56 | 62 | ||
63 | if [ $EUID -ne 0 ]; then | ||
64 | echo "Error: This script must be run with root privileges" | ||
65 | exit | ||
66 | fi | ||
67 | |||
57 | SCRIPT_DIR=`dirname $0` | 68 | SCRIPT_DIR=`dirname $0` |
58 | RUNQEMU_IFUP="$SCRIPT_DIR/runqemu-ifup" | 69 | RUNQEMU_IFUP="$SCRIPT_DIR/runqemu-ifup" |
59 | if [ ! -x "$RUNQEMU_IFUP" ]; then | 70 | if [ ! -x "$RUNQEMU_IFUP" ]; then |