Difference between revisions of "GhettoVCB - clone.sh Script"

From The TinkerNet Wiki
Jump to navigation Jump to search
Line 1: Line 1:
Do note that this is just the code to create the menu, no actual handling here.  (Because '''sh''', as implemented in ESXi is kinda limited...)
 
  
 
  !/bin/sh
 
  !/bin/sh
Line 36: Line 35:
 
     echo "Preparing to create "$VMName
 
     echo "Preparing to create "$VMName
 
     echo "Placing the VM on "$Destination
 
     echo "Placing the VM on "$Destination
     echo "22:22, 1 July 2020 (EDT)22:22, 1 July 2020 (EDT)22:22, 1 July 2020 (EDT)22:22, 1 July 2020 (EDT)22:22, 1 July 2020 (EDT)"
+
     <nowiki>echo "~~~~~~~~~~~~~~~~~~~~~~~~~"</nowiki>
 
     echo " Select your Baseline VM "
 
     echo " Select your Baseline VM "
     echo "22:22, 1 July 2020 (EDT)22:22, 1 July 2020 (EDT)22:22, 1 July 2020 (EDT)22:22, 1 July 2020 (EDT)22:22, 1 July 2020 (EDT)"
+
     <nowiki>echo "~~~~~~~~~~~~~~~~~~~~~~~~~"</nowiki>
 
     echo "1: Linux Mint 19.3"
 
     echo "1: Linux Mint 19.3"
 
     echo "2: SparkyLinux-CLI 5.11"
 
     echo "2: SparkyLinux-CLI 5.11"

Revision as of 22:39, 1 July 2020

!/bin/sh

export PATH=/bin:/sbin

# ----------------------------------
# Step #1: Define variables
# ----------------------------------
RED='\033[0;41;30m'
STD='\033[0;0;39m'
VMName=$1
Destination="/vmfs/volumes/0-VMs"

# ----------------------------------
# Step #2: User defined function
# ----------------------------------
pause(){
   read -p "Press [Enter] key to continue..." fackEnterKey
}

clone(){
   echo "ghettoVCB/clone.sh is creating "$VMName" from "$BaseLine
   logger "ghettoVCB/clone.sh is creating "$VMName" from "$BaseLine

   echo "/vmfs/volumes/Admin/CloneMe/"$BaseLine/$BaseLine"-0;"$Destination";1;"$VMName > CloneIt
   /vmfs/volumes/Admin/Utilities/ghettoVCB/ghettoVCB-restore.sh -c CloneIt

   logger "ghettoVCB/clone.sh "$VMName" finished"
   echo "ghettoVCB/clone.sh "$VMName" finished"
}

# function to display menus
show_menus() {
   clear
   echo "Preparing to create "$VMName
   echo "Placing the VM on "$Destination
   echo "~~~~~~~~~~~~~~~~~~~~~~~~~"
   echo " Select your Baseline VM "
   echo "~~~~~~~~~~~~~~~~~~~~~~~~~"
   echo "1: Linux Mint 19.3"
   echo "2: SparkyLinux-CLI 5.11"
   echo "3: SparkyLinux-GUI 5.11"
   echo "4: Windows 10"
   echo "5: Windows 7"
   echo ""
   echo "0. Exit"
}

# read input from the keyboard and take an action
# Exit when user the user selects 0 form the menu option.                                       
read_options(){                                                           
   local choice                                                  
   read -p "Enter choice [ 1-5 or 0] " choice                      
   case $choice in                               
      1)   echo "Linux Mint 19.3"                                                               
            BaseLine="CloneMe-Mint-19.3"                                  
            clone                                                
            exit 0                                                 
            ;;                                   
      2)   echo "SparkyLinux-CLI 5.11"                                                          
            BaseLine="CloneMe-SparkyLinux-CLI-5.11"                       
            clone                                                
            exit 0                                                 
            ;;                                   
      3)   echo "SparkyLinux-GUI 5.11"                                                          
            BaseLine="CloneMe-SparkyLinux-GUI-5.11"                       
            clone                                                  
            exit 0                               
            ;;                                                                                  
      4)   echo "Windows 10"                                              
            BaseLine="CloneMe-Windows-10"          
            clone                                
            exit 0                             
            ;;                                   
      5)   echo "Windows 7"                              
            BaseLine="CloneMe-Windows-7"           
            clone                  
            exit 0                           
            ;;                                   
      0)   exit 0                                        
            ;;                                     
      *)   echo -e "${RED}Error...${STD}" && sleep 2
   esac                                      
}

# ----------------------------------------------
# Step #3: Trap CTRL+C, CTRL+Z and quit singles  
# ----------------------------------------------         
trap  SIGINT SIGQUIT SIGTSTP                     
                                                    
# -----------------------------------           
# Step #4: Main logic - infinite loop            
# -----------------------------------                    
while true                                         
   do                                               
      show_menus                                
      read_options                               
   done