#!/bin/bash # Initialize variables hostname="" # Appliance hostname mode="" # Static or dhcp address="" # IP address in CIDR format gateway="" # Gateway address dnsservers="" # Dns servers separated by commas port="" # NGINX port netplan_config="/etc/netplan/99-appliance-network.yaml" cloud_init_config="/etc/netplan/50-cloud-init.yaml" printmsg () { echo $1 | systemd-cat -p $2 -t "appliance-bootstrap" } # Parse arguments while true; do case "$1" in -n | --hostname ) hostname="$2" shift 2 ;; -m | --mode ) mode="$2" shift 2 ;; -a | --address ) address="$2" shift 2 ;; -g | --gateway ) gateway="$2" shift 2 ;; -d | --dnsservers ) dnsservers="$2" shift 2 ;; -p | --port ) port="$2" shift 2 ;; * ) break ;; esac done # echo "mode: $mode" # echo "address: $address" # echo "gateway: $gateway" # echo "dnsservers: $dnsservers" # echo "port: $port" if [ -n "$hostname" ]; then printmsg "Info: Setting Hostname to $hostname" "info" hostnamectl set-hostname $hostname fi # Generate netplan config case "$mode" in dhcp) printmsg "Info: Configuring network via DHCP" "info" cat > $netplan_config < $netplan_config < /dev/null if [ $? -eq 0 ]; then rm -f $cloud_init_config fi ls $netplan_config &> /dev/null if [ $? -eq 0 ]; then chmod 0600 $netplan_config fi netplan generate netplan apply # Configure Nginx application if [ -n "$port" ]; then printmsg "Info: Configuring Nginx with port: $port" "info" save-app-config.sh $port fi exit 0