From d9c0a1c1973149bb7f6e20fd4cc2ecb187331c79 Mon Sep 17 00:00:00 2001 From: Munkyu Im Date: Thu, 9 Apr 2015 15:45:24 +0900 Subject: [PATCH] net: Support bridged network automation on ubuntu and modify on macosx Added sudo commands to launcher script and rules on /etc/sudoers Modified launcher script name to os-specific name. Integratied install script not to input password several times Change-Id: I2cf709e25c919f951bb5c34a7e6cadd0e04655da Signed-off-by: Munkyu Im --- include/net/tap.h | 3 + net/tap-linux.c | 94 ++++++++++++++++- net/tap.c | 17 ++- package/emulator-qemu-common.install.macos-64 | 104 ------------------- package/emulator-qemu-x86.install.macos-64 | 114 +++++++++++++++++++++ package/emulator-qemu-x86.install.ubuntu-32 | 87 ++++++++++++++-- package/emulator-qemu-x86.install.ubuntu-64 | 87 ++++++++++++++-- tizen/src/Makefile | 9 +- .../{emulator-ifup.sh => emulator-ifup-darwin.sh} | 0 tizen/src/scripts/emulator-ifup-linux.sh | 37 +++++++ 10 files changed, 414 insertions(+), 138 deletions(-) delete mode 100755 package/emulator-qemu-common.install.macos-64 create mode 100755 package/emulator-qemu-x86.install.macos-64 rename tizen/src/scripts/{emulator-ifup.sh => emulator-ifup-darwin.sh} (100%) create mode 100755 tizen/src/scripts/emulator-ifup-linux.sh diff --git a/include/net/tap.h b/include/net/tap.h index 6daeb42..cf7021a 100644 --- a/include/net/tap.h +++ b/include/net/tap.h @@ -28,6 +28,9 @@ #include "qemu-common.h" #include "qapi-types.h" +#if defined(CONFIG_MARU) +#include "tizen/src/emul_state.h" +#endif int tap_enable(NetClientState *nc); int tap_disable(NetClientState *nc); diff --git a/net/tap-linux.c b/net/tap-linux.c index 812bf2d..f960781 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -36,6 +36,80 @@ #define PATH_NET_TUN "/dev/net/tun" +#if defined(CONFIG_MARU) +static int launch_openvpn(bool ismake, const char *ifname) +{ + int pid, status; + const char* args[] = { + "/usr/bin/sudo", + "/usr/sbin/openvpn", + "--mktun", + "--dev", + ifname, + NULL + }; + if (ismake) { + fprintf(stdout, "launch_openvpn make tap: %s\n", ifname); + } else { + fprintf(stdout, "launch_openvpn remove tap: %s\n", ifname); + args[2] = "--rmtun"; + } + /* try to launch network script */ + pid = fork(); + if (pid == 0) { + execv(args[0], (char**)args); + _exit(1); + } else if (pid > 0) { + while (waitpid(pid, &status, 0) != pid) { + /* loop */ + } + + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { + return 0; + } + } + fprintf(stderr, "Could not launch openvpn\n"); + return -1; +} + +static int tap_cleanup(void) +{ + int fd, ret; + struct ifreq ifr; + char dname[100]; + int port = get_emul_vm_base_port() + 10; + + TFR(fd = open(PATH_NET_TUN, O_RDWR)); + if (fd < 0) { + error_report("could not open %s: %m", PATH_NET_TUN); + return -1; + } + memset(&ifr, 0, sizeof(ifr)); + ifr.ifr_flags = IFF_TAP | IFF_NO_PI; + + for ( ; port < 26200; port += 10) { + snprintf(dname, sizeof(dname), "tap%d", port); + pstrcpy(ifr.ifr_name, IFNAMSIZ, dname); + ret = ioctl(fd, TUNSETIFF, (void *) &ifr); + if (ret == 0) { + close(fd); + if (launch_openvpn(false, dname)) { + fprintf(stderr, "Failed to remove %s device. It can be used on the other emulator\n", dname); + } + TFR(fd = open(PATH_NET_TUN, O_RDWR)); + if (fd < 0) { + error_report("could not open %s: %m", PATH_NET_TUN); + return -1; + } + } else { + close(fd); + } + } + return 0; +} + +#endif + int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required, int mq_required) { @@ -43,7 +117,11 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int fd, ret; int len = sizeof(struct virtio_net_hdr); unsigned int features; - +#if defined(CONFIG_MARU) + if (tap_cleanup() < 0) { + return -1; + } +#endif TFR(fd = open(PATH_NET_TUN, O_RDWR)); if (fd < 0) { error_report("could not open %s: %m", PATH_NET_TUN); @@ -97,8 +175,20 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, if (ifname[0] != '\0') pstrcpy(ifr.ifr_name, IFNAMSIZ, ifname); - else + else { +#if defined(CONFIG_MARU) + /* Create tap */ + char dname[100]; + snprintf(dname, sizeof dname, "tap%d", get_emul_vm_base_port()); + if (launch_openvpn(true, dname)) { + close(fd); + return -1; + } + pstrcpy(ifr.ifr_name, IFNAMSIZ, dname); +#else pstrcpy(ifr.ifr_name, IFNAMSIZ, "tap%d"); +#endif + } ret = ioctl(fd, TUNSETIFF, (void *) &ifr); if (ret != 0) { if (ifname[0] != '\0') { diff --git a/net/tap.c b/net/tap.c index 3ad61df..f200476 100644 --- a/net/tap.c +++ b/net/tap.c @@ -362,10 +362,9 @@ static TAPState *net_tap_fd_init(NetClientState *peer, static int launch_script(const char *setup_script, const char *ifname, int fd) { int pid, status; -#if defined(CONFIG_DARWIN) && defined(CONFIG_MARU) - char *args[5]; - const gchar* cocoasudo_path = g_strdup_printf("%scocoasudo", get_bin_path()); - const char* message = "--prompt=Emulator needs privileged mode to setup bridged network."; +#if !defined(CONFIG_WIN32) && defined(CONFIG_MARU) + char *args[4]; + const char* sudo_path = "/usr/bin/sudo"; #else char *args[3]; #endif @@ -382,15 +381,15 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) } } parg = args; -#if defined(CONFIG_DARWIN) && defined(CONFIG_MARU) - *parg++ = (char *)cocoasudo_path; - *parg++ = (char *)message; +#if !defined(CONFIG_WIN32) && defined(CONFIG_MARU) + *parg++ = (char *)sudo_path; #endif *parg++ = (char *)setup_script; *parg++ = (char *)ifname; *parg = NULL; -#if defined(CONFIG_DARWIN) && defined(CONFIG_MARU) - execv(cocoasudo_path, args); + +#if !defined(CONFIG_WIN32) && defined(CONFIG_MARU) + execv(sudo_path, args); #else execv(setup_script, args); #endif diff --git a/package/emulator-qemu-common.install.macos-64 b/package/emulator-qemu-common.install.macos-64 deleted file mode 100755 index dea8b06..0000000 --- a/package/emulator-qemu-common.install.macos-64 +++ /dev/null @@ -1,104 +0,0 @@ -#!/bin/sh -e - -TIZEN_SDK_INSTALL_PATH=`echo $INSTALLED_PATH` -OLD_SHMMAXSIZE=`sysctl -n kern.sysv.shmmax` -SYSCTL_FILE=sysctl.conf -TMP_DIR=~/.installmanager -TIZEN_BIN_PATH=$TIZEN_SDK_INSTALL_PATH/tools/emulator/bin -TMP_FILE=$TMP_DIR/setshmmax.sh -TMP_INSTALL_TAP_FILE=$TMP_DIR/install-tap.sh -NEW_SHMMAXSIZE=83886080 -if [ -z $TIZEN_SDK_INSTALL_PATH ] -then - echo "There is no TIZEN_SDK_PATH ENV" >> /tmp/emulator.log -# exit 2; -fi - -function install_tap { - echo 'make new install-tap.sh file' - - if [ ! -d $TMP_DIR ] - then - mkdir $TMP_DIR - fi - cat << 'EOF' >> $TMP_INSTALL_TAP_FILE -#!/bin/sh -mkdir -p /Library/Extensions -cp -pR tap.kext /Library/Extensions/ -chown -R root:wheel /Library/Extensions/tap.kext -mkdir -p /Library/LaunchDaemons -cp /Library/Extensions/tap.kext/Contents/net.sf.tuntaposx.tap.plist /Library/LaunchDaemons -/sbin/kextload /Library/Extensions/tap.kext -EOF - /bin/chmod +x $TMP_INSTALL_TAP_FILE - echo 'launch install-tap.sh' - $TIZEN_BIN_PATH/cocoasudo "--prompt=Installing tun/tap driver requires that you type your password." sh -x $TMP_INSTALL_TAP_FILE - rm -f $TMP_INSTALL_TAP_FILE -} - -function remove_tmp_file { - if [ -e $TMP_FILE ] - then - echo 'delete ~/tmp/setshmmax.sh' - rm -f $TMP_FILE - fi -} - -function remove_sysctl_file { - if [ -e $TMP_DIR/$SYSCTL_FILE ] - then - echo 'delete ~/tmp/sysctl.conf' - rm -f $TMP_DIR/$SYSCTL_FILE - fi -} - -function makesysctl { - echo 'make new sysctl.conf file to change' - - if [ ! -d $TMP_DIR ] - then - mkdir $TMP_DIR - fi - - remove_sysctl_file; - - echo "kern.sysv.shmmax=83886080" >> $TMP_DIR/$SYSCTL_FILE - echo "kern.sysv.shmmin=1" >> $TMP_DIR/$SYSCTL_FILE - echo "kern.sysv.shmmni=128" >> $TMP_DIR/$SYSCTL_FILE - echo "kern.sysv.shmseg=32" >> $TMP_DIR/$SYSCTL_FILE - echo "kern.sysv.shmall=20480" >> $TMP_DIR/$SYSCTL_FILE - -} - -if [ $OLD_SHMMAXSIZE -lt $NEW_SHMMAXSIZE ] -then - if [ -e /etc/$SYSCTL_FILE ] - then - remove_tmp_file; - makesysctl; - echo "mv -f /etc/sysctl.conf /etc/sysctl.conf.old" >> $TMP_FILE - echo "cp -f $TMP_DIR/$SYSCTL_FILE /etc/." >> $TMP_FILE - echo "sysctl -w kern.sysv.shmmax=$NEW_SHMMAXSIZE" >> $TMP_FILE - chmod +x $TMP_FILE - $TIZEN_BIN_PATH/cocoasudo "--prompt=Changing /etc/sysctl.conf file requires that you type your password.(The original file will be removed to sysctl.conf.old)" sh -x $TMP_FILE - else - remove_tmp_file; - makesysctl; - echo "cp -f $TMP_DIR/$SYSCTL_FILE /etc/." >> $TMP_FILE - echo "sysctl -w kern.sysv.shmmax=$NEW_SHMMAXSIZE" >> $TMP_FILE - chmod +x $TMP_FILE - $TIZEN_BIN_PATH/cocoasudo "--prompt=Make a new /etc/sysctl.conf file requires that you type your password." sh -x $TMP_FILE - fi -fi - -remove_tmp_file; -remove_sysctl_file; -install_tap; -CURRENT_SHMMAXSIZE=`sysctl -n kern.sysv.shmmax` - -if [ ! $OLD_SHMMAXSIZE -eq $CURRENT_SHMMAXSIZE ] -then - echo 'need reboot' - exit 99 -fi - diff --git a/package/emulator-qemu-x86.install.macos-64 b/package/emulator-qemu-x86.install.macos-64 new file mode 100755 index 0000000..13bb342 --- /dev/null +++ b/package/emulator-qemu-x86.install.macos-64 @@ -0,0 +1,114 @@ +#!/bin/sh -e + +TIZEN_SDK_INSTALL_PATH=`echo $INSTALLED_PATH` +OLD_SHMMAXSIZE=`sysctl -n kern.sysv.shmmax` +COCOASUDOPATH="./cocoasudo" +SYSCTL_FILE=sysctl.conf +TMP_DIR=~/.installmanager +TIZEN_BIN_PATH=$TIZEN_SDK_INSTALL_PATH/tools/emulator/bin +TIZEN_ETC_PATH=$TIZEN_SDK_INSTALL_PATH/tools/emulator/etc + +TMP_FILE=$TMP_DIR/emulator-install.sh +NEW_SHMMAXSIZE=83886080 + +if [ -z $TIZEN_SDK_INSTALL_PATH ] +then + echo "There is no TIZEN_SDK_PATH ENV" >> /tmp/emulator.log +# exit 2; +fi + +function remove_tmp_file { + if [ -e $TMP_FILE ] + then + echo "delete $TMP_FILE" + rm -f $TMP_FILE + fi +} + +function remove_sysctl_file { + if [ -e $TMP_DIR/$SYSCTL_FILE ] + then + echo "delete $TMP_DIR/$SYSCTL_FILE" + rm -f $TMP_DIR/$SYSCTL_FILE + fi +} + +function makesysctl { + echo 'make new sysctl.conf file to change' + + remove_sysctl_file; + + echo "kern.sysv.shmmax=83886080" >> $TMP_DIR/$SYSCTL_FILE + echo "kern.sysv.shmmin=1" >> $TMP_DIR/$SYSCTL_FILE + echo "kern.sysv.shmmni=128" >> $TMP_DIR/$SYSCTL_FILE + echo "kern.sysv.shmseg=32" >> $TMP_DIR/$SYSCTL_FILE + echo "kern.sysv.shmall=20480" >> $TMP_DIR/$SYSCTL_FILE + +} + +function generate_tap_kext_cmd { + echo "mkdir -p /Library/Extensions" >> $TMP_FILE + echo "cp -pR ${TIZEN_ETC_PATH}/tap.kext /Library/Extensions" >> $TMP_FILE + echo "chown -R root:wheel /Library/Extensions/tap.kext" >> $TMP_FILE + echo "mkdir -p /Library/LaunchDaemons" >> $TMP_FILE + echo "cp /Library/Extensions/tap.kext/Contents/net.sf.tuntaposx.tap.plist /Library/LaunchDaemons" >> $TMP_FILE + echo "/sbin/kextload /Library/Extensions/tap.kext" >> $TMP_FILE +} + +function generate_sysctl_cmd { + if [ $OLD_SHMMAXSIZE -lt $NEW_SHMMAXSIZE ] + then + if [ -e /etc/$SYSCTL_FILE ] + then + makesysctl; + echo "mv -f /etc/sysctl.conf /etc/sysctl.conf.old" >> $TMP_FILE + echo "cp -f $TMP_DIR/$SYSCTL_FILE /etc/." >> $TMP_FILE + echo "sysctl -w kern.sysv.shmmax=$NEW_SHMMAXSIZE" >> $TMP_FILE + echo 'echo "Changing /etc/sysctl.conf file. (The original file will be removed to sysctl.conf.old)"' >> $TMP_FILE + else + makesysctl; + echo "cp -f $TMP_DIR/$SYSCTL_FILE /etc/." >> $TMP_FILE + echo "sysctl -w kern.sysv.shmmax=$NEW_SHMMAXSIZE" >> $TMP_FILE + echo 'echo "Make a new /etc/sysctl.conf file."' >> $TMP_FILE + fi + fi +} + +function prepare { + if [ ! -d $TMP_DIR ] + then + echo "make temp directory for emulator install : ( $TMP_DIR )" + mkdir $TMP_DIR + fi + echo "create $TMP_FILE" + echo "#!/bin/sh" > $TMP_FILE +} + +function generate { + generate_sysctl_cmd; + generate_tap_kext_cmd; +} + +function execute { + /bin/chmod +x $TMP_FILE + $TIZEN_BIN_PATH/cocoasudo "--prompt=Please enter your password to install tizen emulator." sh -x $TMP_FILE +} + +function cleanup { + remove_tmp_file; + remove_sysctl_file; +} + +prepare; +generate; +execute; +cleanup; + +CURRENT_SHMMAXSIZE=`sysctl -n kern.sysv.shmmax` + +if [ ! $OLD_SHMMAXSIZE -eq $CURRENT_SHMMAXSIZE ] +then + echo 'need reboot' + exit 99 +fi + diff --git a/package/emulator-qemu-x86.install.ubuntu-32 b/package/emulator-qemu-x86.install.ubuntu-32 index 15eb412..e5342eb 100755 --- a/package/emulator-qemu-x86.install.ubuntu-32 +++ b/package/emulator-qemu-x86.install.ubuntu-32 @@ -29,30 +29,95 @@ if [ ! -z "${OS_NAME}" ]; then fi echo "Linux Distribution: ${OS_NAME}" -TMP_FILE=init_tizen-kvm.sh -echo "#!/bin/bash -ex" >> ${TMP_FILE} -echo "cp ${TIZEN_SDK_INSTALL_PATH}/tools/emulator/etc/tizen-kvm /etc/init.d/" >> ${TMP_FILE} -echo "cp ${TIZEN_SDK_INSTALL_PATH}/tools/emulator/etc/45-tizen-kvm.rules /lib/udev/rules.d/" >> ${TMP_FILE} -echo "/etc/init.d/tizen-kvm start" >> ${TMP_FILE} +# need sudo to enable kvm module and set qemu sudoers +TMP_FILE=init_tizen.sh +cat << 'EOF' >> $TMP_FILE +#!/bin/bash -x +TIZEN_SDK_INSTALL_PATH=`echo ${INSTALLED_PATH}` +cp ${TIZEN_SDK_INSTALL_PATH}/tools/emulator/etc/tizen-kvm /etc/init.d/ +cp ${TIZEN_SDK_INSTALL_PATH}/tools/emulator/etc/45-tizen-kvm.rules /lib/udev/rules.d/ +/etc/init.d/tizen-kvm start if [ "ubuntu" = "${OS_NAME}" ] ; then - echo "update-rc.d tizen-kvm defaults" >> ${TMP_FILE} + update-rc.d tizen-kvm defaults fi -chmod +x ${TMP_FILE} +cp -f ${TIZEN_SDK_INSTALL_PATH}/tools/emulator/etc/emulator-ifup.sh /etc/ +FILE=/etc/sudoers +BACKFILE=/etc/sudoers.bak +TMPFILE=/etc/sudoers.tmp +MESSAGE="# Tizen SDK generated the following script. Do not modify." +LINE1="User_Alias QEMUERS=" +LINE2="Cmnd_Alias QEMU=/etc/emulator-ifup.sh, /etc/emulator-ifdown.sh, /usr/sbin/openvpn" +LINE3="QEMUERS ALL=(ALL) NOPASSWD: QEMU" +if [[ "$2"x == ""x ]] +then + USER=$1 +else + USER=$2 +fi +count=0 +if [[ "$USER" == "" ]] +then + echo "user is not set. aborting..." + exit 1 +fi + +while read line +do + echo $line + count=$((count+1)) + if [[ $line == $LINE1* ]] + then + echo "find original script" + NAMES=`echo $line | cut -d = -f2` + if [[ "$NAMES"x == ""x ]] + then + cp $FILE $BACKFILE + # in case of blank user + eval sed -e "$count"c\"$line $USER\" $FILE > $TMPFILE + exit 0 + fi + for i in $(echo $NAMES | tr "," "\n") + do + if [[ "$i" == "$USER" ]] + then + echo "already added the same user" + exit 0 + fi + done + cp $FILE $BACKFILE + # new user is added with comma behind the original users. + eval sed -e "$count"c\"$line, $USER\" $FILE > $TMPFILE + mv $TMPFILE $FILE + exit 0 + fi +done < $FILE + +cp $FILE $BACKFILE +echo "do not find $line" +echo "$MESSAGE" >> $FILE +echo "$LINE1$USER" >> $FILE +echo "$LINE2" >> $FILE +echo "$LINE3" >> $FILE +exit 0 +EOF + +chmod +x ${TMP_FILE} +USER=`id -un` if [ "${TSUDO}" != "" ] # since installer v2.27 then - TSUDO_MSG="Enter your password to enable kvm module if your machine supports hardware virtualization." + TSUDO_MSG="Enter your password to install Tizen Emulator" TMP_PATH="`pwd`/${TMP_FILE}" - ${TSUDO} -m "${TSUDO_MSG}" sh ${TMP_PATH} + ${TSUDO} -m "${TSUDO_MSG}" sh ${TMP_PATH} ${USER} else GKSUDO=`which gksudo` if [ "${GKSUDO}" = "" ] then echo "there is no gksudo." - sudo ./${TMP_FILE} + sudo ./${TMP_FILE} ${USER} else - gksudo ./${TMP_FILE} + gksudo ./${TMP_FILE} ${USER} fi fi diff --git a/package/emulator-qemu-x86.install.ubuntu-64 b/package/emulator-qemu-x86.install.ubuntu-64 index 15eb412..e5342eb 100755 --- a/package/emulator-qemu-x86.install.ubuntu-64 +++ b/package/emulator-qemu-x86.install.ubuntu-64 @@ -29,30 +29,95 @@ if [ ! -z "${OS_NAME}" ]; then fi echo "Linux Distribution: ${OS_NAME}" -TMP_FILE=init_tizen-kvm.sh -echo "#!/bin/bash -ex" >> ${TMP_FILE} -echo "cp ${TIZEN_SDK_INSTALL_PATH}/tools/emulator/etc/tizen-kvm /etc/init.d/" >> ${TMP_FILE} -echo "cp ${TIZEN_SDK_INSTALL_PATH}/tools/emulator/etc/45-tizen-kvm.rules /lib/udev/rules.d/" >> ${TMP_FILE} -echo "/etc/init.d/tizen-kvm start" >> ${TMP_FILE} +# need sudo to enable kvm module and set qemu sudoers +TMP_FILE=init_tizen.sh +cat << 'EOF' >> $TMP_FILE +#!/bin/bash -x +TIZEN_SDK_INSTALL_PATH=`echo ${INSTALLED_PATH}` +cp ${TIZEN_SDK_INSTALL_PATH}/tools/emulator/etc/tizen-kvm /etc/init.d/ +cp ${TIZEN_SDK_INSTALL_PATH}/tools/emulator/etc/45-tizen-kvm.rules /lib/udev/rules.d/ +/etc/init.d/tizen-kvm start if [ "ubuntu" = "${OS_NAME}" ] ; then - echo "update-rc.d tizen-kvm defaults" >> ${TMP_FILE} + update-rc.d tizen-kvm defaults fi -chmod +x ${TMP_FILE} +cp -f ${TIZEN_SDK_INSTALL_PATH}/tools/emulator/etc/emulator-ifup.sh /etc/ +FILE=/etc/sudoers +BACKFILE=/etc/sudoers.bak +TMPFILE=/etc/sudoers.tmp +MESSAGE="# Tizen SDK generated the following script. Do not modify." +LINE1="User_Alias QEMUERS=" +LINE2="Cmnd_Alias QEMU=/etc/emulator-ifup.sh, /etc/emulator-ifdown.sh, /usr/sbin/openvpn" +LINE3="QEMUERS ALL=(ALL) NOPASSWD: QEMU" +if [[ "$2"x == ""x ]] +then + USER=$1 +else + USER=$2 +fi +count=0 +if [[ "$USER" == "" ]] +then + echo "user is not set. aborting..." + exit 1 +fi + +while read line +do + echo $line + count=$((count+1)) + if [[ $line == $LINE1* ]] + then + echo "find original script" + NAMES=`echo $line | cut -d = -f2` + if [[ "$NAMES"x == ""x ]] + then + cp $FILE $BACKFILE + # in case of blank user + eval sed -e "$count"c\"$line $USER\" $FILE > $TMPFILE + exit 0 + fi + for i in $(echo $NAMES | tr "," "\n") + do + if [[ "$i" == "$USER" ]] + then + echo "already added the same user" + exit 0 + fi + done + cp $FILE $BACKFILE + # new user is added with comma behind the original users. + eval sed -e "$count"c\"$line, $USER\" $FILE > $TMPFILE + mv $TMPFILE $FILE + exit 0 + fi +done < $FILE + +cp $FILE $BACKFILE +echo "do not find $line" +echo "$MESSAGE" >> $FILE +echo "$LINE1$USER" >> $FILE +echo "$LINE2" >> $FILE +echo "$LINE3" >> $FILE +exit 0 +EOF + +chmod +x ${TMP_FILE} +USER=`id -un` if [ "${TSUDO}" != "" ] # since installer v2.27 then - TSUDO_MSG="Enter your password to enable kvm module if your machine supports hardware virtualization." + TSUDO_MSG="Enter your password to install Tizen Emulator" TMP_PATH="`pwd`/${TMP_FILE}" - ${TSUDO} -m "${TSUDO_MSG}" sh ${TMP_PATH} + ${TSUDO} -m "${TSUDO_MSG}" sh ${TMP_PATH} ${USER} else GKSUDO=`which gksudo` if [ "${GKSUDO}" = "" ] then echo "there is no gksudo." - sudo ./${TMP_FILE} + sudo ./${TMP_FILE} ${USER} else - gksudo ./${TMP_FILE} + gksudo ./${TMP_FILE} ${USER} fi fi diff --git a/tizen/src/Makefile b/tizen/src/Makefile index 2a8a7d3..5e20572 100755 --- a/tizen/src/Makefile +++ b/tizen/src/Makefile @@ -205,7 +205,14 @@ endif # give a title name for sdb terminal. ifdef CONFIG_DARWIN cp -pP scripts/sdbscript $(EMUL_DIR)/bin - cp -pP scripts/emulator-ifup.sh $(EMUL_DIR)/bin +endif + +# for bridged network +ifdef CONFIG_LINUX + cp -pP scripts/emulator-ifup-linux.sh $(EMUL_DIR)/etc/emulator-ifup.sh +endif +ifdef CONFIG_DARWIN + cp -pP scripts/emulator-ifup-darwin.sh $(EMUL_DIR)/etc/emulator-ifup.sh endif # use shared memory for display framebuffer diff --git a/tizen/src/scripts/emulator-ifup.sh b/tizen/src/scripts/emulator-ifup-darwin.sh similarity index 100% rename from tizen/src/scripts/emulator-ifup.sh rename to tizen/src/scripts/emulator-ifup-darwin.sh diff --git a/tizen/src/scripts/emulator-ifup-linux.sh b/tizen/src/scripts/emulator-ifup-linux.sh new file mode 100755 index 0000000..3e059ff --- /dev/null +++ b/tizen/src/scripts/emulator-ifup-linux.sh @@ -0,0 +1,37 @@ +#!/bin/sh +x + +BASEIF=eth0 +NETMASK=`ifconfig $BASE | grep "inet " | awk '{print $4}' | cut -d : -f2` +GW=`netstat -rn | grep ^0.0.0.0 | awk '{print $2}'` +BR=br-tizen-vm-1 + +# Check if bridge interface exists. +CHECK_BR=`ifconfig $BR` +if [ "$CHECK_BR" = "" ] +then + BASEIPADDR=`ip addr show eth0 | awk '/inet / {print $2}' | cut -d/ -f1` + brctl addbr $BR +else + BASEIPADDR=`ip addr show $BR | awk '/inet / {print $2}' | cut -d/ -f1` +fi + +# ifconfig up tap device. +ifconfig $1 0.0.0.0 promisc up + +# Take interface down. +ifdown $BASEIF +ifconfig $BASEIF 0.0.0.0 promisc up + +# Add tap device and interface to bridge. +brctl addif $BR $BASEIF +brctl addif $BR $1 + +# Add the default route. +ifconfig $BR $BASEIPADDR netmask $NETMASK + +NET=`netstat -rn | grep ^0.0.0.0 | awk '{print $8}'` +if [ "$NET" != "$BR" ] +then + route add default gw $GW +fi +exit 0 -- 2.7.4