Update qmcreate.sh

This commit is contained in:
2025-10-22 15:27:27 +00:00
parent 5e3030ac8f
commit 3f8e7b6927

View File

@@ -1,13 +1,9 @@
#!/bin/bash #!/bin/bash
while read line while read line
do do
#echo $line
ip=$(echo $line | cut -d ' ' -f 1) ip=$(echo $line | cut -d ' ' -f 1)
#echo "IP address: $ip"
hostname=$(echo $line | cut -d ' ' -f 2) hostname=$(echo $line | cut -d ' ' -f 2)
#echo "Hostname: $hostname"
vmnum=35$(echo $ip | cut -d '.' -f 4) vmnum=35$(echo $ip | cut -d '.' -f 4)
#echo "VM number: $vmnum"
qm clone 5000 $vmnum --name $hostname --full qm clone 5000 $vmnum --name $hostname --full
if [ $? -eq 0 ] if [ $? -eq 0 ]
then echo "clone OK" then echo "clone OK"
@@ -16,22 +12,14 @@ do
qm set $vmnum --tags 3,gfx qm set $vmnum --tags 3,gfx
## preparing custom CloudInit snippets ## preparing custom CloudInit snippets
cp ./user.yaml /mnt/pve/syno-tigra/snippets/${vmnum}_user.yaml cp ./user.yaml /mnt/pve/syno-tigra/snippets/${vmnum}_user.yaml
#cp ./network.yaml /mnt/pve/syno-tigra/snippets/${vmnum}_network.yaml
sed -i "s/HOSTNAME/$hostname/g" /mnt/pve/syno-tigra/snippets/${vmnum}_user.yaml sed -i "s/HOSTNAME/$hostname/g" /mnt/pve/syno-tigra/snippets/${vmnum}_user.yaml
#sed -i "s/IP/$ip/g" /mnt/pve/syno-tigra/snippets/${vmnum}_network.yaml
#mac=$(cat /etc/pve/qemu-server/${vmnum}.conf | grep net0 | cut -d ',' -f 1 | cut -d '=' -f 2)
#sed -i "s/MAC/$mac/g" /mnt/pve/syno-tigra/snippets/${vmnum}_network.yaml
if [ -e "./gfx.pub" ] if [ -e "./gfx.pub" ]
then echo "key OK" then echo "key OK"
else echo "key ERROR. Put the public key named 'gfx.pub'"; exit 2 else echo "key ERROR. Put the public key named 'gfx.pub'"; exit 2
fi fi
qm resize $vmnum scsi0 +50G qm resize $vmnum scsi0 +50G
qm set $vmnum --cicustom "user=syno-tigra:snippets/${vmnum}_user.yaml" --sshkey ./gfx.pub qm set $vmnum --cicustom "user=syno-tigra:snippets/${vmnum}_user.yaml"
qm set $vmnum --ipconfig0 ip=$ip/24,gw=10.10.35.1 qm set $vmnum --ipconfig0 ip=$ip/24,gw=10.10.35.1
qm cloudinit update $vmnum qm cloudinit update $vmnum
qm start $vmnum qm start $vmnum
#if [ $? -eq 0 ]
# then echo "VM successfully CREATED"
# else "ERROR creating VM"; exit 3
# fi
done < ./hosts done < ./hosts