Update vmcreate1.sh
This commit is contained in:
28
vmcreate1.sh
28
vmcreate1.sh
@@ -19,14 +19,14 @@ show_help(){
|
|||||||
echo 'Arguments:'
|
echo 'Arguments:'
|
||||||
echo '-h - show this help;'
|
echo '-h - show this help;'
|
||||||
echo '-a - add hosts to HA affinity rules;'
|
echo '-a - add hosts to HA affinity rules;'
|
||||||
echo "-k - embed custom public key or create new if `pub_keyfile` not specified"
|
echo "-k - embed custom public key or create new if 'pub_keyfile' not specified"
|
||||||
echo "-u - specify user instead of default `root`"
|
echo "-u - specify user instead of default 'root'"
|
||||||
echo "-p - specify password instead of default"
|
echo "-p - specify password instead of default"
|
||||||
echo "-d - add custom disk space (in gibibytes, integer). Default is 50."
|
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 "-t - add additional proxmox tag. Default is only pve node number."
|
||||||
echo "-f - get IP addresses and Hostnames from `flilename`;"
|
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 "\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`."
|
echo "In this case Hostname will be inherited from 2 last IP octets. Example for 10.10.35.20: 'vm035020'."
|
||||||
echo "IP address should be 10.10.*.*"
|
echo "IP address should be 10.10.*.*"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ while getopts "a:f:h" opt; do
|
|||||||
p) password="$OPTARG";;
|
p) password="$OPTARG";;
|
||||||
d) size="$OPTARG";;
|
d) size="$OPTARG";;
|
||||||
t) tag="$OPTARG";;
|
t) tag="$OPTARG";;
|
||||||
*) echo "Invalid option. Use `-h` for help."; exit 1;;
|
*) echo "Invalid option. Use '-h' for help."; exit 1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -56,16 +56,16 @@ if [[ -v username ]]; then echo "User: $file"; fi
|
|||||||
# Если файл не задан, но флаг есть
|
# Если файл не задан, но флаг есть
|
||||||
if [[ $# -eq 0 && -v "$file" && ! -e "$file" ]]; then
|
if [[ $# -eq 0 && -v "$file" && ! -e "$file" ]]; then
|
||||||
input=y
|
input=y
|
||||||
read -p "File `$file` does not exist. Use default `hosts` file? Y/n: " input
|
read -p "File $file does not exist. Use default 'hosts' file? Y/n: " input
|
||||||
case $input in
|
case $input in
|
||||||
y) file=hosts;;
|
y) file=hosts;;
|
||||||
Y) file=hosts;;
|
Y) file=hosts;;
|
||||||
n) read -p "Enter file name: " file;;
|
n) read -p "Enter file name: " file;;
|
||||||
N) read -p "Enter file name: " file;;
|
N) read -p "Enter file name: " file;;
|
||||||
*) echo "Use `-h` flag for help"; exit 0;;
|
*) echo "Use '-h' flag for help"; exit 0;;
|
||||||
esac
|
esac
|
||||||
if [[ ! -e "$file" ]]; then
|
if [[ ! -e "$file" ]]; then
|
||||||
echo "File `$file` does not exist. Exiting."
|
echo "File $file does not exist. Exiting."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -88,12 +88,12 @@ if [[ -e "$file" ]]; then
|
|||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
echo $line >> hosts.tmp
|
echo $line >> hosts.tmp
|
||||||
else
|
else
|
||||||
echo "Hostname `$hostname` is not valid. Should contain only letters, numbers and dash. Aborting."
|
echo "Hostname $hostname is not valid. Should contain only letters, numbers and dash. Aborting."
|
||||||
rm hosts.tmp
|
rm hosts.tmp
|
||||||
exit 3
|
exit 3
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "`$ip` is not a valid IPv4 address (10.10.*.*). Aborting."
|
echo "$ip is not a valid IPv4 address (10.10.*.*). Aborting."
|
||||||
rm hosts.tmp
|
rm hosts.tmp
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
@@ -112,7 +112,7 @@ if [[ $# -ne 0 ]]; then
|
|||||||
get_vmid "$arg" >> hosts.tmp
|
get_vmid "$arg" >> hosts.tmp
|
||||||
echo >> hosts.tmp
|
echo >> hosts.tmp
|
||||||
else
|
else
|
||||||
echo "Argument `$arg` is not a valid IPv4 address (10.10.*.*). Aborting."
|
echo "Argument $arg is not a valid IPv4 address (10.10.*.*). Aborting."
|
||||||
rm hosts.tmp
|
rm hosts.tmp
|
||||||
exit 5
|
exit 5
|
||||||
fi
|
fi
|
||||||
@@ -178,11 +178,11 @@ if [ -v pubkey ]; then
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
pubkey="key.pub"
|
pubkey="key.pub"
|
||||||
if [[ ! -e key.pub ]]; then echo "`key.pub` does not exist. Please use `-k` flag to specify public key."; exit 7; fi
|
if [[ ! -e key.pub ]]; then echo "key.pub does not exist. Please use '-k' flag to specify public key."; exit 7; fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
###DEBUG 1
|
###DEBUG 1
|
||||||
echo "File `hosts.tmp`:"
|
echo "File hosts.tmp:"
|
||||||
cat hosts.tmp; echo
|
cat hosts.tmp; echo
|
||||||
###
|
###
|
||||||
|
|
||||||
@@ -256,6 +256,6 @@ done
|
|||||||
rm hosts.tmp
|
rm hosts.tmp
|
||||||
if [ -v $privkey ]
|
if [ -v $privkey ]
|
||||||
then
|
then
|
||||||
echo "\nGenerated private key `$privkey`"
|
echo "\nGenerated private key: ./$privkey"
|
||||||
echo "SAVE IT IMMEDIATELY!!!"
|
echo "SAVE IT IMMEDIATELY!!!"
|
||||||
fi
|
fi
|
||||||
Reference in New Issue
Block a user