From e395c1475204b71ed53d7067a31b471c1529bf76 Mon Sep 17 00:00:00 2001 From: phil Date: Wed, 18 Jan 2023 23:24:33 +0100 Subject: [PATCH] modif mkvm --- scripts/mkvm | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/scripts/mkvm b/scripts/mkvm index c5b61fb..147743d 100755 --- a/scripts/mkvm +++ b/scripts/mkvm @@ -1,21 +1,24 @@ #!/bin/bash +mkvmrelease="v1.2" + ovarelease="2023a" ovafogrelease="2023a" ovafile="$HOME/Téléchargements/debian-bullseye-gsb-${ovarelease}.ova" ovafilefog="$HOME/Téléchargements/debian-buster-gsb-${ovafogrelease}.ova" - +deletemode=0 usage () { - echo "$0 - version ${ovarelease}" + echo "$0 - version ${mkvmrelease} - Ova version ${ovarelease}" echo "$0 : creation VM et parametrage interfaces" - echo "usage : $0 " + echo "usage : $0 [-r] " + echo " option -r : efface vm existante avant creation nouvelle" exit 1 } create_vm () { - nom="$1" - nomova=${ovafile} + local nom="$1" + local nomova="${ovafile}" if [[ "${nom}" == "s-fog" ]] ; then nomova="${ovafilefog}" fi @@ -23,6 +26,9 @@ create_vm () { echo "$0 : erreur ouverture fichier ${nomova} ..." exit 3 fi + if [[ "${deletemode}" = 1 ]] ; then + VBoxManage unregistervm --delete "${nom}" + fi vboxmanage import "${nomova}" --vsys 0 --vmname "${nom}" } @@ -38,15 +44,25 @@ setif () { create_if () { # enp0s3 setif "$1" 1 "$2" - setif "$1" 2 "$3" #(enp0s8) + setif "$1" 2 "$3" +#(enp0s9) + if [[ -n "$4" ]] ; then + setif "$1" 3 "$4" + fi } -if [[ $# != 1 ]] ; then +if [[ $# == 0 ]] ; then usage fi - +if [[ $1 == "--help" ]] || [[ $1 == "-h" ]] || [[ $1 == "-V" ]] ; then + usage +fi +if [[ $1 == "-r" ]] ; then + deletemode=1 + shift +fi vm="$1" create_vm "${vm}" @@ -56,9 +72,7 @@ elif [[ "${vm}" == "s-proxy" ]] ; then create_if "${vm}" "n-adm" "n-infra" elif [[ "${vm}" == "r-int" ]] ; then # n-adm, n-link, n-wifi, n-user, n-infra - create_if "${vm}" "n-adm" "n-infra" - setif "${vm}" 2 "n-link" - setif "${vm}" 3 "n-wifi" + create_if "${vm}" "n-adm" "n-link" "n-wifi" setif "${vm}" 4 "n-user" setif "${vm}" 5 "n-infra" elif [[ "${vm}" == "r-ext" ]] ; then @@ -74,9 +88,8 @@ elif [[ "${vm}" == "s-itil" ]] ; then elif [[ "${vm}" == "s-nxc" ]] ; then create_if "${vm}" "n-adm" "n-infra" elif [[ "${vm}" == "s-fog" ]] ; then - create_if "${vm}" "n-adm" "n-infra" - setif "${vm}" 3 "n-user" -elif [[ "${vm}" == "s-DNS-ext" ]] ; then + create_if "${vm}" "n-adm" "n-infra" "n-user" +elif [[ "${vm}" == "s-dns-ext" ]] ; then create_if "${vm}" "n-adm" "n-dmz" elif [[ "${vm}" == "s-web-ext" ]] ; then create_if "${vm}" "n-adm" "n-dmz" @@ -86,12 +99,10 @@ elif [[ "${vm}" == "s-lb" ]] ; then create_if "${vm}" "n-adm" "n-dmz" "n-dmz-lb" elif [[ "${vm}" == "s-web1" ]] ; then create_if "${vm}" "n-adm" "n-dmz-lb" "n-dmz-db" -# setif "${vm}" 3 "n-dmz-lb" elif [[ "${vm}" == "s-web2" ]] ; then create_if "${vm}" "n-adm" "n-dmz-lb" "n-dmz-db" elif [[ "${vm}" == "s-web3" ]] ; then create_if "${vm}" "n-adm" "n-dmz-lb" "n-dmz-db" - # setif "${vm}" 3 "n-dmz-lb" elif [[ "${vm}" == "s-lb-bd" ]] ; then create_if "${vm}" "n-adm" "n-dmz-db" elif [[ "${vm}" == "s-nas" ]] ; then @@ -102,8 +113,7 @@ elif [[ "${vm}" == "r-vp2" ]] ; then ./addint.r-vp2 elif [[ "${vm}" == "s-agence" ]] ; then create_if "${vm}" "n-adm" "n-agence" - else - echo "$0 : vm ${vm} non prevu" + echo "$0 : vm ${vm} non prevue " exit 2 fi