From dc9fbe1cd988e4e8c3776f7a204fd09ca847a3f2 Mon Sep 17 00:00:00 2001 From: David Tomaschik Date: Fri, 6 Jan 2017 21:20:19 -0800 Subject: [PATCH] Update switch_virt.sh --- bin/switch_virt.sh | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/bin/switch_virt.sh b/bin/switch_virt.sh index ae2173f..6cb259c 100755 --- a/bin/switch_virt.sh +++ b/bin/switch_virt.sh @@ -1,13 +1,28 @@ -#!/bin/sh +#!/bin/bash -if [ "$1" -eq "kvm" ] ; then +if [ $# -lt 1 ] ; then + echo "Usage: $0 " >&2 + exit 1 +fi + +if [ `whoami` != "root" ] ; then + if which sudo >/dev/null 2>&1 ; then + sudo $0 $* + exit + fi + echo "Sorry, this requires root." >&2 + exit 1 +fi + +if [ "$1" == "kvm" ] ; then /etc/init.d/virtualbox stop modprobe kvm modprobe kvm_intel -elif [ "$1" -eq "vbox" ] ; then +elif [ "$1" == "vbox" ] ; then rmmod kvm_intel rmmod kvm /etc/init.d/virtualbox start else echo 'WTF?' >&2 + exit 1 fi