|
|
|
@ -36,12 +36,13 @@ usage() {
|
|
|
|
|
echo -e "\t-r ram size (in megabytes) *"
|
|
|
|
|
echo -e "\t-c number of vcpus"
|
|
|
|
|
echo -e "\t-b bridge to attach to *"
|
|
|
|
|
echo -e "\t-x network info (ip:netmask:gateway)"
|
|
|
|
|
echo -e "\t-x network info"
|
|
|
|
|
echo -e "(type:ip:netmask:gateway - type=eni/1, ip=dhcp or address, default eni dhcp)"
|
|
|
|
|
echo -e "\t-i distribution to use (see script for supported options) - default is stretch"
|
|
|
|
|
echo -e "\t-o OS type and variant (default: generic:generic - also set by distro option when available)"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while getopts "c:r:s:n:d:i:o:b:h" opt; do
|
|
|
|
|
while getopts "c:r:s:n:d:i:o:b:x:h" opt; do
|
|
|
|
|
case $opt in
|
|
|
|
|
c) cpucount=$OPTARG;;
|
|
|
|
|
r) ram=$OPTARG;;
|
|
|
|
@ -51,6 +52,7 @@ while getopts "c:r:s:n:d:i:o:b:h" opt; do
|
|
|
|
|
i) distro=$OPTARG;;
|
|
|
|
|
o) ostype=$OPTARG;;
|
|
|
|
|
b) bridge=$OPTARG;;
|
|
|
|
|
x) netinfo=$OPTARG;;
|
|
|
|
|
h) help="yes";;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
@ -62,6 +64,17 @@ if [[ -z $ram || -z $storage || -z $hostname || -z $domain || -z $bridge || $he
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ -f ${WORKING_DIR}/config ]]; then
|
|
|
|
|
source ${WORKING_DIR}/config
|
|
|
|
|
else
|
|
|
|
|
echo "Error: Missing ${WORKING_DIR}/config !"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ -f ${WORKING_DIR}/config.local ]]; then
|
|
|
|
|
source ${WORKING_DIR}/config.local
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ -z $distro ]]; then
|
|
|
|
|
distro="stretch"
|
|
|
|
|
fi
|
|
|
|
@ -70,6 +83,22 @@ if [[ -z $cpucount ]]; then
|
|
|
|
|
cpucount="2"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ -z $netinfo ]]; then
|
|
|
|
|
netinfo="eni:dhcp"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ ! -z $netinfo ]]; then
|
|
|
|
|
OIFS=${IFS}
|
|
|
|
|
IFS=:
|
|
|
|
|
read -ra $netinfo_config <<< "$netinfo"
|
|
|
|
|
virt_netinfo_type=${netinfo_config[0]}
|
|
|
|
|
virt_netinfo_address=${netinfo_config[1]}
|
|
|
|
|
virt_netinfo_netmask=${netinfo_config[2]}
|
|
|
|
|
virt_netinfo_gateway=${netinfo_config[3]}
|
|
|
|
|
IFS=${OIFS}
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [[ ! -z $ostype ]]; then
|
|
|
|
|
OIFS=${IFS}
|
|
|
|
|
IFS=:
|
|
|
|
@ -86,21 +115,25 @@ arch="amd64"
|
|
|
|
|
|
|
|
|
|
source distros
|
|
|
|
|
|
|
|
|
|
if [[ -f ${WORKING_DIR}/config ]]; then
|
|
|
|
|
source ${WORKING_DIR}/config
|
|
|
|
|
else
|
|
|
|
|
echo "Error: Missing ${WORKING_DIR}/config !"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ -f config.local ]]; then
|
|
|
|
|
source config.local
|
|
|
|
|
sed -e "s/%GUEST_NAME%/${hostname}/" ${WORKING_DIR}/meta-data > ${WORKING_DIR}/output/meta-data
|
|
|
|
|
sed -e "s/%FQDN%/${hostname}.${domain}/" ${WORKING_DIR}/user-data > ${WORKING_DIR}/output/user-data
|
|
|
|
|
|
|
|
|
|
if [[ ${virt_netinfo_type} == "eni" ]]; then
|
|
|
|
|
cat ${WORK_DIR}/network/legacy-eni >> ${WORK_DIR}/output/meta-data
|
|
|
|
|
if [[ ${virt_netinfo_address} == "dhcp" ]]; then
|
|
|
|
|
echo " iface eth0 inet dhcp" >> ${WORK_DIR}/output/meta-data
|
|
|
|
|
else
|
|
|
|
|
echo " iface eth0 inet static" >> ${WORK_DIR}/output/meta-data
|
|
|
|
|
echo " address ${virt_netinfo_address}" >> ${WORK_DIR}/output/meta-data
|
|
|
|
|
echo " netmask ${virt_netinfo_netmask}" >> ${WORK_DIR}/output/meta-data
|
|
|
|
|
echo " gateway ${virt_netinfo_gateway}" >> ${WORK_DIR}/output/meta-data
|
|
|
|
|
fi
|
|
|
|
|
elif [[ $virt_netinfo_type == "1" ]]; then
|
|
|
|
|
echo "Not implemented yet!"
|
|
|
|
|
elif [[ $virt_netinfo_type == "2" ]]; then
|
|
|
|
|
echo "Not implemented yet!"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
sed -e "s/%GUEST_NAME%/${hostname}/" meta-data > output/meta-data
|
|
|
|
|
sed -e "s/%FQDN%/${hostname}.${domain}/" user-data > output/user-data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [[ ! -f images/${IMG_NAME} ]]; then
|
|
|
|
|
echo "Downloading image ${IMG_NAME}..."
|
|
|
|
|
wget ${IMG_URL}/${IMG_NAME} -O images/${IMG_NAME}
|
|
|
|
|