Update vmcreate1.sh
This commit is contained in:
18
vmcreate1.sh
18
vmcreate1.sh
@@ -16,7 +16,7 @@ size=50
|
||||
|
||||
show_help()
|
||||
echo 'Usage:'
|
||||
echo 'vmcreate [-h][-a rule_name][-k pub_keyfile][-u][-p][-d 50][-f filename]'
|
||||
echo 'vmcreate [-h][-a rule_name][-k pub_keyfile][-u][-p][-d 50][-t][-f filename]'
|
||||
echo 'Arguments:'
|
||||
echo '-h - show this help;'
|
||||
echo '-a - add hosts to HA affinity rules;'
|
||||
@@ -24,6 +24,7 @@ show_help()
|
||||
echo "-u - specify user instead of default `root`"
|
||||
echo "-p - specify password instead of default"
|
||||
echo "-d - add custom disk space (in gibibytes, integer). Default is 50."
|
||||
echo "-t - add additional proxmox tag. Default is only pve node number."
|
||||
echo "-f - get IP addresses and Hostnames from `flilename`;"
|
||||
echo "\nIf file not specified, script will use arguments as a list of IP addresses."
|
||||
echo "In this case Hostname will be inherited from 2 last IP octets. Example for 10.10.35.20: `vm035020`."
|
||||
@@ -39,11 +40,12 @@ while getopts "a:f:h" opt; do
|
||||
k) pubkey="$OPTARG";;
|
||||
u) username="$OPTARG";;
|
||||
p) password="$OPTARG";;
|
||||
d) size="$OPTARG"; ;;
|
||||
d) size="$OPTARG";;
|
||||
t) tag="$OPTARG";;
|
||||
# *) noopts=true
|
||||
esac
|
||||
done
|
||||
if [[ size >= 10 && size <= 500 ]]; then echo "Disk size increment shoud be in range of 10..500. Aborting."
|
||||
if [[ size >= 10 && size <= 500 ]]; then echo "Disk size increment shoud be in range of 10..500. Aborting."; exit 1; fi
|
||||
# Вывод переменных для дебага:
|
||||
if [[ -v file ]]; then echo "File: $file"; fi
|
||||
if [[ -v pubkey ]]; then echo "Public key: $pubkey"; fi
|
||||
@@ -116,7 +118,7 @@ fi
|
||||
ipcheck() {
|
||||
local ip=$1
|
||||
local stat=1
|
||||
oldIFS=$IFS
|
||||
#oldIFS=$IFS
|
||||
# Check if the IP matches the general IPv4 pattern
|
||||
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||||
# Split the IP into octets
|
||||
@@ -127,7 +129,7 @@ ipcheck() {
|
||||
fi
|
||||
fi
|
||||
return $stat
|
||||
IFS=$oldIFS
|
||||
#IFS=$oldIFS
|
||||
}
|
||||
|
||||
# Функция для проверки hostname на валидные символы (буквы, цифры, дефис)
|
||||
@@ -203,10 +205,10 @@ do
|
||||
then echo "OK"
|
||||
else "ERROR"; exit 8
|
||||
fi
|
||||
qm set $vmnum --tags $node,gfx
|
||||
qm resize $vmnum scsi0 +50G
|
||||
qm set $vmnum --tags $node,$tag
|
||||
qm resize $vmnum scsi0 +"$size"G
|
||||
qm set $vmnum --cicustom "user=${storage}:snippets/${vmnum}_user.yaml"
|
||||
qm set $vmnum --ipconfig0 ip=$ip/24,gw=10.10.35.1
|
||||
qm set $vmnum --ipconfig0 ip="$ip"/"$mask",gw="$gw"
|
||||
qm cloudinit update $vmnum
|
||||
qm start $vmnum
|
||||
if [ -v harule ]
|
||||
|
||||
Reference in New Issue
Block a user