]>
Commit | Line | Data |
---|---|---|
95642cd9 MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2008 Michael Tremer & Christian Schmidt # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
22 | qemu_start() { | |
23 | # Check if we have a qemu binary | |
24 | if ! which qemu &>/dev/null; then | |
25 | dialogerror "Cannot find qemu." | |
26 | exit 1 | |
27 | fi | |
28 | ||
29 | # Check if the working directory is present | |
30 | [ -d "$BASEDIR/vm" ] || mkdir $BASEDIR/vm | |
31 | QEMU_DISK=$BASEDIR/vm/qemu-hda-$HOSTNAME.img | |
32 | ||
33 | # Create a qemu disk if not present (4G) | |
34 | [ -e $QEMU_DISK ] || qemu-img create $QEMU_DISK 4G | |
35 | ||
36 | # Load the kernel module | |
37 | if ! grep -q ^kqemu /proc/modules; then | |
38 | modprobe kqemu 2>/dev/null | |
39 | fi | |
40 | ||
41 | # Prepare qemu command | |
42 | QEMU_COMMAND="qemu -name $NAME-$VERSION -m 256" | |
43 | QEMU_COMMAND="$QEMU_COMMAND -k de -localtime -std-vga -usb" | |
44 | QEMU_COMMAND="$QEMU_COMMAND -no-reboot -vnc :2 -hda $QEMU_DISK" | |
45 | ||
46 | if ! grep -q ^kqemu /proc/modules; then | |
47 | QEMU_COMMAND="$QEMU_COMMAND -no-kqemu" | |
48 | fi | |
49 | ||
50 | case "$1" in | |
51 | ""|cd*) | |
52 | QEMU_COMMAND="$QEMU_COMMAND -boot d -cdrom" | |
53 | if [ -n "$2" ]; then | |
54 | QEMU_COMMAND="$QEMU_COMMAND $2" | |
55 | else | |
56 | QEMU_COMMAND="$QEMU_COMMAND $BASEDIR/$IMAGENAME.iso" | |
57 | fi | |
58 | ;; | |
59 | disk|hd*) | |
60 | QEMU_COMMAND="$QEMU_COMMAND -boot c" | |
61 | ;; | |
62 | esac | |
63 | ||
64 | echo -e "We are going to run a ${BOLD}virtual machine${NORMAL}, now." | |
65 | echo | |
66 | echo "You may connect to this machine with a vnc viewer to $HOSTNAME:2." | |
67 | echo "Kill this vm by pressing Ctrl+C." | |
68 | echo | |
69 | $QEMU_COMMAND | |
70 | if [ $? -eq 0 ]; then | |
71 | echo -n "The virtual machine quit gracefully." | |
a4d1c7d6 | 72 | beautify message DONE |
95642cd9 MT |
73 | else |
74 | echo -n "The virtual machine quit with an error!" | |
75 | beautify message FAIL | |
76 | fi | |
77 | } |