application of some corrections
This commit is contained in:
parent
aa98ee4c37
commit
abf7786020
2 changed files with 37 additions and 47 deletions
|
@ -65,5 +65,5 @@ done
|
|||
echo user=${USER}
|
||||
echo port=${PORT}
|
||||
|
||||
ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile=/dev/null" ${USER}@localhost -p ${PORT}
|
||||
ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile=/dev/null" -p ${PORT} ${USER}@localhost
|
||||
|
||||
|
|
82
vm-start.sh
82
vm-start.sh
|
@ -1,10 +1,10 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
|
||||
#RESULT_POSSIBLE=("init","start","start-backup","create","backup","restore","suppr")
|
||||
#RESULT_POSSIBLE=("init","start","start_backup","create","backup","restore","suppr")
|
||||
|
||||
# Constante d'éxecutions.
|
||||
VERSION=0.6
|
||||
Version="0.6"
|
||||
USAGE="vm-start [ NAME COMMAND [PARAMETER] ] [OPTION]
|
||||
|
||||
Script to manage virtual machine easily.
|
||||
|
@ -55,13 +55,9 @@ HELP() {
|
|||
INIT() {
|
||||
echo "INIT for vm $1"
|
||||
NAME=$1
|
||||
echo "How many proccessor will you use ? "
|
||||
read NPROC
|
||||
echo "How much memory will you need ? "
|
||||
read MEMORY
|
||||
|
||||
echo "Do you want to forward ssh port (y/n) "
|
||||
read entry
|
||||
read -p "How many proccessor will you use ? " -r NPROC
|
||||
read -p "How much memory will you need ? " -r MEMORY
|
||||
read -p "Do you want to forward ssh port (y/n) " -r entry
|
||||
|
||||
if [[ $entry =~ ^[yY]$ ]]
|
||||
then
|
||||
|
@ -71,14 +67,14 @@ INIT() {
|
|||
fi
|
||||
|
||||
mkdir -p conf
|
||||
echo "
|
||||
NAME=\"$NAME\"
|
||||
VMHOSTNAME=\"\$NAME-vm\"
|
||||
NPROC=$NPROC
|
||||
MEMORY=\"$MEMORY\"
|
||||
FORWARD=\"$FORWARD\"
|
||||
LOCATION=\"\$NAME-sandbox/\"
|
||||
" > conf/$NAME-vm_var.sh
|
||||
cat << EOF > "conf/$NAME-vm_var.sh"
|
||||
NAME="$NAME"
|
||||
VMHOSTNAME="\$NAME-vm"
|
||||
NPROC="$NPROC"
|
||||
MEMORY="$MEMORY"
|
||||
FORWARD="$FORWARD"
|
||||
LOCATION="\$NAME-sandbox/"
|
||||
EOF
|
||||
chmod +x conf/$NAME-vm_var.sh
|
||||
|
||||
}
|
||||
|
@ -95,12 +91,9 @@ START() {
|
|||
$OPTION \
|
||||
-daemonize
|
||||
|
||||
sleep 5
|
||||
|
||||
ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile=/dev/null" primardj@localhost -p 10022
|
||||
}
|
||||
|
||||
START-BACKUP() {
|
||||
START_BACKUP() {
|
||||
qemu-system-x86_64 \
|
||||
-enable-kvm \
|
||||
-cpu host \
|
||||
|
@ -112,9 +105,6 @@ START-BACKUP() {
|
|||
$OPTION \
|
||||
-daemonize
|
||||
|
||||
sleep 5
|
||||
|
||||
#ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile=/dev/null" primardj@localhost -p 10022
|
||||
}
|
||||
|
||||
CREATE() {
|
||||
|
@ -124,14 +114,14 @@ CREATE() {
|
|||
SIZE="40G"
|
||||
fi
|
||||
|
||||
if [[ ! -f ${MAIN_LOCATION}${LOCATION}${VMHOSTNAME}.cow ]]
|
||||
if [ ! -f "${MAIN_LOCATION}${LOCATION}${VMHOSTNAME}.cow" ]
|
||||
then
|
||||
echo "create directory ${MAIN_LOCATION}${LOCATION}"
|
||||
mkdir -p ${MAIN_LOCATION}${LOCATION}
|
||||
qemu-img create -f qcow2 ${MAIN_LOCATION}${LOCATION}${VMHOSTNAME}.cow $SIZE
|
||||
fi
|
||||
|
||||
if [ -n ${UEFI+x} ]
|
||||
if [ "${UEFI}" == "set" ]
|
||||
then
|
||||
echo "create UEFIVAR"
|
||||
if [ ! -f ${MAIN_LOCATION}${LOCATION}OVMF_VARS.4m.fd ]
|
||||
|
@ -158,7 +148,7 @@ CREATE() {
|
|||
|
||||
RESTORE() {
|
||||
echo "Are you sure you want to restore the rescue? (y/N)"
|
||||
read entry
|
||||
read -r entry
|
||||
if [[ $entry =~ ^[yY]$ ]]
|
||||
then
|
||||
cp ${MAIN_LOCATION}${LOCATION}${VMHOSTNAME}.cow.backup ${MAIN_LOCATION}${LOCATION}${VMHOSTNAME}.cow
|
||||
|
@ -168,8 +158,8 @@ RESTORE() {
|
|||
|
||||
|
||||
BACKUP() {
|
||||
echo "Are you sure you want to backup the volume? If you continue the previous backup will be lost (y/N)"
|
||||
read entry
|
||||
# Should test if the folder ${MAIN_LOCATION}${LOCATION}${VMHOSTNAME}.cow exist or else it will arrive an error.
|
||||
read -p "Are you sure you want to backup the volume? If you continue the previous backup will be lost (y/N) " -r entry
|
||||
if [[ $entry =~ ^[yY]$ ]]
|
||||
then
|
||||
cp ${MAIN_LOCATION}${LOCATION}${VMHOSTNAME}.cow ${MAIN_LOCATION}${LOCATION}${VMHOSTNAME}.cow.backup
|
||||
|
@ -178,8 +168,7 @@ BACKUP() {
|
|||
}
|
||||
|
||||
SUPPRESS() {
|
||||
echo "Are you sure you want to delete all data relative to the vm $1"
|
||||
read entry
|
||||
read -p "Are you sure you want to delete all data relative to the vm $1? (y/N)" -r entry
|
||||
if [[ $entry =~ ^[yY]$ ]]
|
||||
then
|
||||
rm -Ri ${MAIN_LOCATION}${LOCATION}
|
||||
|
@ -197,7 +186,7 @@ do
|
|||
HELP
|
||||
elif [ "$i" == "-v" ] || [ "$i" == "--version" ]
|
||||
then
|
||||
echo "vm-start ${VERSION}"
|
||||
echo "vm-start ${Version}"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
|
@ -207,14 +196,14 @@ done
|
|||
|
||||
if [ $# -lt 2 ]
|
||||
then
|
||||
echo "Error, not enough args"
|
||||
echo "Error, not enough args" >&2
|
||||
HELP
|
||||
fi
|
||||
|
||||
# vérifie que le dossier pour stocker les vms existe & change le dossier actif pour qu'il soit cellui du lanceur.
|
||||
|
||||
mkdir -p $MAIN_LOCATION
|
||||
cd "$( dirname "$( readlink -f "$0" )" )"
|
||||
cd "$( dirname "$( readlink -f "$0" )" )" || exit
|
||||
|
||||
# Véréfie qu'il y ait bien un fichier de config pour la vm que l'on tente de démarer dans la cas contraire en génére un.
|
||||
# possibilitée de générer à nouveau le fichier de config avec vm-start nom-vm init
|
||||
|
@ -222,14 +211,13 @@ cd "$( dirname "$( readlink -f "$0" )" )"
|
|||
if [ "$2" == "init" ]
|
||||
then
|
||||
INIT $1
|
||||
elif [[ ! -f conf/$1-vm_var.sh ]]
|
||||
elif [ ! -f "conf/$1-vm_var.sh" ]
|
||||
then
|
||||
echo "no config file found. creating one in conf/${1}-vm_var.sh"
|
||||
INIT $1
|
||||
fi
|
||||
|
||||
#Vérifie si l'option UEFI est set dans le fichier de config. Si oui l'ajoutte aux options.
|
||||
#TODO l'ajoutter au detecteur d'options.
|
||||
|
||||
. conf/$1-vm_var.sh
|
||||
|
||||
|
@ -242,7 +230,7 @@ for (( i=3; i<=$#; i++)); do
|
|||
MEMORY="${!i#*=}"
|
||||
elif [ "${!i%=*}" == "uefi" ]
|
||||
then
|
||||
unset UEFI
|
||||
UEFI="set"
|
||||
OPTION="$OPTION \
|
||||
-drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2/x64/OVMF_CODE.4m.fd \
|
||||
-drive if=pflash,format=raw,file=${MAIN_LOCATION}${LOCATION}OVMF_VARS.4m.fd"
|
||||
|
@ -250,8 +238,9 @@ for (( i=3; i<=$#; i++)); do
|
|||
done
|
||||
|
||||
|
||||
if [ -n "${UEFI+x}" ]
|
||||
if [ "${UEFI}" == "yes" ]
|
||||
then
|
||||
UEFI="set"
|
||||
OPTION="$OPTION \
|
||||
-drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2/x64/OVMF_CODE.4m.fd \
|
||||
-drive if=pflash,format=raw,file=${MAIN_LOCATION}${LOCATION}OVMF_VARS.4m.fd"
|
||||
|
@ -265,7 +254,7 @@ then
|
|||
elif [ "$2" == "start-backup" ]
|
||||
then
|
||||
echo "starting VM rescue"
|
||||
START-BACKUP
|
||||
START_BACKUP
|
||||
elif [ "$2" == "backup" ]
|
||||
then
|
||||
echo "backup VM"
|
||||
|
@ -277,19 +266,20 @@ then
|
|||
elif [ "$2" == "create" ]
|
||||
then
|
||||
echo "creating VM"
|
||||
if [[ $# == 3 ]]
|
||||
if [ $# -ge 3 ]
|
||||
then
|
||||
echo "using image disk $3"
|
||||
CREATE $3
|
||||
echo "using image disk $3" # Error here, please don't think that there will be only three devices, should be improve like with an install-device parametter.
|
||||
CREATE $3 # TODO
|
||||
else
|
||||
echo "Error, no image defined."
|
||||
echo "$#"
|
||||
echo "Error, no image defined." >&2
|
||||
fi
|
||||
elif [[ $2 == "suppr" ]]
|
||||
elif [ "$2" == "suppr" ]
|
||||
then
|
||||
echo "suppressing all data of the vm $1"
|
||||
SUPPRESS
|
||||
SUPPRESS $1
|
||||
else
|
||||
echo "commande $2 inconnue"
|
||||
echo "commande $2 inconnue" >&2
|
||||
HELP
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in a new issue