Skip to content

Commit

Permalink
Sociois: Updated to the latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
Anilkumar18 committed May 18, 2022
1 parent 762472e commit 4428f27
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 37 deletions.
69 changes: 46 additions & 23 deletions lib/create_vm.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,67 @@
#!/bin/bash
MACHINENAME="socios_vm_test"
#Disk_location="/tmp/socios/$Server_name.vdi"
#Image_file="/tmp/socios/ubuntu.iso"
if [ -d socios ]; then
rm -rf socios
fi
mkdir -p socios
chmod -R 755 socios

echo "Copying the ISO Image to Root Path"

cp /tmp/socios/ubuntu.iso socios

# Destination to save the VDI File
DESTINATION=socios/VirtualBoxVMs
ISO=socios

# List available Guest OS on MAC Machine
echo "Available Guest OS on MAC Machine "
VBoxManage list ostypes | grep -i ubuntu

echo "Enter the VM name: "
read MACHINENAME

#Creating virtual machine
echo "Creating a $MACHINENAME virtual machine"
vboxmanage createvm --name $MACHINENAME --ostype "Ubuntu_64" --register --basefolder `pwd`
vboxmanage createvm --name $MACHINENAME --ostype "Ubuntu_64" --register --basefolder $DESTINATION

#Set memory and network
echo "Setting up the memory and network for created $MACHINENAME virtual machine"
VBoxManage modifyvm $MACHINENAME --ioapic on
VBoxManage modifyvm $MACHINENAME --memory 4096
vboxmanage modifyvm $MACHINENAME --vram 128
vboxmanage modifyvm $MACHINENAME --vram 256
VBoxManage modifyvm $MACHINENAME --nic1 nat
vboxmanage modifyvm $MACHINENAME --cpus 4
vboxmanage modifyvm $MACHINENAME --graphicscontroller VMSVGA

diskutil list
echo "Select the partition disk to install the OS"

read -p "Provide the disk space want to use for Linux OS: " disk_input

disk=$(/dev/"$disk_input")
echo "Enter the storage size"
read -p "Enter the storage size in GB in numerals:" gb
size=`expr $gb \* 1024`

#Create Disk and connect Debian Iso
# VBoxManage createhd --filename `pwd`/$MACHINENAME/$MACHINENAME.vdi --size 40000 --format VDI
VBoxManage internalcommands createrawvmdk -filename `pwd`/"$MACHINENAME"/$MACHINENAME.vmdk -rawdisk disk
VBoxManage modifyvm "$MACHINENAME" --boot1 dvd --boot2 disk --boot3 none
echo "Creating Virtual Hard Disk"
VBoxManage createhd --filename $DESTINATION/$MACHINENAME/$MACHINENAME.vdi --size $size --format VDI --variant Standard

#Add Storage Controller to Virtual Machine
VBoxManage storagectl $MACHINENAME --name "SATA Controller" --add sata --bootable on

#Configuration of virtual hard_disk
VBoxManage storagectl "$MACHINENAME" --name "SATA Controller" --add sata --controller IntelAhci
VBoxManage storageattach $MACHINENAME --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium `pwd`/$MACHINENAME/$MACHINENAME_DISK.vdi
#Attach Virtual Hard Disk to Virtual Storage Controller
VBoxManage storageattach $MACHINENAME --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium $DESTINATION/$MACHINENAME/$MACHINENAME.vdi

#Configuration of ISO_image
#Add IDE Controller to Virtual Machine (To Later Connect ISO/CD/DVD)
VBoxManage storagectl $MACHINENAME --name "IDE Controller" --add ide --controller PIIX4
VBoxManage storageattach $MACHINENAME --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium `pwd`/ubuntu.iso

#Enable RDP
VBoxManage modifyvm $MACHINENAME --vrde on
VBoxManage modifyvm $MACHINENAME --vrdemulticon on --vrdeport 10001
#Resize virtual machine (VDI and VHD)
#VBoxManage modifyhd "$DESTINATION/$MACHINENAME/$MACHINENAME.vdi" −−resize 40000
#This changes the size of the virtual hard drive to 40000 MB

#Attach ISO_image
VBoxManage storageattach $MACHINENAME --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium $ISO/ubuntu.iso

#Start the Virtual Machine in Headless Mode
VBoxManage startvm $MACHINENAME

#Resize the Virtualbox in VM
VBoxManage setextradata "$MACHINENAME" GUI/ScaleFactor 2.5

