Update vmcreate1.sh

This commit is contained in:
2025-10-26 17:58:10 +00:00
parent a11b285216
commit e0591eee5e

View File

@@ -14,7 +14,6 @@ mkdir $path #REMOVE AFTER CORRECT PATH!!!!!!!!
node=3 node=3
size=50 size=50
file="hosts" file="hosts"
pubkey="pub.key"
show_help(){ show_help(){
echo 'Usage:' echo 'Usage:'
@@ -94,7 +93,9 @@ mksnippet (){
phash=$(cat $password | mkpasswd -m sha-256 -s) phash=$(cat $password | mkpasswd -m sha-256 -s)
sed -i "s|.*password.*| - ${phash}|" "$snippet" sed -i "s|.*password.*| - ${phash}|" "$snippet"
fi fi
sed -i "s|.*ssh-rsa.*| - (cat ${pubkey})|" "$snippet" if [[ -v $pubkey]]; then
sed -i "s|.*ssh-rsa.*| - (cat ${pubkey})|" "$snippet"
fi
echo "Snippet $snippet created" echo "Snippet $snippet created"
} }
@@ -198,19 +199,39 @@ if [[ $# -ne 0 ]]; then
fi fi
# Проверяем ключ # Проверяем ключ
if [[ ! -e "$pubkey" ]]; then if [[ -v $pubkey ]]; then
input=y if ! [[ -e "$pubkey" ]]; then
echo "Public key does not exist. Generate new pair? y/n" input=y
read input echo "You sbecified public key but it does not exist. Generate new pair? y/n"
case $input in read input
y) read -p "Enter name for your PRIVATE key: " privkey && keypair_generate "$privkey";; case $input in
Y) read -p "Enter name for your PRIVATE key: " privkey && keypair_generate "$privkey";; y) read -p "Enter name for your PRIVATE key: " privkey && keypair_generate "$privkey";;
n) echo "Public key is necessary to continue. Please specify or generate new pair."; exit 6;; Y) read -p "Enter name for your PRIVATE key: " privkey && keypair_generate "$privkey";;
N) echo "Public key is necessary to continue. Please specify or generate new pair."; exit 6;; n) echo "Public key is necessary to continue. Please use default, specify or generate new pair."; exit 6;;
*) echo "Use '-h' flag for help"; exit 6;; N) echo "Public key is necessary to continue. Please use default, specify or generate new pair."; exit 6;;
esac *) echo "Use '-h' flag for help"; exit 6;;
esac
fi
else
read -p "Public key not specified. Use default? Enter to continue or Ctrl+C to abort"
fi fi
# Проверяем, что нет ВМ в списке и нет сниппетов
for line in $(cat hosts.tmp)
do
ip=$(echo -n "$line" | cut -d ',' -f 1)
vmid=$(get_vmid "$ip")
snippet=
if [[ (qm status "$vmid") ]]; then
echo "VM $vmid exists. Aborting"
exit 9
elif [[ -e "$snippet" ]]; then
echo "Snippet $snippet exists. Aborting"
exit 9
fi
done
###DEBUG 1 ###DEBUG 1
echo "DEBUG File hosts.tmp:" echo "DEBUG File hosts.tmp:"
cat hosts.tmp; echo cat hosts.tmp; echo