-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathemulator
More file actions
executable file
·682 lines (576 loc) · 20.7 KB
/
emulator
File metadata and controls
executable file
·682 lines (576 loc) · 20.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
#!/bin/bash
SCRIPT_VERSION=1.0.0
SCRIPT_PATH=$( cd "$(dirname "$0")" ; pwd -P )
#echo $SCRIPT_PATH
#Not use ose build environment
unset TOPDIR
unset BUILDDIR
function log {
local msg=$1
# echo "Log message: $msg" >&2
}
function printWarning {
YELLOW='\033[1;33m'
NC='\033[0m'
printf "${YELLOW}$1${NC}\n"
}
function printError {
RED='\033[0;31m'
NC='\033[0m'
printf "${RED}$1${NC}\n"
}
function echoLightBlue {
BLUE='\033[1;34m'
NC='\033[0m'
printf "${BLUE}$1${NC}"
}
function printHelp {
echo "========================================="
echo "Usage: emulator [CONFIGURATION_JSON_FILE]"
echo "Reference the README file for Configuration JSON file options."
echo
echo "Mandatory arguments to long options are mandatory for short options too."
echo "-h, -help display this help and exit"
echo "-v, -version output version information and exit"
}
function bridge_up {
eth_option=$(ls /sys/class/net/)
for i in $eth_option;
do
if [ "${i:0:1}" == "e" ]
then
var_eth="$i"
break
fi
done
echo $var_eth
echoLightBlue "bridge_utils and uml-utilities must be installed to start emulator with Bridge support."
echo ""
sudo apt-get install bridge-utils
echo ""
sudo apt-get install uml-utilities
echo ""
sudo tunctl -t $var_eth
ip tuntap add dev $var_eth mode tap
ip link ls dev $var_eth
echoLightBlue "Bridge creation is initiated."
echo ""
sudo brctl addbr br_QEMU
sudo ip addr flush dev $var_eth
sudo brctl addif br_QEMU $var_eth
sudo tunctl -t tap0 -u `whoami`
sudo brctl addif br_QEMU tap0
sudo ifconfig $var_eth up
sudo ifconfig tap0 up
sudo ifconfig br_QEMU up
echo ""
sudo brctl show
sudo dhclient -v br_QEMU
echo ""
echoLightBlue "Bridge is up successfully"
echo ""
}
function bridge_down {
eth_option=$(ls /sys/class/net/)
for i in $eth_option;
do
if [ "${i:0:1}" == "e" ]
then
var_eth="$i"
fi
done
echo $var_eth
echo ""
echo "Bridge to be deleted..."
echo ""
sudo tunctl -d $var_eth
sudo brctl delif br_QEMU tap0
sudo tunctl -d tap0
sudo brctl delif br_QEMU $var_eth
sudo ifconfig br_QEMU down
sudo brctl delbr br_QEMU
sudo ifconfig $var_eth up
sudo dhclient -v $var_eth
echo ""
echoLightBlue "Bridge is down successfully"
echo ""
}
#get Configuration value from Array
#getConfValue [key]
# return [value]
function getConfValue {
for key in ${!QEMUBOOT_CONF_DATA_ARR[@]}; do
if [ ${1} == ${key} ]; then
echo ${QEMUBOOT_CONF_DATA_ARR[${key}]} ;
exit 1;
fi;
# echo "*"${key}":"${QEMUBOOT_CONF_DATA_ARR[${key}]}"*"
done
printWarning "Warning: Cannot find \"${1}\" in ${QEMUBOOT_CONF_PATH}" >&2;
exit 1;
}
#add configuration to webos-config.json
#addJsonValue [key] [value]
function addJsonValue {
local args="'$*'"
local SECOND_ARG=$(sed -e 's/'"$1 "'//g'i <<< $args)
SECOND_ARG=$(sed -e "s/'//g"i <<< $SECOND_ARG)
#add key, value to last
#sed -i '$s/}/,"'$1'":"'"$SECOND_ARG"'"\n}/' $CONFIG_JSON_FILE
#add key, value to first
sed -i 's/[{]/{\n "'$1'":"'"$SECOND_ARG"'",/g' $CONFIG_JSON_FILE
}
#get Json Value
#getJsonValue [key]
# return [value]
function getJsonValue {
local UNAMESTR=`uname`
if [[ "$UNAMESTR" == 'Linux' ]]; then
SED_EXTENDED='-r'
elif [[ "$UNAMESTR" == 'Darwin' ]]; then
SED_EXTENDED='-E'
fi;
local VALUE=`grep -m 1 "\"${1}\"" ${CONFIG_JSON_FILE} | sed ${SED_EXTENDED} 's/^ *//;s/.*: *"//;s/",?//'`
log $1" : "$VALUE
if [ ! "$VALUE" ]; then
printWarning "Warning: Cannot find \"${1}\" in ${CONFIG_JSON_FILE}" >&2;
echo ""
else
echo $VALUE ;
fi;
}
function isNumber {
local IsNumber='^[0-9]+$'
if ! [[ $1 =~ $IsNumber ]]; then
echo false
else
echo true
fi
}
function getMemorySize {
local TMP_RAMSIZE=$1
TMP_RAMSIZE=$(sed -e 's/B//g'i <<< $TMP_RAMSIZE)
TMP_RAMSIZE=$(sed -e 's/b//g'i <<< $TMP_RAMSIZE)
if [ "${TMP_RAMSIZE:$((${#TMP_RAMSIZE}-1)):1}" == "G" -o "${TMP_RAMSIZE:$((${#TMP_RAMSIZE}-1)):1}" == "g" ]; then
TMP_RAMSIZE=$(sed -e 's/G//g'i <<< $TMP_RAMSIZE)
TMP_RAMSIZE=$(sed -e 's/g//g'i <<< $TMP_RAMSIZE)
TMP_RAMSIZE=$((($TMP_RAMSIZE + 0) * 1024))
elif [ "${TMP_RAMSIZE:$((${#TMP_RAMSIZE}-1)):1}" == "M" -o "${TMP_RAMSIZE:$((${#TMP_RAMSIZE}-1)):1}" == "m" ]; then
TMP_RAMSIZE=$(sed -e 's/M//g'i <<< $TMP_RAMSIZE)
TMP_RAMSIZE=$(sed -e 's/m//g'i <<< $TMP_RAMSIZE)
TMP_RAMSIZE=$(($TMP_RAMSIZE + 0))
else
if [ `isNumber $TMP_RAMSIZE` == "false" ]; then
printError "Check the hw.ramSize value." >&2;
TMP_RAMSIZE=0
fi
fi
echo $TMP_RAMSIZE
}
function isPackageInstalled {
dpkg -s $1 &> /dev/null
if [ $? -eq 0 ]; then
echo "true"
else
echo "false"
fi
}
function toLowercase {
echo "$(tr [A-Z] [a-z] <<< "$1")"
}
function toUppercase {
echo "$(tr [a-z] [A-Z] <<< "$1")"
}
SHOW_VERSION=0
SHOW_HELP=0
for arg; do
if [ $arg == "-version" -o $arg == "-v" ]; then
SHOW_VERSION=1
elif [ $arg == "-help" -o $arg == "-h" ]; then
SHOW_HELP=1
elif [[ $arg == *".json" ]] || [[ $arg == *".JSON" ]]; then
CONFIG_JSON_FILE=$arg
fi
done
if [ $SHOW_VERSION == 1 ]; then
echo "Emulator script version is "$SCRIPT_VERSION
exit
elif [ $SHOW_HELP == 1 ]; then
printHelp
exit
fi
LINUX_VERSION=`lsb_release -r -s`
HOST_OS=`uname`
OS=$(awk '/DISTRIB_ID=/' /etc/*-release | sed 's/DISTRIB_ID=//' | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
echo $HOST_OS $OS $LINUX_VERSION $ARCH
# check libsdl2-2.0-0 package
if [ `isPackageInstalled libsdl2-2.0-0` == "false" ]; then
printError "libsdl2-2.0-0 is not installed."
echo "----------------------------------"
echo "sudo apt-get install libsdl2-2.0-0"
exit
fi
# check libpng12-0 package
if [ `isPackageInstalled libpng12-0` == "false" ]; then
printError "libpng12-0 is not installed."
echo "----------------------------------"
if [ "${LINUX_VERSION:0:2}" == "18" ]; then
echo "wget -q -O http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1_amd64.deb"
echo "sudo dpkg -i libpng12-0_1.2.54-1ubuntu1_amd64.deb"
else
echo "sudo apt-get install libpng12-0"
fi
exit
fi
# check mesa-utils package to check whether your pc suppor openGL 3.0 version at least
if [ `isPackageInstalled mesa-utils` == "false" ]; then
printError "mesa-utils is not installed. Please install mesa-utils to check whether your pc suppor openGL 3.0 version."
echo "----------------------------------"
echo "sudo apt-get install mesa-utils"
else
# check libegl1-mesa-dev package
mesa_version=`glxinfo | grep "OpenGL version"`
var1=${mesa_version:23:3}
mesa_version_number=3.0
if (( $(echo "$var1 < $mesa_version_number" | bc -l) )); then
printError "The GLES & mesa library version is $mesa_version"
echo "------------------------------------------------------------------------------------------------------------------"
printError "Minimum version to run the emulator is 3.0"
echo
echo '''To install newest mesa package, follow bellow steps.
1. Check the installed mesa package:
sudo apt list --installed | grep mesa
2. Check the GLES & mesa library version:
glxinfo | grep "OpenGL version"
3. Delete old mesa package:
14.04
https://www.howtoinstall.co/en/ubuntu/trusty/libegl1-mesa-dev?action=remove
16.04
https://www.howtoinstall.co/en/ubuntu/xenial/libegl1-mesa?action=remove
4. Update the system:
sudo apt-get update
sudo apt-get upgrade(or sudo apt-get dist-upgrade)
sudo apt-get -f install
5. Install dependency packages:
sudo apt-get install libegl1-mesa-drivers
sudo apt-get install libsdl2-2.0-0
6. Install newest mesa package:
sudo apt-get install -f libegl1-mesa-lts-xenial'''
exit
fi
fi
if [ "$ARCH" == "32" ]; then
ARCH="x86"
else
ARCH="x86_64"
fi
#check build environment setting
if [ -z "$TOPDIR" ] || [ -z "$BUILDDIR" ] ; then
QEMU_PATH=$SCRIPT_PATH/bin/$ARCH
else
QEMU_PATH=$TOPDIR/BUILD/sysroots/x86_64-linux/usr/bin/$ARCH
fi
QEMU_PATH=$SCRIPT_PATH/bin/$ARCH
#Set the configuration json
if [ -z "$CONFIG_JSON_FILE" ]; then
if [ -n "$TOPDIR" ] && [ -n "$BUILDDIR" ] ; then
#get the configuration information from webos-image-qemux86.qemuboot.conf
QEMUBOOT_CONF_PATH=`find $BUILDDIR -name '*qemux86.qemuboot.conf'`
if [ -z "$QEMUBOOT_CONF_PATH" ]; then
printError "Error: Cannot find 'qemux86.qemuboot.conf' file. Build first."
exit
fi
echo "QEMU Boot Configuration file : "`echoLightBlue $QEMUBOOT_CONF_PATH`
while read -r line
do
if [[ "$line" = *"="* ]]; then
IFS='=' read -r -a array <<< "$line"
#get key
#remove end white space
key=$(sed -e 's/^ *//g' -e 's/ *$//g' <<< ${array[0]})
#change "-" to "_"
key=$(sed -e 's/-/_/g'i <<< $key)
#key=$(sed -e 's/qb_//g'i <<< $key)
#get value
#remove start white space
value=$(sed -e 's/^ *//g' -e 's/ *$//g' <<< ${array[1]})
for (( i=2; i<${#array[@]}; i++ ));
do
value=$value"="$(sed -e 's/^ *//g' -e 's/ *$//g' <<< ${array[$i]})
done
#insert key value pair
declare -A QEMUBOOT_CONF_DATA_ARR
QEMUBOOT_CONF_DATA_ARR[$key]=$value
fi
done < "$QEMUBOOT_CONF_PATH"
#for Debug configuration key & value
#for key in ${!QEMUBOOT_CONF_DATA_ARR[@]}; do
# echo "***"${key}":"${QEMUBOOT_CONF_DATA_ARR[${key}]}"***"
#done
DEPLOY_PATH=`getConfValue deploy_dir_image`
CONFIG_JSON_FILE=$SCRIPT_PATH/webos-config.json
#generate the configuration json file
printf '{\n' > $CONFIG_JSON_FILE
printf ' "portforwarding.SSH":"6622",\n' >> $CONFIG_JSON_FILE
printf ' "portforwarding.inspector":"9998"\n' >> $CONFIG_JSON_FILE
printf '}\n' >> $CONFIG_JSON_FILE
DEPLOY_PATH=$(sed -e 's:/:\\/:g' <<< $DEPLOY_PATH)
IMAGE_NAME=`getConfValue image_name`
#add the vmdk path in configuration json file
#TODO: check exception case???
TMP_A=`getConfValue qb_serial_opt`
TMP_B="-serial mon:stdio -serial null"
addJsonValue debug $([ "$TMP_A" == "$TMP_B" ] && echo true || echo false)
soundhw=`getConfValue qb_audio_opt`
if [ -n "$soundhw" ]; then
soundhw=$(sed -e 's/-soundhw//g'i <<< $soundhw)
# addJsonValue soundhw $soundhw
fi
# addJsonValue hw.audio `getConfValue qb_audio_drv`
TMP_A=`getConfValue qb_opt_append`
TMP_B="-show-cursor"
# addJsonValue cursor $([[ $TMP_A = *"$TMP_B"* ]] && echo true || echo false)
TMP_B="-usb -usbdevice tablet"
# addJsonValue touch $([[ $TMP_A = *"$TMP_B"* ]] && echo true || echo false)
TMP_B="virgl"
TMP_C=",gl=on"
addJsonValue hw.gl.accel $([[ $TMP_A = *"$TMP_B"*"$TMP_C"* ]] || [[ $TMP_A = *"$TMP_C"*"$TMP_B"* ]] && echo true || echo false)
TMP_B="-enable-kvm"
addJsonValue hw.accel $([[ $TMP_A = *"$TMP_B"* ]] && echo true || echo false)
mem=`getConfValue qb_mem`
if [ -n "$mem" ]; then
mem=$(sed -e 's/-m//g'i <<< $mem)
addJsonValue hw.ramSize $mem
fi
addJsonValue hw.core 1
addJsonValue vmdk_file_path "$DEPLOY_PATH\/$IMAGE_NAME.vmdk"
addJsonValue name `getConfValue image_link_name`
addJsonValue description `getConfValue machine`
TMP_B="-device virtio-rng-pci"
# addJsonValue hw.virtio.rng $([[ $TMP_A = *"$TMP_B"* ]] && echo true || echo false)
# else
# CONFIG_JSON_FILE=`find $QEMU_PATH -name 'webos-config.json'`
fi
fi
if [ -n "$CONFIG_JSON_FILE" ]; then
if [ ! -f "$CONFIG_JSON_FILE" ]; then
printError "Error: "$CONFIG_JSON_FILE" is correct???"
exit
fi
CONFIG_JSON_FILE=`readlink -e $CONFIG_JSON_FILE`
echo "Configuration JSON file : "`echoLightBlue $CONFIG_JSON_FILE`
else
printError "Error: Choice the webos-config.json"
exit
fi
CONFIG_JSON_DIR=`dirname $CONFIG_JSON_FILE`
#read information from webos-config.json
QEMU_VMDK_FILE=`getJsonValue vmdk_file_path`
if [ -z "$QEMU_VMDK_FILE" ]; then
printError "Error: Check the "$CONFIG_JSON_FILE
# QEMU_VMDK_FILE=`find . -type f -name '*.vmdk' | sed 's/.vmdk\([0-9]\+\).*/\1/g' | sort -n | tail -1`
exit
else
if [ "${QEMU_VMDK_FILE:0:2}" == "./" ]; then
QEMU_VMDK_FILE=`readlink -e $CONFIG_JSON_DIR/$QEMU_VMDK_FILE`
elif [ "${QEMU_VMDK_FILE:0:2}" == "~/" ]; then
QEMU_VMDK_FILE=${QEMU_VMDK_FILE/#~/$HOME}
fi
if [ ! -f "$QEMU_VMDK_FILE" ]; then
printError "Error: Check the vmdk_file_path value in the "$CONFIG_JSON_FILE
printError "Error: "$QEMU_VMDK_FILE
exit
fi
fi
#echo "Emualtor start with : "`echoLightBlue $QEMU_VMDK_FILE`
QEMU_NAME=`getJsonValue name`
if [ -n "$QEMU_NAME" ]; then
QEMU_NAME="-name "$QEMU_NAME
fi
QEMU_SSH_PORT=`getJsonValue portforwarding.SSH`
if [ `isNumber $QEMU_SSH_PORT` == "false" ]; then
printError "Check the portfowarding.SSH." >&2;
exit
fi
if [ -z "$QEMU_SSH_PORT" ]; then
QEMU_SSH_PORT="6622-:22"
else
QEMU_SSH_PORT="$QEMU_SSH_PORT-:22"
fi
QEMU_INSPECTOR_PORT=`getJsonValue portforwarding.inspector`
if [ `isNumber $QEMU_INSPECTOR_PORT` == "false" ]; then
printError "Check the portfowarding.inspector" >&2;
exit
fi
if [ -n "$QEMU_INSPECTOR_PORT" ]; then
QEMU_INSPECTOR_PORT=",hostfwd=tcp::$QEMU_INSPECTOR_PORT-:9998"
fi
QEMU_DEBUG=`getJsonValue debug`
QEMU_DEBUG=`toLowercase $QEMU_DEBUG`
if [ "$QEMU_DEBUG" == "true" ]; then
QEMU_DEBUG="-serial mon:stdio -serial null"
else
QEMU_DEBUG=""
fi
QEMU_CORE=`getJsonValue hw.core`
if [ -z "$QEMU_CORE" ]; then
QEMU_CORE_CNT=`cat /proc/cpuinfo | grep processor | wc -l`
QEMU_CORE=$((QEMU_CORE_CNT/2))
fi
if [ `isNumber $QEMU_CORE` == "false" ]; then
printError "Check the hw.core." >&2;
exit
fi
QEMU_CORE="-smp "$QEMU_CORE
QEMU_RAMSIZE=`getJsonValue hw.ramSize`
QEMU_RAMSIZE=`getMemorySize $QEMU_RAMSIZE`
if [ -z "$QEMU_RAMSIZE" ]; then
TOTAL_MEM=`grep MemTotal /proc/meminfo | awk '{print $2}'`
QEMU_RAMSIZE=$((TOTAL_MEM/2/1000/1000*1024))
fi
if [ "$QEMU_RAMSIZE" -lt "1024" ]; then
printError "Error: Guest memory must set more than 1024MB."
exit
fi
QEMU_RAMSIZE="-m "$QEMU_RAMSIZE
QEMU_ACCEL=`getJsonValue hw.accel`
QEMU_ACCEL=`toLowercase $QEMU_ACCEL`
if [ "$QEMU_ACCEL" == "true" ]; then
QEMU_ACCEL="-enable-kvm"
else
QEMU_ACCEL=""
fi
QEMU_DISPLAY=sdl
QEMU_GL_ACCEL=`getJsonValue hw.gl.accel`
QEMU_GL_ACCEL=`toLowercase $QEMU_GL_ACCEL`
if [ "$QEMU_GL_ACCEL" == "true" ]; then
if [ "$HOST_OS" == "Linux" -a "$OS" == "ubuntu" ]; then
QEMU_GL_ACCEL_DEV="-device virtio-vga,virgl"
fi
QEMU_GL_ACCEL="-display $QEMU_DISPLAY,gl=on"
else
QEMU_GL_ACCEL_DEV="-device virtio-vga"
QEMU_GL_ACCEL="-display $QEMU_DISPLAY,gl=off"
fi
#if [ "`getJsonValue cursor`" == "true" ]; then
QEMU_CURSOR="-show-cursor"
#fi
#if [ "`getJsonValue touch`" == "true" ]; then
QEMU_USB="-usb -usbdevice tablet"
#fi
#if [ "`getJsonValue hw.virtio.rng`" == "true" ]; then
QEMU_DEVICE_RNG="-device virtio-rng-pci"
#fi
#QEMU_SOUND_HW=`getJsonValue soundhw`
QEMU_SOUND_HW=hda
if [ -n "$QEMU_SOUND_HW" ]; then
QEMU_SOUND_HW="-soundhw "$QEMU_SOUND_HW
fi
QEMU_OPT_APPEND="$QEMU_ACCEL $QEMU_GL_ACCEL_DEV $QEMU_GL_ACCEL $QEMU_CURSOR $QEMU_USB $QEMU_DEVICE_RNG"
#echo $QEMU_OPT_APPEND
sleep 1
#path for additional library path
export LD_LIBRARY_PATH=$SCRIPT_PATH/lib/$ARCH
#QEMU_AUDIO_DRV=`getJsonValue hw.audio`
QEMU_AUDIO_DRV=alsa
QEMU_EXEC=qemu-system-x86_64
FINAL_CMD="$QEMU_PATH/$QEMU_EXEC $QEMU_NAME $QEMU_CORE $QEMU_RAMSIZE $QEMU_DEBUG -drive file=$QEMU_VMDK_FILE,if=virtio $QEMU_OPT_APPEND $QEMU_SOUND_HW -net nic -net user,hostfwd=tcp::$QEMU_SSH_PORT$QEMU_INSPECTOR_PORT"
echo $FINAL_CMD
# check kvm package
if [ `isPackageInstalled cpu-checker` == "false" ]; then
printError "cpu-checker is not installed. If you want to check kvm in your pc, please install cpu-checker."
echo "----------------------------------"
echo "sudo apt-get install cpu-checker"
#exit # do not exit because it's optional
else
#KVM check
KVM_status=`sudo kvm-ok`
if [ "${KVM_status}" == "INFO: /dev/kvm does not exist
HINT: sudo modprobe kvm_intel
INFO: Your CPU supports KVM extensions
INFO: KVM (vmx) is disabled by your BIOS
HINT: Enter your BIOS setup and enable Virtualization Technology (VT),
and then hard poweroff/poweron your system
KVM acceleration can NOT be used" ]; then
echo ""
printError "Not able to initialize KVM. Check your processor support and enable KVM under BIOS settings."
echo '''
Check if processor supports virtualization or not using below commands.
NOTE:(If the processor doesnot have support, virtualization cannot be enabled).
For Intel VT technology:
Run the command: grep --color vmx /proc/cpuinfo
(If the output has the vmx flags, then Intel CPU host is capable of running hardware virtualization)
For AMD – V technology:
Run the command: grep --color svm /proc/cpuinfo
(If the output has the svm flags, then AMD CPU host is capable of running hardware virtualization).
In host system, install kvm module by using bellow command and run it again:
$ sudo apt-get install qemu-kvm
Follow the Steps to Enable KVM support for Hardware acceleration:
1.Go to the BIOS settings.
2.Enable Virtualization Options:
-Virtualization
-V.T for direct I/O
3.Apply
4.EXIT'''
echo ""
exit
fi
fi
#usb_WebCam_implementation
if [ `isPackageInstalled libusb-dev` == "false" ]; then
printError " libusb-dev is not installed."
echo "----------------------------------"
echo "sudo apt-get install libusb-dev"
exit
fi
if [ `isPackageInstalled libusb-1.0-0-dev` == "false" ]; then
printError " libusb-1.0-0-dev is not installed."
echo "----------------------------------"
echo "sudo apt-get install libusb-1.0-0-dev"
exit
fi
if [ `isPackageInstalled libusbredirparser-dev` == "false" ]; then
printError " libusbredirparser-dev is not installed."
echo "----------------------------------"
echo "sudo apt-get install libusbredirparser-dev"
exit
fi
QEMU_usbVendor=`getJsonValue webCam_vendor.id`
QEMU_usbProduct=`getJsonValue webCam_product.id`
sudo scp -r $LD_LIBRARY_PATH/libexec /usr/local
sudo chmod -R 4755 /usr/local/libexec
#user interaction for the bridge creation
echo ""
echoLightBlue "By default NAT support is enabled .If you wish to change then you can switch to Bridge network support.To work effectively, the Bridge support requires an active Internet connection. We strongly recommend that you do not disconnect the Internet while using Bridge support."
echo ""
read -p 'Bridge support needed? [y/N]' bridge_support_var
if [ "$bridge_support_var" = "N" ] || [ "$bridge_support_var" = "n" ]; then
FINAL_CMD="sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SCRIPT_PATH/lib/$ARCH $QEMU_PATH/$QEMU_EXEC $QEMU_NAME $QEMU_CORE $QEMU_RAMSIZE $QEMU_DEBUG -drive file=$QEMU_VMDK_FILE,if=virtio $QEMU_OPT_APPEND $QEMU_SOUND_HW -net nic -net user,hostfwd=tcp::$QEMU_SSH_PORT$QEMU_INSPECTOR_PORT -usb -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=$QEMU_usbVendor,productid=$QEMU_usbProduct"
elif [ "$bridge_support_var" = "Y" ] || [ "$bridge_support_var" = "y" ]; then
file="/usr/local/etc/qemu/bridge.conf"
if [ -f "$file" ]; then
'bridge_up'
else
echo ""
sudo scp -r $LD_LIBRARY_PATH/qemu /usr/local/etc/
sudo chmod -R 4755 $LD_LIBRARY_PATH/qemu
'bridge_up'
echo ""
fi
FINAL_CMD="sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SCRIPT_PATH/lib/$ARCH $QEMU_PATH/$QEMU_EXEC $QEMU_NAME $QEMU_CORE $QEMU_RAMSIZE $QEMU_DEBUG -drive file=$QEMU_VMDK_FILE,if=virtio $QEMU_OPT_APPEND $QEMU_SOUND_HW -net nic -net bridge,br=br_QEMU,model=virtio -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::6622-:22 -usb -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=$QEMU_usbVendor,productid=$QEMU_usbProduct"
elif [ "$bridge_support_var" = "" ];then
FINAL_CMD="sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SCRIPT_PATH/lib/$ARCH $QEMU_PATH/$QEMU_EXEC $QEMU_NAME $QEMU_CORE $QEMU_RAMSIZE $QEMU_DEBUG -drive file=$QEMU_VMDK_FILE,if=virtio $QEMU_OPT_APPEND $QEMU_SOUND_HW -net nic -net user,hostfwd=tcp::$QEMU_SSH_PORT$QEMU_INSPECTOR_PORT -usb -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=$QEMU_usbVendor,productid=$QEMU_usbProduct"
else
printError "Please enter valid option.i.e [y/N]"
exit
fi
echo ""
echo "Emualtor start with : "`echoLightBlue $QEMU_VMDK_FILE`""
echo ""
$FINAL_CMD
if [ -z $DISPLAY ]; then
exit
elif [ "$bridge_support_var" = "Y" ] || [ "$bridge_support_var" = "y" ] ; then
'bridge_down'
fi