Skip to content

Instantly share code, notes, and snippets.

@itskenny0
Created September 1, 2017 04:17
Show Gist options
  • Save itskenny0/aa70feb97fc80e4b8ee559fd2011d140 to your computer and use it in GitHub Desktop.
Save itskenny0/aa70feb97fc80e4b8ee559fd2011d140 to your computer and use it in GitHub Desktop.
#!/bin/bash
CYAN=$(echo -ne "\033[00;36m")
GREEN=$(echo -en '\033[01;32m')
MAG=$(echo -en '\033[01;35m')
YEL=$(echo -en '\033[00;33m')
NOCOL=$(echo -ne "\E[0m")
CREATED=$(date)
cd /vz
read -ep "${GREEN}VM name (e.g. tizi.cloud, n8gs.redis): ${NOCOL}" VMNAME
read -ep "${GREEN}RAM size in megabyte: ${NOCOL}" RAM
read -ep "${GREEN}Amount of CPU cores: ${NOCOL}" CPU
echo; echo "${MAG}[+] Creating new VM with parameters:${NOCOL} $VMNAME | $CPU CPUs | $RAM MB RAM"; echo
# NOGRAPHIC CONFIG
CFGTARGET=conf/$VMNAME.nographic.sh
echo -n "${CYAN}[+] Copying nographic config (TEMPLATE => $VMNAME.nographic.sh) ... ${NOCOL}"
cp conf/TEMPLATE $CFGTARGET && echo "OK"; echo
echo -n "${CYAN}[+] Filling out nographic config ... ${NOCOL}"
sed -i "s/_VM_/$VMNAME/" $CFGTARGET
sed -i "s/_CPU_/$CPU/" $CFGTARGET
sed -i "s/_RAM_/$RAM/" $CFGTARGET
sed -i "s/_CREATED_/$CREATED/" $CFGTARGET
sed -i "s/_GRAPHIC_/-nographic/" $CFGTARGET
echo "OK"; echo
# END NOGRAPHIC CONFIG
# MOBAXTERM CONFIG
MCFGTARGET=conf/$VMNAME.mobaXt.sh
echo -n "${CYAN}[+] Copying mobaXterm config (TEMPLATE => $VMNAME.mobaXt.sh) ... ${NOCOL}"
cp conf/TEMPLATE $MCFGTARGET && echo "OK"; echo
echo -n "${CYAN}[+] Filling out mobaXterm config ... ${NOCOL}"
sed -i "s/_VM_/$VMNAME/" $MCFGTARGET
sed -i "s/_CPU_/$CPU/" $MCFGTARGET
sed -i "s/_RAM_/$RAM/" $MCFGTARGET
sed -i "s/_CREATED_/$CREATED/" $MCFGTARGET
sed -i "s/_GRAPHIC_//" $MCFGTARGET
echo "OK"; echo
# END MOBAXTERM CONFIG
# HDD CLONE
echo "${CYAN}[+] Cloning HDD template ... ${NOCOL}"
rsync --progress disk/TPL-Ubuntu1604-prod.qcow2 disk/$VMNAME.qcow2
echo " ${GREEN}--> rsync finished.${NOCOL}"
echo
echo
# END HDD CLONE
# SUPERVISOR CONFIG
SVTARGET=/etc/supervisor/conf.d/VM-$VMNAME.conf
echo -n "${CYAN}[+] Copying supervisor config (TEMPLATE => VM-$VMNAME.conf) ... ${NOCOL}"
cp /etc/supervisor/conf.d/TEMPLATE $SVTARGET && echo "OK"; echo
echo -n "${CYAN}[+] Filling out supervisor config ... ${NOCOL}"
sed -i "s/_VM_/$VMNAME/" $SVTARGET && echo "OK"; echo
# SUPERVISOR CONFIG
echo
echo "${YEL}New VM created!"
echo "The VM still requires setup. Please run using MobaXterm:${NOCOL} /vz/conf/$VMNAME.mobaXt.sh"
echo "${YEL}Once the VM has been configured and joined into ZeroTier, update supervisor:${NOCOL} supervisorctl update"
echo "${GREEN}This should conclude the VM setup.${NOCOL}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment