|
|
@@ -2,7 +2,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo ""
|
|
|
|
echo "Updating local packages..."
|
|
|
|
echo "Updating local packages..."
|
|
|
|
errors=`apt-add-repository universe >/dev/null 2>/dev/null && apt update 2>&1 >/dev/null`
|
|
|
|
errors=`apt-add-repository universe >/dev/null 2>&1 1>/dev/null && apt update 2>&1 >/dev/null`
|
|
|
|
if [ "$?" = "0" ]; then
|
|
|
|
if [ "$?" = "0" ]; then
|
|
|
|
echo "Done."
|
|
|
|
echo "Done."
|
|
|
|
else
|
|
|
|
else
|
|
|
@@ -25,6 +25,8 @@ width=`tput cols`
|
|
|
|
height=`tput lines`
|
|
|
|
height=`tput lines`
|
|
|
|
window=$((height - 5))
|
|
|
|
window=$((height - 5))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ -d "/sys/firmware/efi" ]; then efi="1"; echo -e "\nUEFI detected..." else efi="0"; echo -e "\nBIOS detected..."; fi
|
|
|
|
|
|
|
|
|
|
|
|
# gather input at the start
|
|
|
|
# gather input at the start
|
|
|
|
devices=""; for device in $(ls /dev/disk/by-id | grep -v part); do devices="$devices $device off"; done
|
|
|
|
devices=""; for device in $(ls /dev/disk/by-id | grep -v part); do devices="$devices $device off"; done
|
|
|
|
disks=`dialog --separate-output --no-cancel --no-items --title "Root devices" --checklist "Select root OS disks:" $height $width ${window}$devices 2>&1 1>/dev/tty`
|
|
|
|
disks=`dialog --separate-output --no-cancel --no-items --title "Root devices" --checklist "Select root OS disks:" $height $width ${window}$devices 2>&1 1>/dev/tty`
|
|
|
@@ -56,7 +58,12 @@ swapspace=$(($swapspace * `getconf PAGESIZE`))
|
|
|
|
# 20% swap space with 2G minimum
|
|
|
|
# 20% swap space with 2G minimum
|
|
|
|
if [ "$swapspace" -lt "2048000" ]; then swapspace="2048000" ; fi
|
|
|
|
if [ "$swapspace" -lt "2048000" ]; then swapspace="2048000" ; fi
|
|
|
|
|
|
|
|
|
|
|
|
nics=`dialog --separate-output --no-cancel --no-items --title "Bridged network devices" --checklist "Select the network devices to be bridged to br0:" $height $width ${window}$nicdevices 2>&1 1>/dev/tty`
|
|
|
|
nics=`dialog --separate-output --no-cancel --no-items --title "Bridged network devices" --checklist "Select the network devices to be bridged to bridge - select none for no bridge:" $height $width ${window}$nicdevices 2>&1 1>/dev/tty`
|
|
|
|
|
|
|
|
if [ -z "$nics" ]; then
|
|
|
|
|
|
|
|
bridgedevice=`dialog --no-cancel --no-items --title "Configure network devices" --radiolist "NO BRIDGE MODE!\nSelect the network device to configure:" $height $width ${window}$nicdevices 2>&1 1>/dev/tty`
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
bridgedevice="br0"
|
|
|
|
|
|
|
|
fi
|
|
|
|
networktype=`dialog --no-items --no-cancel --title "Network type" --radiolist "Select the network type:" 9 40 2 dhcp off static off 2>&1 1>/dev/tty`
|
|
|
|
networktype=`dialog --no-items --no-cancel --title "Network type" --radiolist "Select the network type:" 9 40 2 dhcp off static off 2>&1 1>/dev/tty`
|
|
|
|
if [ "$networktype" = "static" ]; then
|
|
|
|
if [ "$networktype" = "static" ]; then
|
|
|
|
address=""; while [ -z "$address" ]; do address=`dialog --no-cancel --inputbox "IP Address:" 8 40 2>&1 >/dev/tty`; done
|
|
|
|
address=""; while [ -z "$address" ]; do address=`dialog --no-cancel --inputbox "IP Address:" 8 40 2>&1 >/dev/tty`; done
|
|
|
@@ -106,16 +113,44 @@ for disk in `echo "$alldisks"`; do
|
|
|
|
echo "Done."
|
|
|
|
echo "Done."
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
for disk in `echo "$boots"`; do
|
|
|
|
if [ "$efi" = "1" ]; then
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for disk in `echo "$boots"`; do
|
|
|
|
echo ""
|
|
|
|
echo ""
|
|
|
|
echo "Creating boot partitions for device $disk..."
|
|
|
|
echo "Creating boot partitions for device $disk..."
|
|
|
|
errors=`sgdisk -n2:1M:+512M -t2:EF00 /dev/disk/by-id/$disk 2>&1 1>/dev/null && sgdisk -n3:0:+512M -t3:BF01 /dev/disk/by-id/$disk 2>&1 1>/dev/null`
|
|
|
|
errors=`sgdisk -n1:1M:+512M -t1:EF00 /dev/disk/by-id/$disk 2>&1 1>/dev/null`
|
|
|
|
if ! [ "$?" = "0" ]; then
|
|
|
|
if ! [ "$?" = "0" ]; then
|
|
|
|
echo "Failed to create boot partition for device $disk - $errors"
|
|
|
|
echo "Failed to create boot partition for device $disk - $errors"
|
|
|
|
exit 3
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo "Done."
|
|
|
|
echo "Done."
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for disk in `echo "$boots"`; do
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
echo "Creating boot partitions for device $disk..."
|
|
|
|
|
|
|
|
errors=`sgdisk -n3:0:+512M -t3:BF01 /dev/disk/by-id/$disk 2>&1 1>/dev/null`
|
|
|
|
|
|
|
|
if ! [ "$?" = "0" ]; then
|
|
|
|
|
|
|
|
echo "Failed to create boot partition for device $disk - $errors"
|
|
|
|
|
|
|
|
exit 3
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Done."
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for disk in `echo "$boots"`; do
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
echo "Creating boot partitions for device $disk..."
|
|
|
|
|
|
|
|
errors=`sgdisk -a1 -n1:24K:+1000K -t1:EF02 /dev/disk/by-id/$disk 2>&1 1>/dev/null`
|
|
|
|
|
|
|
|
if ! [ "$?" = "0" ]; then
|
|
|
|
|
|
|
|
echo "Failed to create boot partition for device $disk - $errors"
|
|
|
|
|
|
|
|
exit 3
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Done."
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
for disk in `echo "$disks"`; do
|
|
|
|
for disk in `echo "$disks"`; do
|
|
|
|
echo ""
|
|
|
|
echo ""
|
|
|
@@ -128,18 +163,31 @@ for disk in `echo "$disks"`; do
|
|
|
|
echo "Done."
|
|
|
|
echo "Done."
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# create boot mirror list
|
|
|
|
# create boot mirror list and root list
|
|
|
|
bootmirror=""; rootraidz=""; for disk in `echo "$disks"`; do bootmirror="$bootmirror /dev/disk/by-id/${disk}-part3"; rootraidz="$rootraidz /dev/disk/by-id/${disk}-part4"; done
|
|
|
|
|
|
|
|
|
|
|
|
count="0"; bootmirror=""; for disk in `echo "$boots"`; do bootmirror="$bootmirror /dev/disk/by-id/${disk}-part3"; count=$((count + 1)); done; if [ "$count" -gt "1" ]; then bootmirror="mirror $bootmirror"; fi
|
|
|
|
|
|
|
|
rootraidz=""; for disk in `echo "$disks"`; do rootraidz="$rootraidz /dev/disk/by-id/${disk}-part4"; done
|
|
|
|
|
|
|
|
|
|
|
|
# refresh drives or there are missing partitions
|
|
|
|
# refresh drives or there are missing partitions
|
|
|
|
partprobe 2>/dev/null 1>/dev/null
|
|
|
|
partprobe 2>/dev/null 1>/dev/null
|
|
|
|
|
|
|
|
|
|
|
|
# wait for the partitions to show up
|
|
|
|
# wait for the partitions to show up
|
|
|
|
|
|
|
|
|
|
|
|
for disk in `echo "$boots"`; do
|
|
|
|
for disk in `echo "$boots"`; do
|
|
|
|
pending="0"
|
|
|
|
pending="0"
|
|
|
|
while ! [ -e "/dev/disk/by-id/${disk}-part3" ]; do
|
|
|
|
while ! [ -e "/dev/disk/by-id/${disk}-part3" ]; do
|
|
|
|
partprobe 2>/dev/null 1>/dev/null
|
|
|
|
partprobe 2>/dev/null 1>/dev/null
|
|
|
|
if [ "$pending" = "0" ]; then echo "" && echo "Waiting for ${disk} boot partition to update..."; pending="1"; fi
|
|
|
|
if [ "$pending" = "0" ]; then echo "" && echo "Waiting for ${disk} boot pool partition to update on device ${disk}..."; pending="1"; fi
|
|
|
|
|
|
|
|
sleep 3
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$pending" = "1" ]; then echo "Done."; fi
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for disk in `echo "$boots"`; do
|
|
|
|
|
|
|
|
pending="0"
|
|
|
|
|
|
|
|
while ! [ -e "/dev/disk/by-id/${disk}-part1" ]; do
|
|
|
|
|
|
|
|
partprobe 2>/dev/null 1>/dev/null
|
|
|
|
|
|
|
|
if [ "$pending" = "0" ]; then echo "" && echo "Waiting for ${disk} boot partition to update on device ${disk}..."; pending="1"; fi
|
|
|
|
sleep 3
|
|
|
|
sleep 3
|
|
|
|
done
|
|
|
|
done
|
|
|
|
if [ "$pending" = "1" ]; then echo "Done."; fi
|
|
|
|
if [ "$pending" = "1" ]; then echo "Done."; fi
|
|
|
@@ -147,7 +195,7 @@ done
|
|
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo ""
|
|
|
|
echo "Creating boot zpool..."
|
|
|
|
echo "Creating boot zpool..."
|
|
|
|
errors=`zpool create -f -o ashift=12 -d -o feature@async_destroy=enabled -o feature@bookmarks=enabled -o feature@embedded_data=enabled -o feature@empty_bpobj=enabled -o feature@enabled_txg=enabled -o feature@extensible_dataset=enabled -o feature@filesystem_limits=enabled -o feature@hole_birth=enabled -o feature@large_blocks=enabled -o feature@lz4_compress=enabled -o feature@spacemap_histogram=enabled -o feature@userobj_accounting=enabled -O acltype=posixacl -O canmount=off -O compression=lz4 -O devices=off -O normalization=formD -O relatime=on -O xattr=sa -O mountpoint=/ -R /mnt bpool mirror$bootmirror 2>&1 1>/dev/null`
|
|
|
|
errors=`zpool create -f -o ashift=12 -d -o feature@async_destroy=enabled -o feature@bookmarks=enabled -o feature@embedded_data=enabled -o feature@empty_bpobj=enabled -o feature@enabled_txg=enabled -o feature@extensible_dataset=enabled -o feature@filesystem_limits=enabled -o feature@hole_birth=enabled -o feature@large_blocks=enabled -o feature@lz4_compress=enabled -o feature@spacemap_histogram=enabled -o feature@userobj_accounting=enabled -O acltype=posixacl -O canmount=off -O compression=lz4 -O devices=off -O normalization=formD -O relatime=on -O xattr=sa -O mountpoint=/ -R /mnt bpool $bootmirror 2>&1 1>/dev/null`
|
|
|
|
if ! [ "$?" = "0" ]; then
|
|
|
|
if ! [ "$?" = "0" ]; then
|
|
|
|
echo "Failed to create boot pool - $errors"
|
|
|
|
echo "Failed to create boot pool - $errors"
|
|
|
|
exit 4
|
|
|
|
exit 4
|
|
|
@@ -292,7 +340,7 @@ echo "cp /usr/share/zoneinfo/$timezone /etc/localtime" >> /mnt/setup-chroot.sh
|
|
|
|
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
|
|
|
|
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
|
|
|
|
echo "echo \"\"" >> /mnt/setup-chroot.sh
|
|
|
|
echo "echo \"\"" >> /mnt/setup-chroot.sh
|
|
|
|
echo "echo \"Installing linux image, ifupdown dnsutils nfs-kernel-server apparmor-profiles vim, libvirt-bin, bridge-utils, net-tools, bash, screen, tmux, zfs-initramfs, dosfstools, mailutils, ssmtp, openssh-server, ufw, docker.io, sharutils...\"" >> /mnt/setup-chroot.sh
|
|
|
|
echo "echo \"Installing linux image, ifupdown, dnsutils, nfs-kernel-server, apparmor-profiles, vim, libvirt-bin, bridge-utils, net-tools, bash, screen, tmux, zfs-initramfs, dosfstools, mailutils, ssmtp, openssh-server, ufw, docker.io, sharutils...\"" >> /mnt/setup-chroot.sh
|
|
|
|
echo "errors=\$(DEBCONF_FRONTEND='noninteractive' apt install -y --no-install-recommends linux-image-generic 2>&1 1>/dev/null && apt purge -y netplan 2>&1 1>/dev/null && apt autoremove -y 2>&1 1>/dev/null && DEBCONF_FRONTEND='noninteractive' apt install -y ifupdown efibootmgr htop iotop smartmontools dnsutils nfs-kernel-server apparmor-profiles vim libvirt-bin bridge-utils net-tools bash screen tmux zfs-initramfs dosfstools mailutils ssmtp openssh-server ufw docker.io sharutils 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
|
|
|
|
echo "errors=\$(DEBCONF_FRONTEND='noninteractive' apt install -y --no-install-recommends linux-image-generic 2>&1 1>/dev/null && apt purge -y netplan 2>&1 1>/dev/null && apt autoremove -y 2>&1 1>/dev/null && DEBCONF_FRONTEND='noninteractive' apt install -y ifupdown efibootmgr htop iotop smartmontools dnsutils nfs-kernel-server apparmor-profiles vim libvirt-bin bridge-utils net-tools bash screen tmux zfs-initramfs dosfstools mailutils ssmtp openssh-server ufw docker.io sharutils 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
|
|
|
|
echo 'if ! [ \"$?\" = \"0\" ]; then '>> /mnt/setup-chroot.sh
|
|
|
|
echo 'if ! [ \"$?\" = \"0\" ]; then '>> /mnt/setup-chroot.sh
|
|
|
@@ -322,12 +370,12 @@ echo "net.ipv6.conf.lo.disable_ipv6 = 1" >> /mnt/etc/sysctl.conf
|
|
|
|
echo 'echo ""' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'echo ""' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'echo "Creating EFI partition..."' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'echo "Creating EFI partition..."' >> /mnt/setup-chroot.sh
|
|
|
|
firstdisk=`echo "$boots" | head -n1`
|
|
|
|
firstdisk=`echo "$boots" | head -n1`
|
|
|
|
echo "error=\$(mkdosfs -F 32 -s 1 -n EFI /dev/disk/by-id/${firstdisk}-part2 2>&1 1>/dev/null && mkdir /boot/efi 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
|
|
|
|
echo "error=\$(mkdosfs -F 32 -s 1 -n EFI /dev/disk/by-id/${firstdisk}-part1 2>&1 1>/dev/null && mkdir /boot/efi 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
|
|
|
|
echo 'if ! [ \"$?\" = \"0\" ]; then '>> /mnt/setup-chroot.sh
|
|
|
|
echo 'if ! [ \"$?\" = \"0\" ]; then '>> /mnt/setup-chroot.sh
|
|
|
|
echo ' echo "Failed to create dos file system for EFI partition - $errors"' >> /mnt/setup-chroot.sh
|
|
|
|
echo ' echo "Failed to create dos file system for EFI partition - $errors"' >> /mnt/setup-chroot.sh
|
|
|
|
echo " exit 100">> /mnt/setup-chroot.sh
|
|
|
|
echo " exit 100">> /mnt/setup-chroot.sh
|
|
|
|
echo "fi">> /mnt/setup-chroot.sh
|
|
|
|
echo "fi">> /mnt/setup-chroot.sh
|
|
|
|
echo "echo PARTUUID=$(blkid -s PARTUUID -o value /dev/disk/by-id/${firstdisk}-part2) /boot/efi vfat nofail,x-systemd.device-timeout=0 0 1 >> /etc/fstab" >> /mnt/setup-chroot.sh
|
|
|
|
echo "echo PARTUUID=$(blkid -s PARTUUID -o value /dev/disk/by-id/${firstdisk}-part1) /boot/efi vfat nofail,x-systemd.device-timeout=0 0 1 >> /etc/fstab" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
|
|
|
|
echo "errors=\$(mount /boot/efi 2>&1 1>/dev/null && apt install -y grub-efi-amd64-signed shim-signed 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
|
|
|
|
echo "errors=\$(mount /boot/efi 2>&1 1>/dev/null && apt install -y grub-efi-amd64-signed shim-signed 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
|
|
|
|
echo 'if ! [ \"$?\" = \"0\" ]; then '>> /mnt/setup-chroot.sh
|
|
|
|
echo 'if ! [ \"$?\" = \"0\" ]; then '>> /mnt/setup-chroot.sh
|
|
|
@@ -359,6 +407,7 @@ echo "echo \"Success.\"" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
|
|
|
|
echo 'echo ""' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'echo ""' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'echo "Updating initramfs..."' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'echo "Updating initramfs..."' >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"vmd\" >> /etc/initramfs-tools/modules" >> /mnt/setup-chroot.sh
|
|
|
|
echo 'errors=$(update-initramfs -u -k all 2>&1 1>/dev/null)' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'errors=$(update-initramfs -u -k all 2>&1 1>/dev/null)' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'if ! [ \"$?\" = \"0\" ]; then '>> /mnt/setup-chroot.sh
|
|
|
|
echo 'if ! [ \"$?\" = \"0\" ]; then '>> /mnt/setup-chroot.sh
|
|
|
|
echo ' echo "Failed to update initramfs - $errors"' >> /mnt/setup-chroot.sh
|
|
|
|
echo ' echo "Failed to update initramfs - $errors"' >> /mnt/setup-chroot.sh
|
|
|
@@ -369,7 +418,7 @@ echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
|
|
|
|
# you need sed to do this right!
|
|
|
|
# you need sed to do this right!
|
|
|
|
echo 'echo ""' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'echo ""' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'echo "Modifying grub for ZFS root..."' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'echo "Modifying grub for ZFS root..."' >> /mnt/setup-chroot.sh
|
|
|
|
echo "errors=\$(sed -ir 's/quiet splash//g' /etc/default/grub 2>&1 1>/dev/null && sed -ir 's/GRUB_CMDLINE_LINUX=\".*\"/GRUB_CMDLINE_LINUX=\"root=ZFS=rpool\/ROOT\/ubuntu\"/g' /etc/default/grub 2>&1 1>/dev/null && sed -ir 's/^#GRUB_TERMINAL=console/GRUB_TERMINAL=console/g' /etc/default/grub 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
|
|
|
|
echo "errors=\$(sed -ir 's/quiet splash//g' /etc/default/grub 2>&1 1>/dev/null && sed -ir 's/GRUB_CMDLINE_LINUX=\".*\"/GRUB_CMDLINE_LINUX=\"root=ZFS=rpool\/ROOT\/ubuntu rootdelay=10 noresume\"/g' /etc/default/grub 2>&1 1>/dev/null && sed -ir 's/^#GRUB_TERMINAL=console/GRUB_TERMINAL=console/g' /etc/default/grub 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
|
|
|
|
echo "if ! [ \"\$?\" = \"0\" ]; then echo \"Failed to set grub ZFS root - \$errors\"; exit 104; fi" >> /mnt/setup-chroot.sh
|
|
|
|
echo "if ! [ \"\$?\" = \"0\" ]; then echo \"Failed to set grub ZFS root - \$errors\"; exit 104; fi" >> /mnt/setup-chroot.sh
|
|
|
|
echo 'echo "Done."' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'echo "Done."' >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
|
|
|
@@ -389,16 +438,19 @@ echo "if ! [ \"\$?\" = \"0\" ]; then echo \"Failed to install grub UEFI on plex1
|
|
|
|
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
|
|
|
|
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
|
|
|
|
if ! [ "$boots" = "" ]; then
|
|
|
|
if ! [ "$boots" = "" ]; then
|
|
|
|
|
|
|
|
if [ "$efi" = "1" ]; then
|
|
|
|
|
|
|
|
|
|
|
|
echo 'echo ""' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'echo ""' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'echo "Cloning EFI boot partition to all boot devices..."' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'echo "Cloning EFI boot partition to all boot devices..."' >> /mnt/setup-chroot.sh
|
|
|
|
i="2"
|
|
|
|
i="2"
|
|
|
|
for disk in `echo "$boots" | tail -n+2`; do
|
|
|
|
for disk in `echo "$boots" | tail -n+2`; do
|
|
|
|
echo "errors=\$(dd if=/dev/disk/by-id/${firstdisk}-part2 of=/dev/disk/by-id/${disk}-part2 2>&1 1>/dev/null && efibootmgr -c -g -d /dev/disk/by-id/${disk} -p 3 -L "ubuntu-$i" -l '\EFI\ubuntu\grubx64.efi' 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
|
|
|
|
echo "errors=\$(dd if=/dev/disk/by-id/${firstdisk}-part1 of=/dev/disk/by-id/${disk}-part1 2>&1 1>/dev/null && efibootmgr -c -g -d /dev/disk/by-id/${disk} -p 3 -L "ubuntu-$i" -l '\EFI\ubuntu\grubx64.efi' 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
|
|
|
|
echo "if ! [ \"\$?\" = \"0\" ]; then echo \"EFI copy failed - \$errors\"; exit 20; fi" >> /mnt/setup-chroot.sh
|
|
|
|
echo "if ! [ \"\$?\" = \"0\" ]; then echo \"EFI copy failed - \$errors\"; exit 20; fi" >> /mnt/setup-chroot.sh
|
|
|
|
i=$((i + 1))
|
|
|
|
i=$((i + 1))
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
echo 'echo "Done."' >> /mnt/setup-chroot.sh
|
|
|
|
echo 'echo "Done."' >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# error check this as one big block
|
|
|
|
# error check this as one big block
|
|
|
@@ -446,27 +498,6 @@ echo "chown -R ${admin}:${admin} \"/home/${admin}\"/.ssh" >> /mnt/setup-chroot.s
|
|
|
|
echo "HOME=\"/root\"" >> /mnt/setup-chroot.sh
|
|
|
|
echo "HOME=\"/root\"" >> /mnt/setup-chroot.sh
|
|
|
|
echo "HOSTNAME=\"$hostname\"" >> /mnt/setup-chroot.sh
|
|
|
|
echo "HOSTNAME=\"$hostname\"" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
|
|
|
|
echo "echo \"FromLineOverride=YES\" > /etc/ssmtp/ssmtp.conf" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"root=admin\" >> /etc/ssmtp/ssmtp.conf" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"hostname=${fqdn}\" >> /etc/ssmtp/ssmtp.conf" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"AuthUser=${email}\" >> /etc/ssmtp/ssmtp.conf" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"AuthPass=${emailpassword}\" >> /etc/ssmtp/ssmtp.conf" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"mailhub=${smtp}\" >> /etc/ssmtp/ssmtp.conf" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"UseSTARTTLS=YES\" >> /etc/ssmtp/ssmtp.conf" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"root:${admins}\" >> /etc/ssmtp/revaliases" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "chfn -f '${email}' root" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"\"" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"Sending SSH key via e-mail...\"" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
if [ "$networktype" = "dhcp" ]; then
|
|
|
|
|
|
|
|
connection="`hostname -I` (`wget -qO - ifconfig.me`)"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
connection="$address"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "serverinfo=\`cat \"/home/${admin}/.ssh/id_rsa\"\`" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "serverinfo=\"Server available at $connection\\n\\n\$serverinfo\"; echo -e \"\$serverinfo\" | mail -s \"$hostname SSH key\" -r \"${email}\" \"\`cat /admins\`\"" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
errors=`chmod +x /mnt/setup-chroot.sh 2>&1 1>/dev/null`
|
|
|
|
errors=`chmod +x /mnt/setup-chroot.sh 2>&1 1>/dev/null`
|
|
|
|
if ! [ "$?" = "0" ]; then
|
|
|
|
if ! [ "$?" = "0" ]; then
|
|
|
|
echo "Failed to set execution permission on chroot script - $errors"
|
|
|
|
echo "Failed to set execution permission on chroot script - $errors"
|
|
|
@@ -505,6 +536,27 @@ echo " exit 122">> /mnt/setup-chroot.sh
|
|
|
|
echo "fi">> /mnt/setup-chroot.sh
|
|
|
|
echo "fi">> /mnt/setup-chroot.sh
|
|
|
|
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
|
|
|
|
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "echo \"\"" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"Sending SSH key via e-mail...\"" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
if [ "$networktype" = "dhcp" ]; then
|
|
|
|
|
|
|
|
connection="`hostname -I` (`wget -qO - ifconfig.me`)"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
connection="$address"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "echo \"FromLineOverride=YES\" > /etc/ssmtp/ssmtp.conf" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"root=admin\" >> /etc/ssmtp/ssmtp.conf" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"hostname=${fqdn}\" >> /etc/ssmtp/ssmtp.conf" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"AuthUser=${email}\" >> /etc/ssmtp/ssmtp.conf" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"AuthPass=${emailpassword}\" >> /etc/ssmtp/ssmtp.conf" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"mailhub=${smtp}\" >> /etc/ssmtp/ssmtp.conf" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"UseSTARTTLS=YES\" >> /etc/ssmtp/ssmtp.conf" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"root:${admins}\" >> /etc/ssmtp/revaliases" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "chfn -f '${email}' root" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "serverinfo=\`cat \"/home/${admin}/.ssh/id_rsa\"\`" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "serverinfo=\"Server available at $connection\\n\\n\$serverinfo\"; echo -e \"\$serverinfo\" | mail -s \"$hostname SSH key\" -r \"${email}\" \"\`cat /admins\`\"" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "exit 0" >> /mnt/setup-chroot.sh
|
|
|
|
echo "exit 0" >> /mnt/setup-chroot.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -527,29 +579,31 @@ echo ""
|
|
|
|
echo "Writing network interfaces file..."
|
|
|
|
echo "Writing network interfaces file..."
|
|
|
|
macaddr=$(echo $hostname|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')
|
|
|
|
macaddr=$(echo $hostname|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')
|
|
|
|
mkdir -p /mnt/etc/network && mkdir -p /mnt/etc/network/interfaces.d
|
|
|
|
mkdir -p /mnt/etc/network && mkdir -p /mnt/etc/network/interfaces.d
|
|
|
|
echo "auto lo br0" > /mnt/etc/network/interfaces.d/br0
|
|
|
|
echo "auto lo $bridgedevice" > /mnt/etc/network/interfaces.d/$bridgedevice
|
|
|
|
echo "iface lo inet loopback" >> /mnt/etc/network/interfaces.d/br0
|
|
|
|
echo "iface lo inet loopback" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
|
|
|
niclist=""
|
|
|
|
niclist=""
|
|
|
|
for nic in `echo "$nics"`; do
|
|
|
|
for nic in `echo "$nics"`; do
|
|
|
|
echo "iface ${nic} inet manual" >> /mnt/etc/network/interfaces.d/br0
|
|
|
|
echo "iface ${nic} inet manual" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
|
|
|
niclist="$niclist $nic"
|
|
|
|
niclist="$niclist $nic"
|
|
|
|
done
|
|
|
|
done
|
|
|
|
if [ "$networktype" = "dhcp" ]; then
|
|
|
|
if [ "$networktype" = "dhcp" ]; then
|
|
|
|
echo "iface br0 inet dhcp" >> /mnt/etc/network/interfaces.d/br0
|
|
|
|
echo "iface $bridgedevice inet dhcp" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
|
|
|
else
|
|
|
|
else
|
|
|
|
echo "iface br0 inet static" >> /mnt/etc/network/interfaces.d/br0
|
|
|
|
echo "iface $bridgedevice inet static" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
|
|
|
echo " address $address" >> /mnt/etc/network/interfaces.d/br0
|
|
|
|
echo " address $address" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
|
|
|
echo " netmask $subnet" >> /mnt/etc/network/interfaces.d/br0
|
|
|
|
echo " netmask $subnet" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
|
|
|
echo " gateway $gateway" >> /mnt/etc/network/interfaces.d/br0
|
|
|
|
echo " gateway $gateway" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
|
|
|
sed -ir "s/^#DNS=.*/DNS=${dns1}/g" /mnt/etc/systemd/resolved.conf
|
|
|
|
sed -ir "s/^#DNS=.*/DNS=${dns1}/g" /mnt/etc/systemd/resolved.conf
|
|
|
|
if ! [ -z "$dns2" ]; then sed -ir "s/^#FallbackDNS=.*/FallbackDNS=${dns2}/g" /mnt/etc/systemd/resolved.conf ; fi
|
|
|
|
if ! [ -z "$dns2" ]; then sed -ir "s/^#FallbackDNS=.*/FallbackDNS=${dns2}/g" /mnt/etc/systemd/resolved.conf ; fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
#echo " bridge_hw $macaddr" >> /mnt/etc/network/interfaces.d/br0
|
|
|
|
#echo " bridge_hw $macaddr" >> /mnt/etc/network/interfaces.d/br0
|
|
|
|
echo " dns-nameservers 127.0.0.53" >> /mnt/etc/network/interfaces.d/br0
|
|
|
|
echo " dns-nameservers 127.0.0.53" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
|
|
|
echo " bridge_waitport 0" >> /mnt/etc/network/interfaces.d/br0
|
|
|
|
if [ "$bridgedevice" = "br0" ]; then
|
|
|
|
echo " bridge_fd 0" >> /mnt/etc/network/interfaces.d/br0
|
|
|
|
echo " bridge_waitport 0" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
|
|
|
echo " bridge_ports${niclist}" >> /mnt/etc/network/interfaces.d/br0
|
|
|
|
echo " bridge_fd 0" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
|
|
|
echo " bridge_stp on" >> /mnt/etc/network/interfaces.d/br0
|
|
|
|
echo " bridge_ports${niclist}" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
|
|
|
|
|
|
|
echo " bridge_stp on" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
|
|
|
|
|
|
|
fi
|
|
|
|
echo "source-directory /etc/network/interfaces.d" > /mnt/etc/network/interfaces
|
|
|
|
echo "source-directory /etc/network/interfaces.d" > /mnt/etc/network/interfaces
|
|
|
|
echo "Done."
|
|
|
|
echo "Done."
|
|
|
|
|
|
|
|
|
|
|
@@ -557,7 +611,7 @@ echo "Done."
|
|
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo ""
|
|
|
|
echo "Opening SSH port on firewall..."
|
|
|
|
echo "Opening SSH port on firewall..."
|
|
|
|
sed -ir 's/### RULES ###/### RULES ###\n-A ufw-user-input -i br0 -p tcp --dport 22 -j ACCEPT/g' /mnt/etc/ufw/user.rules 2>&1 1>/dev/null
|
|
|
|
sed -ir 's/### RULES ###/### RULES ###\n-A ufw-user-input -p tcp --dport 22 -j ACCEPT/g' /mnt/etc/ufw/user.rules 2>&1 1>/dev/null
|
|
|
|
echo "Done."
|
|
|
|
echo "Done."
|
|
|
|
# commented out for debugging
|
|
|
|
# commented out for debugging
|
|
|
|
echo ""
|
|
|
|
echo ""
|
|
|
|