Update vmcreate1.sh

This commit is contained in:
2025-10-26 20:52:22 +00:00
parent 50ee844628
commit 5a795e1c0b

View File

@@ -12,6 +12,21 @@ mkdir $path #REMOVE AFTER CORRECT PATH!!!!!!!!
node=3
size=50
# Далее объявляю переменные, в цикле getopts это не получается
harule=""
use_harule=false
pubkey=""
use_pubkey=false
username=""
use_username=false
password=""
use_password=false
tag=""
use_tag=false
file=""
use_file=false
# Конец костыля
show_help () {
echo
echo 'Usage:'
@@ -101,14 +116,14 @@ mksnippet () {
# Обрабатываем опции
while getopts "a:f:hk:u:p:d:t:" opt; do
case $opt in
a) harule=${OPTARG};;
f) file=${OPTARG};;
a) harule=${OPTARG}; use_harule=true;;
f) file=${OPTARG}; use_file=true;;
h) show_help; exit 0;;
k) pubkey=${OPTARG};;
u) username=${OPTARG};;
p) password=${OPTARG};;
k) pubkey=${OPTARG}; use_pubkey=true;;
u) username=${OPTARG}; use_username=true;;
p) password=${OPTARG}; use_password=true;;
d) size=${OPTARG};;
t) tag=${OPTARG};;
t) tag=${OPTARG}; use_tag=true;;
\?) echo "Invalid option."; show_help; exit 1;;
esac
done
@@ -152,12 +167,12 @@ if ! [[ $size -ge 10 && $size -le 500 ]]; then echo "Disk size increment shoud b
# Создаём hosts.tmp из аргументов/файла, попутно проверяя данные
# Если заданы И аргументы, И файл - сразу нахуй
if [[ $# -ne 0 && -v $file ]]; then
if [[ $# -ne 0 && $use_file ]]; then
echo "Please use EITHER file OR arguments. Use '-h' flag for help"
exit 3
else
# Если файл задан
if [[ -v $file ]]; then
if $use_file; then
# Но не существует, то нахуй
if [[ ! -e "$file" ]];then
echo "File $file does not exist. Aborting."
@@ -217,7 +232,7 @@ fi
# Закончили с вводными данными
# Проверяем ключ
if [[ -v $pubkey ]]; then
if $use_pubkey; then
if ! [[ -e "$pubkey" ]]; then
input=y
echo "You sbecified public key but it does not exist. Generate new pair? y/n"
@@ -301,7 +316,7 @@ do
exit 102
###
# qm start $vmid ВРЕМЕННО ОТКЛЮЧЕНО
if [ -v harule ]; then
if $use_harule; then
ha-manager add vm:$vmid --state started --max_relocate 2
ha-manager rules add node-affinity $harule --resources vm:$vmid --nodes pve1,pve2,pve3 --strict 1
echo "HA rule added"