#cloud-config hostname: backupassure manage_etc_hosts: true bootcmd: - | primary_interface=$(ip -o link show | awk '$2 !~ "lo:" {print substr($2, 1, length($2)-1); exit}') cat < /etc/sysconfig/network-scripts/ifcfg-$primary_interface DEVICE=$primary_interface BOOTPROTO=dhcp ONBOOT=yes EOF if systemctl is-active --quiet NetworkManager; then nmcli connection reload nmcli device disconnect $primary_interface nmcli device connect $primary_interface else systemctl restart network fi runcmd: - | echo "Backup Assure is currently building. Please refrain from logging in until you see 'Backup Assure is ready' message." | tee /dev/console sleep 5 # Detect unpartitioned disks larger than 16GB disks=() for dev in /dev/nvme*n1; do size=$(lsblk -bn -d -o SIZE "$dev") if (( size > 17179869184 )); then has_parts=$(lsblk -no NAME "$dev" | wc -l) if (( has_parts == 1 )); then disks+=("$dev") fi fi done num_disks=${#disks[@]} if [ "$num_disks" -eq 1 ]; then disk="${disks[0]}" echo "One additional disk found: $disk. Mounting to /backups" | tee /dev/console parted "$disk" --script mklabel gpt sleep 2 parted "$disk" --script mkpart primary ext4 0% 100% sleep 2 mkfs.ext4 "${disk}p1" sleep 2 UUID=$(blkid -s UUID -o value "${disk}p1") mkdir -p /backups mount -U "$UUID" /backups echo "UUID=$UUID /backups ext4 defaults 0 0" >> /etc/fstab mkdir -p /backups/rsync /backups/nfs elif [ "$num_disks" -eq 2 ]; then disk1="${disks[0]}" disk2="${disks[1]}" echo "Two disks found: $disk1 (NFS), $disk2 (RSYNC)" | tee /dev/console for d in "$disk1" "$disk2"; do parted "$d" --script mklabel gpt sleep 2 parted "$d" --script mkpart primary ext4 0% 100% sleep 2 mkfs.ext4 "${d}p1" sleep 2 done UUID_nfs=$(blkid -s UUID -o value "${disk1}p1") UUID_rsync=$(blkid -s UUID -o value "${disk2}p1") mkdir -p /backups/nfs mount -U "$UUID_nfs" /backups/nfs echo "UUID=$UUID_nfs /backups/nfs ext4 defaults 0 0" >> /etc/fstab mkdir -p /backups/rsync mount -U "$UUID_rsync" /backups/rsync echo "UUID=$UUID_rsync /backups/rsync ext4 defaults 0 0" >> /etc/fstab else echo "Unexpected number of disks ($num_disks). No action taken." | tee /dev/console fi echo "Backup Assure is ready." | tee /dev/console sleep 5 clear