#Start the VM
VBoxHeadless --startvm $MACHINENAME
echo "ISO image booted in Virtualbox.... Start setup process"
21 changes: 13 additions & 8 deletions lib/disk_partition.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,31 @@ target_disk=$(diskutil list | awk '/Apple_APFS/ {print $7}')

echo "$target_disk"
default_disk=$target_disk
default_size='40g'
default_size=40

read -p "Click Yes to use the default disk for the partition, No to select custom disk (Yes\No):" choice

case "$choice" in
Yes|yes|"") Input=1;;
No|no) Input=0;;
* ) { echo "Invalid option. Plesase select the correct option."; exit 1; };;
esac

No|no) Input=0;;
if [ $Input == 1 ]
then
echo "Resizing the APFS container for partition $default_disk $default_size"
diskutil apfs resizeContainer $default_disk $default_size
echo "Resizing the APFS container for partition named New_volume $default_disk $default_size"
read -p "Provide the total space you find on the left side of the $target_disk in numerals(eg:100 for 100GB): " total_space
crct_default_space="$(echo $total_space - $default_size | bc)"
diskutil apfs resizeContainer "$default_disk" "$crct_default_space""g" jhfs+ New_volume "$default_size""g"
else
diskutil list
echo "Provide the disk space want to use for the above list."
read -p "Provide the disk space want to use for Linux OS: " disk_input
read -p "Provide the disk space want to allocate for Linux OS in GB(e.g:30g): " size_input
diskutil apfs resizeContainer "$disk_input" "$size_input"
read -p "Provide the APFS container identifier you want to use for Linux OS(e.g:disk0s2): " disk_input
read -p "Provide the total space you find on the left side of the provided identifier in numerals(eg:100 for 100GB): " total_space
read -p "Provide a name for the volume of your wish: " name
read -p "Provide the disk space want to allocate for Linux OS in numerals(e.g:30 for 30GB): " size_input
crct_space="$(echo $total_space - $size_input | bc)"
diskutil apfs resizeContainer "$disk_input" "$crct_space""g" jhfs+ "$name" "$size_input""g"
fi

disk=$(/dev/"$disk_input")
Expand All @@ -41,4 +46,4 @@ $target_disk# GB boot parttion
p # print the in-memory partition table
w # write the partition table
q # and we're done
EOF
EOF
2 changes: 0 additions & 2 deletions lib/install_virtualbox.scpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ printf "Analyzing system application environment. Wait...\n" && sleep 2
if osascript -e 'id of application "virtualbox" ' >/dev/null 2>&1; then
printf "%s\n" "VirtualBox is available."
source $Cellar/*/lib/image.sh
source $Cellar/*/lib/disk_partition.sh
else
printf "%s\n" "VirtualBox yet not installled. Need to install it."
read -p "Click Yes to install VirtualBox, No to end the process(Yes\No):" choice
Expand All @@ -19,7 +18,6 @@ if [ $vmInput == 1 ]; then
brew install --cask virtualbox
brew install --cask gdisk
source $Cellar/*/lib/image.sh
source $Cellar/*/lib/disk_partition.sh
fi

if [ $vmInput == 0 ]; then
Expand Down
15 changes: 11 additions & 4 deletions socios
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ function createvm {

#Uninstalling VirtualBox_VM

function unmount {
source $Cellar/*/lib/disk_partition.sh
}

#Uninstalling VirtualBox_VM

function purge {
source $Cellar/*/lib/purge.sh
}
Expand All @@ -23,14 +29,12 @@ function purge {

function help {
echo "Socios - Linux with your Mac."
echo "Usage: socios [options...]"
echo
echo "Valid options are:"
echo "build Create the virtual machine in VirtualBox"
echo "init Check the environment to install Socios"
echo "--help Print this Help menu"
echo "--version Print the current version"
echo "purge Uninstall the Virtualbox and GDisk"
echo "unmount unmount the current disk space in MAC Machine"
echo "purge Uninstall the Virtualbox and GDisk"
}

#Version of Socios formula
Expand All @@ -57,6 +61,9 @@ for arg in "$@"; do
if [[ "$arg" = --version ]]; then
version
fi
if [[ "$arg" = unmount ]]; then
unmount
fi
if [[ "$arg" = purge ]]; then
purge
fi
Expand Down

0 comments on commit 4428f27

Please sign in to comment.