Skip to content

Instantly share code, notes, and snippets.

@nitrocode
Last active August 7, 2020 07:08
Show Gist options
  • Save nitrocode/007fce26f161aa0b74ec to your computer and use it in GitHub Desktop.
Save nitrocode/007fce26f161aa0b74ec to your computer and use it in GitHub Desktop.
#!/bin/sh
# Usage:
# ./clone.sh TESTENV_TO_CLONE_DIR NEW_TEST_ENV_DIR
# ./clone.sh TESTENV08-HOST TESTENV03-HOST
# The above will clone 08 to 03 and register the vm
#
# * Do not end the argument directories with a slash!
# Date: Mar 10, 2015
DIR_DS=$(pwd)
cd $1
# clone vmdk and create vmdk and flat vmdk
vmkfstools -i "$1.vmdk" "$2.vmdk" -d thin -a buslogic
# create new directory
mkdir "../$2"
# moves created files to new directory
mv "$2-flat.vmdk" "../$2"
mv "$2.vmdk" "../$2"
# copies original vm's essential files and renames them
cp "$1.vmx" "../$2/$2.vmx"
cp "$1.vmxf" "../$2/$2.vmxf"
cp "$1.vmsd" "../$2/$2.vmsd"
cd "../$2"
# change all references in vmx from the cloned dir to the new dir
sed -i "s/$1/$2/g" "$2.vmx"
# Change this pesky variable to the correct one
sed -i 's,^\(scsi0:0.fileName = \).*,\1'\"$2.vmdk\"',' "$2.vmx"
# register vm
vim-cmd "solo/registervm $DIR_DS/$2/$2.vmx"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment