Tons of changes :)
This commit is contained in:
parent
3423cb18cb
commit
855a980df3
20
_vms.conf
20
_vms.conf
|
@ -1,14 +1,24 @@
|
||||||
SERVER="server1
|
# Server config for install-<mac>.conf
|
||||||
|
SERVER="server1"
|
||||||
DOMAIN="example.com"
|
DOMAIN="example.com"
|
||||||
|
# IP / MAC config
|
||||||
|
IP_PREFIX="46.23.92"
|
||||||
|
IP_START=170
|
||||||
|
IPV6_PREFIX="2a03:6000:9210"
|
||||||
|
IPV6_START=9200
|
||||||
|
MAC_PREFIX="fe:e1:bb:d4:c3"
|
||||||
|
# .conf locations
|
||||||
|
VMS="."
|
||||||
ETC="."
|
ETC="."
|
||||||
IMG="."
|
IMAGES="."
|
||||||
HTDOCS="."
|
HTDOCS="."
|
||||||
VMDUSERS="vmdusers"
|
# vm.conf
|
||||||
|
VMDUSERS="_vmdusers"
|
||||||
UPLINK="uplink_vlan42"
|
UPLINK="uplink_vlan42"
|
||||||
BRIDGE="bridge42"
|
BRIDGE="bridge42"
|
||||||
ROUTER="192.168.1.1
|
# dhcpd.conf
|
||||||
|
ROUTER="192.168.1.1"
|
||||||
DNS="192.186.1.3"
|
DNS="192.186.1.3"
|
||||||
SUBNET="192.168.1.0"
|
SUBNET="192.168.1.0"
|
||||||
NETMASK="255.255.255.0"
|
NETMASK="255.255.255.0"
|
||||||
RANGE="192.168.1.32 192.168.1.127"
|
RANGE="192.168.1.32 192.168.1.127"
|
||||||
|
|
||||||
|
|
140
deploy.sh
140
deploy.sh
|
@ -3,21 +3,30 @@
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
|
|
||||||
# CONF_FILE "_vms.conf" needs to have the following variables:
|
# CONF_FILE "_vms.conf" needs to have the following variables:
|
||||||
#ROUTER="192.168.0.1"
|
## Server config for install-<mac>.conf
|
||||||
#DNS="192.168.0.1"
|
|
||||||
#SERVER="server1"
|
#SERVER="server1"
|
||||||
#DOMAIN="example.com"
|
#DOMAIN="example.com"
|
||||||
|
## IP / MAC config
|
||||||
|
#IP_PREFIX="192.168.0"
|
||||||
|
#IP_START=100
|
||||||
|
#IPV6_PREFIX="fe1:dead:beef"
|
||||||
|
#IPV6_START=1000
|
||||||
|
#MAC_PREFIX="fe:1e:bb:4d:3c"
|
||||||
|
## .conf locations
|
||||||
|
#VMS="/root/vms"
|
||||||
#ETC="/etc"
|
#ETC="/etc"
|
||||||
#IMG="/var/vmm"
|
#IMAGES="/var/vmm"
|
||||||
#HTDOCS="/var/www/htdocs"
|
#HTDOCS="/var/www/htdocs"
|
||||||
|
## vm.conf
|
||||||
#VMDUSERS="vmdusers"
|
#VMDUSERS="vmdusers"
|
||||||
#UPLINK="uplink_vlan42"
|
#UPLINK="uplink_vlan42"
|
||||||
#BRIDGE="bridge42"
|
#BRIDGE="bridge42"
|
||||||
|
## dhcpd.conf
|
||||||
#ROUTER="192.168.0.1"
|
#ROUTER="192.168.0.1"
|
||||||
#DNS="192.168.0.1"
|
#DNS="192.186.0.1"
|
||||||
#SUBNET="192.168.0.0"
|
#SUBNET="192.168.0.1"
|
||||||
#NETMASK="255.255.255.0"
|
#NETMASK="255.255.255.0"
|
||||||
#RANGE="192.168.0.10 192.168.0.10"
|
#RANGE="192.168.1.10 192.168.1.10"
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
@ -29,7 +38,7 @@ main () {
|
||||||
echo "New config files created for $SERVER @ $date"
|
echo "New config files created for $SERVER @ $date"
|
||||||
|
|
||||||
fs=$(
|
fs=$(
|
||||||
list_files
|
list_files "$VMS"
|
||||||
)
|
)
|
||||||
|
|
||||||
if test -n "$fs"
|
if test -n "$fs"
|
||||||
|
@ -37,10 +46,10 @@ main () {
|
||||||
echo "$fs"
|
echo "$fs"
|
||||||
|
|
||||||
echo "$fs" |
|
echo "$fs" |
|
||||||
render_vm_conf >> "${ETC}/vm.conf"
|
render_vm_conf > "${ETC}/vm.conf"
|
||||||
|
|
||||||
echo "$fs" |
|
echo "$fs" |
|
||||||
render_dhcpd_conf >> "${ETC}/dhcpd.conf"
|
render_dhcpd_conf > "${ETC}/dhcpd.conf"
|
||||||
|
|
||||||
echo "$fs" |
|
echo "$fs" |
|
||||||
render_install_conf
|
render_install_conf
|
||||||
|
@ -51,16 +60,62 @@ main () {
|
||||||
echo "$fs" |
|
echo "$fs" |
|
||||||
create_users
|
create_users
|
||||||
fi
|
fi
|
||||||
|
|
||||||
restart_service
|
|
||||||
}
|
}
|
||||||
|
|
||||||
list_files() {
|
list_files() {
|
||||||
find . -type f -name "vm*.txt" -maxdepth 1 | sort | xargs awk '/message/ { print FILENAME }'
|
# Find all the VM config files.
|
||||||
|
# Takes the directory with vm*.txt files.
|
||||||
|
find "$1" -type f -name "vm*.txt" -maxdepth 1 | sort | xargs grep -l "message"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
find_vm() {
|
||||||
|
# Find the number of the VM (VM#).
|
||||||
|
# Takes the directory with vm*.txt files and instance name as variable.
|
||||||
|
find "$1" -type f -name "vm*.txt" -maxdepth 1 | xargs grep -l "$2" | sed 's/^\.\/vm//;s/\.txt$//'
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch_mac() {
|
||||||
|
# Fetch the MAC address for the VM.
|
||||||
|
# Takes the MAC_PREFIX and VM#.
|
||||||
|
# print the MAC address
|
||||||
|
echo "${1}:${2}"
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch_ip() {
|
||||||
|
# Fetch the IP address for the VM.
|
||||||
|
# Takes the IP_PREFIX, IP_START and VM#.
|
||||||
|
# add IP_START and VM# and print the IP address
|
||||||
|
# print the IP address
|
||||||
|
_prefix=$1
|
||||||
|
_host=$(($2 + $3))
|
||||||
|
echo "${_prefix}.${_host}"
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch_ipv6() {
|
||||||
|
# Fetch the IPv6 address of the VM.
|
||||||
|
# Takes the IPV6_PREFIX, IPV6_START, IP_START and VM#
|
||||||
|
# add IPV6_START and VM#, IP_START and VM# and print the IPv6 address
|
||||||
|
# print the IPv6 address
|
||||||
|
_prefix=$1
|
||||||
|
_subnet=$(($2 + $4))
|
||||||
|
_host=$(($3 + $4))
|
||||||
|
echo "${_prefix}:${_subnet}::${_host}"
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_passwd() {
|
||||||
|
# Generate a random password for the install-<MAC>.conf file.
|
||||||
|
# Doesn't take variables.
|
||||||
|
tr -cd '[:print:]' < /dev/urandom | fold -w 20 | head -n 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
render_vm_conf() {
|
render_vm_conf() {
|
||||||
printf "#\\n# File generated on %s\\n#\\n" "$date" > "${IMG}/vm.conf"
|
# Generate vm.comf
|
||||||
|
# Takes defaults from of _vms.conf and iterate over the vm*.txt files.
|
||||||
|
# When the owner exists add "owner".
|
||||||
|
# When the VM image doesn't exist add "boot".
|
||||||
|
# fetch_mac() to get the correct MAC address of the VM.
|
||||||
|
printf "#\\n# File generated on %s\\n#\\n" "$date"
|
||||||
printf "socket owner :%s\\n\\n" "$VMDUSERS"
|
printf "socket owner :%s\\n\\n" "$VMDUSERS"
|
||||||
printf "switch \"%s\" {\\n" "$UPLINK"
|
printf "switch \"%s\" {\\n" "$UPLINK"
|
||||||
printf "\\tinterface %s\\n" "$BRIDGE"
|
printf "\\tinterface %s\\n" "$BRIDGE"
|
||||||
|
@ -74,21 +129,27 @@ render_vm_conf() {
|
||||||
then
|
then
|
||||||
printf "\\towner %s\\n" "$owner"
|
printf "\\towner %s\\n" "$owner"
|
||||||
fi
|
fi
|
||||||
if ! test -f "${IMG}/${instance}.img"
|
if ! test -f "${IMAGES}/${instance}.img"
|
||||||
then
|
then
|
||||||
printf "\\tboot \"%s/bsd.rd\"\\n" "$IMG"
|
printf "\\tboot \"%s/bsd.rd\"\\n" "$IMAGES"
|
||||||
fi
|
fi
|
||||||
printf "\\tdisk \"%s/%s.img\"\\n" "$IMG" "$instance"
|
printf "\\tdisk \"%s/%s.img\"\\n" "$IMAGES" "$instance"
|
||||||
printf "\\tinterface tap {\\n"
|
printf "\\tinterface tap {\\n"
|
||||||
printf "\\t\\tswitch \"uplink_vlan921\"\\n"
|
printf "\\t\\tswitch \"uplink_vlan921\"\\n"
|
||||||
printf "\\t\\tlladdr %s\\n" "$mac"
|
printf "\\t\\tlladdr %s\\n" "$(fetch_mac "$MAC_PREFIX" "$(find_vm "$VMS" "$instance")")"
|
||||||
printf "\\t}\\n"
|
printf "\\t}\\n"
|
||||||
printf "}\\n"
|
printf "}\\n"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
render_dhcpd_conf() {
|
render_dhcpd_conf() {
|
||||||
printf "#\\n# File generated on %s\\n#\\n" "$date" > "${ETC}/dhcpd.conf"
|
# Generate dhcpd.comf
|
||||||
|
# Takes defaults from of _vms.conf and iterate over the vm*.txt files.
|
||||||
|
# When the VM image doesn't exist add "auto_install".
|
||||||
|
# When the VM image does exist add "auto_upgrade".
|
||||||
|
# fetch_mac() to get the correct MAC address of the VM.
|
||||||
|
# fetch_ip() to get the correct IP address of the VM.
|
||||||
|
printf "#\\n# File generated on %s\\n#\\n" "$date"
|
||||||
printf "option domain-name \"%s\";\\n" "$DOMAIN"
|
printf "option domain-name \"%s\";\\n" "$DOMAIN"
|
||||||
printf "option domain-name-servers \"%s\";\\n\\n" "$DNS"
|
printf "option domain-name-servers \"%s\";\\n\\n" "$DNS"
|
||||||
printf "subnet %s netmask %s {\\n" "$SUBNET" "$NETMASK"
|
printf "subnet %s netmask %s {\\n" "$SUBNET" "$NETMASK"
|
||||||
|
@ -99,9 +160,9 @@ render_dhcpd_conf() {
|
||||||
do
|
do
|
||||||
. "$f"
|
. "$f"
|
||||||
printf "\\thost %s {\\n" "$instance"
|
printf "\\thost %s {\\n" "$instance"
|
||||||
printf "\\t\\thardware ethernet %s\\n" "$mac"
|
printf "\\t\\thardware ethernet %s\\n" "$(fetch_mac "$MAC_PREFIX" "$(find_vm "$VMS" "$instance")")"
|
||||||
printf "\\t\\tfixed-address %s\\n" "$ip"
|
printf "\\t\\tfixed-address %s\\n" "$(fetch_ip "$IP_PREFIX" "$IP_START" "$(find_vm "$VMS" "$instance")")"
|
||||||
if ! test -f "${IMG}/${instance}.img"
|
if ! test -f "${IMAGES}/${instance}.img"
|
||||||
then
|
then
|
||||||
printf "\\t\\tfilename \"auto_install\"\\n"
|
printf "\\t\\tfilename \"auto_install\"\\n"
|
||||||
else
|
else
|
||||||
|
@ -114,36 +175,45 @@ render_dhcpd_conf() {
|
||||||
}
|
}
|
||||||
|
|
||||||
render_install_conf() {
|
render_install_conf() {
|
||||||
|
# Generate install-<mac>.comf
|
||||||
|
# Takes defaults from of _vms.conf and iterate over the vm*.txt files.
|
||||||
|
# When the VM image doesn't exist create the install-<mac>.conf file.
|
||||||
|
# When the VM image does exist remove the install-<mac>.conf file.
|
||||||
|
# fetch_ipv6() to get the correct IPv6 address of the VM.
|
||||||
|
# fetch_mac() to get the correct MAC address of the VM.
|
||||||
while read -r f
|
while read -r f
|
||||||
do
|
do
|
||||||
. "$f"
|
. "$f"
|
||||||
ipv6_gateway=$(echo "$ipv6" | sed -e 's/::[0-9]*$/::1/g')
|
_pass="$(generate_passwd)"
|
||||||
if ! test -f "${IMG}/${instance}.img"
|
_ipv6=$(fetch_ipv6 "$IPV6_PREFIX" "$IPV6_START" "$IP_START" "$(find_vm "$VMS" "$instance")")
|
||||||
|
_ipv6_gateway=$(echo "$_ipv6" | sed -e 's/::[0-9]*$/::1/g')
|
||||||
|
_mac=$(fetch_mac "$MAC_PREFIX" "$(find_vm "$VMS" "$instance")")
|
||||||
|
if ! test -f "${IMAGES}/${instance}.img"
|
||||||
then
|
then
|
||||||
cat <<-EOF > "${HTDOCS}/install-${mac}.conf"
|
cat <<-EOF > "${HTDOCS}/install-${_mac}.conf"
|
||||||
#
|
#
|
||||||
# File generated on $date
|
# File generated on $date
|
||||||
#
|
#
|
||||||
System hostname = $hostname
|
System hostname = $hostname
|
||||||
Password for root = $pass
|
Password for root = $_pass
|
||||||
Which speed should com0 = 115200
|
Which speed should com0 = 115200
|
||||||
Network interfaces = vio0
|
Network interfaces = vio0
|
||||||
IPv4 address for vio0 = dhcp
|
IPv4 address for vio0 = dhcp
|
||||||
IPv6 address for vio0 = $ipv6
|
IPv6 address for vio0 = $_ipv6
|
||||||
IPv6 default router = $ipv6_gateway
|
IPv6 default router = $_ipv6_gateway
|
||||||
Setup a user = $username
|
Setup a user = $username
|
||||||
Password for user = $pass
|
Password for user = $_pass
|
||||||
Public ssh key for user = $message $pass
|
Public ssh key for user = $message $_pass
|
||||||
Which disk is the root disk = sd0
|
Which disk is the root disk = sd0
|
||||||
What timezone are you in = Europe/Amsterdam
|
What timezone are you in = Europe/Amsterdam
|
||||||
Location of sets = http
|
Location of sets = http
|
||||||
Server = ftp.nluug.nl
|
Server = ftp.nluug.nl
|
||||||
Set name(s) = -x* +xb* +xf*
|
Set name(s) = -x* +xb* +xf*
|
||||||
EOF
|
EOF
|
||||||
echo "Install file created: ${HTDOCS}/install-${mac}.conf"
|
echo "Install file created: ${HTDOCS}/install-${_mac}.conf"
|
||||||
else
|
else
|
||||||
if test -f "${HTDOCS}/install-${mac}.conf"
|
if test -f "${HTDOCS}/install-${_mac}.conf"
|
||||||
then rm -rf "${HTDOCS}/install-${mac}.conf"
|
then rm -rf "${HTDOCS}/install-${_mac}.conf"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -153,9 +223,9 @@ create_images() {
|
||||||
while read -r f
|
while read -r f
|
||||||
do
|
do
|
||||||
. "$f"
|
. "$f"
|
||||||
if ! test -f "${IMG}/${instance}.img"
|
if ! test -f "${IMAGES}/${instance}.img"
|
||||||
then vmctl create "${IMG}/${instance}.img" -s 50G > /dev/null
|
then vmctl create "${IMAGES}/${instance}.img" -s 50G > /dev/null
|
||||||
echo "Image file created: ${IMG}/${instance}.img"
|
echo "Image file created: ${IMAGES}/${instance}.img"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
4
vm1.txt
4
vm1.txt
|
@ -1,8 +1,4 @@
|
||||||
instance="vm1"
|
instance="vm1"
|
||||||
ip="192.168.0.10"
|
|
||||||
ipv6="2a03:6000:192::10"
|
|
||||||
mac="fe:e1:bb:d4:ce:a9"
|
|
||||||
pass="kOlyAvD6lqLDS4X"
|
|
||||||
date="2018/09/18"
|
date="2018/09/18"
|
||||||
payment=
|
payment=
|
||||||
donated=
|
donated=
|
||||||
|
|
10
vm2.txt
10
vm2.txt
|
@ -1,15 +1,11 @@
|
||||||
instance="vm2"
|
instance="vm2"
|
||||||
ip="192.168.0.11
|
|
||||||
ipv6="2a03:6000:192::11"
|
|
||||||
mac="fe:e1:bb:d4:f2:6a"
|
|
||||||
pass="IRiH5fXiez3iDvU"
|
|
||||||
date="2018/09/18"
|
date="2018/09/18"
|
||||||
payment=
|
payment=
|
||||||
donated=
|
donated=
|
||||||
owner=
|
owner=
|
||||||
name="user Two
|
name="User Two"
|
||||||
email="user.two@gmail.com"
|
email="user.two@gmail.com"
|
||||||
message="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5SudIBvFRhkxldn1OEgnQdl7PxMQjm2DyYCqHjy"
|
message="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5SudIBvFRhkxldn1OEgnQdl7PxMQjm2DyYCqHjy"
|
||||||
hostname="user2"
|
hostname="vm2"
|
||||||
username="vm2"
|
username="user2"
|
||||||
note="Second!"
|
note="Second!"
|
||||||
|
|
4
vm3.txt
4
vm3.txt
|
@ -1,8 +1,4 @@
|
||||||
instance="vm3"
|
instance="vm3"
|
||||||
ip="192.168.0.12
|
|
||||||
ipv6="2a03:6000:192::12"
|
|
||||||
mac="fe:e1:bb:d4:ad:fd"
|
|
||||||
pass="fJweGUoqglVKqU4"
|
|
||||||
date="2018/09/18"
|
date="2018/09/18"
|
||||||
payment=
|
payment=
|
||||||
donated=
|
donated=
|
||||||
|
|
Loading…
Reference in New Issue