finalSH - AlphaOmega
finalSH - AlphaOmega
sh (ctrl x)
----------------------
#!/bin/bash
choice=10
while [ "$choice" -ne 0 ];
do
clear
echo -e " The ALL in One by Areeb"
echo -e "------------------------------------"
echo -e "Press 1 for Making a Network\n"
echo -e "Press 2 for Importing Backup(currently in trial)\n"
echo -e "Press 3 for Making Clone(NEW VMS) :\n"
echo -e "Press 4 for Changing Mac Addresses :\n"
echo -e "Press 5 for Deleting a VMs :\n"
echo -e "Press 6 for renaming a VMs :\n"
echo -e "Press 7 for Getting Macs of VMs :\n"
echo -e "Press 8 for cloning & assigning macs :\n"
echo -e "Press 9 for Getting old VMs Macs :\n"
echo -e "Press 10 for Converting Templete into VM:\n"
echo -e "Press 0 for exiting :\n"
echo -e "----------------------------------------\n"
read choice
if [[ choice -eq 1 ]];
then
clear
#!/bin/bash
echo " MAKING A NETWORK :"
# Define the bridge name and network interface to bridge
echo -n "Please enter Linux Bridge Name"
read BRIDGE_NAME
echo -n "Please Enter Default link Network"
read net
BRIDGE_IP="10.10.10.1/24"
EOL
fi
# Loop through the list of remote backup paths and transfer each file
for remote_backup_path in "${remote_backup_paths[@]}"; do
# Check if the backup file exists on the remote server
sshpass -p "$remote_password" ssh $remote_server "[ -f $remote_backup_path ]"
if [ $? -ne 0 ]; then
echo "Backup file $remote_backup_path does not exist on the remote server."
else
# Transfer the backup from the remote server to the local server using SCP
sshpass -p "$remote_password" scp $remote_server:$remote_backup_path
$local_server
# Check the SCP exit status to ensure the transfer was successful
if [ $? -eq 0 ]; then
echo "Backup file $remote_backup_path transferred successfully."
else
echo "Error transferring the backup file $remote_backup_path."
fi
fi
done
qmrestore "/var/lib/vz/dump/vzdump-qemu-9999-2023_10_30-15_02_18.vma.zst" 9999
qmrestore "/var/lib/vz/dump/vzdump-qemu-276-2023_10_30-15_03_20.vma.zst" 3000
echo "Press Enter to continue..."
read
fi
then
#!/bin/bash
clear
echo -e " MAKING CLONES"
echo -n "Enter starting id:"
read first_vm_id
echo -n "Enter ending id:"
read last_vm_id
echo -n "Enter which vm from you want to clone:"
read clone_id
echo -n "Enter your cloned vms names:"
read vm_name
echo -n "Enter Bot ID that you want to concatinate with vms names:"
read i
echo -e "Press "0" for full Cloning & "1" for link Cloning "
read g
if [[ g -eq 0 ]];
then
for ((st=first_vm_id; st<=last_vm_id; st++,i++)); do
qm start $st
done
clear
echo"Yours New Mac Addresses are !!!!!!!"
then
#!/bin/bash
clear
echo -e " CHANGING MAC ADDRESSES"
echo "All MAC addresses have been reset for VMs connected to $common_bridge within
the specified range."
qm shutdown $st
done
qm start $st
done
echo "Press Enter when all vms are started to continue..."
read
fi
done
echo "Press Enter to continue..."
read
clear
fi
if [[ choice -eq 7 ]];
then
clear
#!/bin/bash
echo -e " GETTING MACS OF THE VMS"
# Ask for the first and last VM IDs
read -p "Enter the first VM ID: " first_vm_id
read -p "Enter the last VM ID: " last_vm_id
# Debugging output
echo "Assigning MAC address $mac_address to VM ID $vm_id"
# Append the new line with the specified MAC address for net0
echo "net0: e1000=$mac_address,bridge=$network_bridge" >> "$vm_config"
# Cloning VMs
clear
echo -e " MAKING CLONES"
echo -n "Enter starting id:"
read first_vm_id
echo -n "Enter ending id:"
read last_vm_id
echo -n "Enter which vm from you want to clone:"
read clone_id
echo -n "Enter your cloned vms names:"
read vm_name
echo -n "Enter Bot ID that you want to concatenate with vms names:"
read i
echo -n "please enter network bridge from network"
read n
echo -e "Press '0' for full Cloning & '1' for link Cloning "
read g
case $g in
0)
for ((st=first_vm_id; st<=last_vm_id; st++,i++)); do
qm clone $clone_id $st --full=True --name="$vm_name-$i"
# Call function to assign MAC addresses after each cloning
assign_mac_addresses "$n" # Pass the network bridge value to the
function
done
;;
1)
for ((st=first_vm_id; st<=last_vm_id; st++,i++)); do
qm clone $clone_id $st --full=false --name="$vm_name-$i"
# Call function to assign MAC addresses after each cloning
assign_mac_addresses "$n" # Pass the network bridge value to the
function
done
;;
*)
echo "Invalid option selected. Please select '0' or '1'."
;;
esac
fi
if [[ choice -eq 9 ]];
then
clear
#!/bin/bash
echo -e " GETTING MACS OF THE VMS in Mac.txt"
rm mac.txt
# Output file
OUTPUT_FILE="mac.txt"
# Loop through the range of VM IDs and get MAC addresses, and store in the output
file
for ((vm_id = first_vm_id; vm_id <= last_vm_id; vm_id++)); do
# Define the path to the VM configuration file
vm_config="/etc/pve/qemu-server/$vm_id.conf"
# Open the VM config file and remove the "template: 1" line
sed -i '/^template: 1$/d' "$vm_config"