test
sean 7 years ago
parent 0b33dd6be9
commit fac4a088ae

@ -27,19 +27,19 @@ window=$((height - 5))
# gather input at the start
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 boot drives" $height $width ${window}$devices 2>&1 1>/dev/tty`
raidtype=`dialog --no-items --no-cancel --title "Root pool ZFS RAID" --radiolist "Select root pool ZFS RAID type" 12 35 5 raidz off raidz2 off raidz3 off mirror off none off 2>&1 1>/dev/tty`
hostname=""; while [ -z "$hostname" ]; do hostname=`dialog --no-cancel --inputbox "Host name/Server name" 8 30 2>&1 >/dev/tty`; done
disks=`dialog --separate-output --no-cancel --no-items --title "Root devices" --checklist "Select boot drives:" $height $width ${window}$devices 2>&1 1>/dev/tty`
raidtype=`dialog --no-items --no-cancel --title "Root pool ZFS RAID" --radiolist "Select root pool ZFS RAID type:" 12 35 5 raidz off raidz2 off raidz3 off mirror off none off 2>&1 1>/dev/tty`
hostname=""; while [ -z "$hostname" ]; do hostname=`dialog --no-cancel --inputbox "Hostname:" 8 40 2>&1 >/dev/tty`; done
nicdevices=""; for nic in $(ip -o link show | awk -F': ' '{print $2}' | grep -v '^lo'); do nicdevices="$nicdevices $nic off"; done
nics=`dialog --separate-output --no-cancel --no-items --title "Network devices for bridge" --checklist "Select the network devices to be bridged" $height $width ${window}$nicdevices 2>&1 1>/dev/tty`
admin=""; while [ -z "$admin" ]; do admin=`dialog --no-cancel --inputbox "Admin account/first user (with sudo capability)" 8 30 2>&1 >/dev/tty`; done
rootpassword=`dialog --no-cancel --title "Root password" --insecure --passwordbox "Enter root password" 8 30 2>&1 1>/dev/tty`
confirmpassword=`dialog --no-cancel --title "Root password confirmation" --insecure --passwordbox "Re-enter root password" 8 30 2>&1 1>/dev/tty`
admin=""; while [ -z "$admin" ]; do admin=`dialog --no-cancel --inputbox "Admin user:" 8 40 2>&1 >/dev/tty`; done
rootpassword=`dialog --no-cancel --title "Root password" --insecure --passwordbox "Enter root password:" 8 40 2>&1 1>/dev/tty`
confirmpassword=`dialog --no-cancel --title "Root password confirmation" --insecure --passwordbox "Re-enter root password:" 8 40 2>&1 1>/dev/tty`
if ! [ "$rootpassword" = "$confirmpassword" ]; then
echo "Password does not match confirmation - please retry the setup"
exit 10
fi
timezone=`dialog --no-cancel --title "Timezone" --inputbox "Enter time zone" $height $width "America/Los_Angeles" 2>&1 1>/dev/tty`
timezone=`dialog --no-cancel --title "Timezone" --inputbox "Time zone:" $height $width "America/Los_Angeles" 2>&1 1>/dev/tty`
for disk in `echo "$disks"`; do
echo ""
@ -60,11 +60,13 @@ partprobe 2>/dev/null 1>/dev/null
# wait for the partitions to show up
for disk in `echo "$disks"`; do
pending="0"
while ! [ -e "/dev/disk/by-id/${disk}-part3" ]; do
partprobe 2>/dev/null 1>/dev/null
echo "Waiting for ${disk} partition 3 to update..."
if [ "$pending" = "0" ]; then echo "" && echo "Waiting for ${disk} partition 3 to update..."; pending="1"; fi
sleep 3
done
if [ "$pending" = "1" ]; then echo "Done."; fi
done
echo ""
@ -104,7 +106,6 @@ echo "Done."
echo ""
echo "Bootstrapping..."
#debootstrap bionic /mnt
errors=`debootstrap bionic /mnt 2>&1 1>/dev/null`
if ! [ "$?" = "0" ]; then
echo "Failed to bootstrap root - $errors"
@ -140,7 +141,7 @@ echo "Done."
# network configuration should have optional static configuration - not just DHCP, it's very important
echo ""
echo "Writing netplan file"
echo "Writing netplan file..."
macaddr=$(echo $hostname|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')
echo "network:" > /mnt/etc/netplan/bridge.yaml
echo " version: 2" >> /mnt/etc/netplan/bridge.yaml
@ -218,13 +219,13 @@ echo ' echo "Failed to set the locale to en_US.UTF-8 - $errors"' >> /mnt/setup-c
echo " exit 1">> /mnt/setup-chroot.sh
echo "fi">> /mnt/setup-chroot.sh
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
echo "echo \"\""
echo "echo \"Setting time zone...\""
echo "echo \"\"" >> /mnt/setup-chroot.sh
echo "echo \"Setting time zone...\"" >> /mnt/setup-chroot.sh
echo "cp /usr/share/zoneinfo/$timezone /etc/localtime" >> /mnt/setup-chroot.sh
echo "echo \"Done.\""
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
echo "echo \"\""
echo "echo \"Installing linux image, bash, screen, tmux, zfs, dosfstools, openssh...\""
echo "echo \"\"" >> /mnt/setup-chroot.sh
echo "echo \"Installing linux image, bash, screen, tmux, zfs, dosfstools, openssh...\"" >> /mnt/setup-chroot.sh
echo "errors=\$(apt install -y --no-install-recommends linux-image-generic 2>&1 1>/dev/null && apt install -y vim bash screen tmux zfs-initramfs dosfstools openssh-server 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
echo 'if ! [ "$?" = "0" ]; then '>> /mnt/setup-chroot.sh
echo ' echo "Failed to install preliminary software - $errors"' >> /mnt/setup-chroot.sh
@ -237,8 +238,7 @@ echo 'echo "Creating EFI partition..."' >> /mnt/setup-chroot.sh
firstdisk=`echo "$disks" | head -n1`
echo "mkdosfs -F 32 -s 1 -n EFI /dev/disk/by-id/${firstdisk}-part2 && mkdir /boot/efi" >> /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 "mount /boot/efi" >> /mnt/setup-chroot.sh
echo "apt install -y grub-efi-amd64-signed shim-signed" >> /mnt/setup-chroot.sh
echo "mount /boot/efi && apt install -y grub-efi-amd64-signed shim-signed" >> /mnt/setup-chroot.sh
echo 'echo "Done..."' >> /mnt/setup-chroot.sh
if ! [ "$disks" = "" ]; then
@ -246,14 +246,18 @@ if ! [ "$disks" = "" ]; then
echo 'echo "Copying EFI partition to other boot disks..."' >> /mnt/setup-chroot.sh
i="2"
for disk in `echo "$disks" | tail -n+2`; do
echo "dd if=/dev/disk/by-id/${firstdisk}-part2 of=/dev/disk/by-id/${disk}-part2" >> /mnt/setup-chroot.sh
echo "efibootmgr -c -g -d /dev/disk/by-id/${disk} -p 3 -L "ubuntu-$i" -l '\EFI\ubuntu\grubx64.efi'" >> /mnt/setup-chroot.sh
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 "if ! [ \"\$?\" = \"0\" ]; then echo \"EFI copy failed - \$errors\"; exit 20; fi" >> /mnt/setup-chroot.sh
i=$((i + 1))
done
echo 'echo "Done."' >> /mnt/setup-chroot.sh
fi
echo "echo 'root:${rootpassword}' | chpasswd" >> /mnt/setup-chroot.sh
echo "echo ''" >> /mnt/setup-chroot.sh
echo 'echo "Setting root password..."' >> /mnt/setup-chroot.sh
echo "errors=\$(echo 'root:${rootpassword}' | chpasswd 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
echo "if ! [ \"\$?\" = \"0\" ]; then echo \"Could not set root password - \$errors\"; exit 21; fi" >> /mnt/setup-chroot.sh
echo 'echo "Done."'>> /mnt/setup-chroot.sh
echo "systemctl enable zfs-import-bpool.service" >> /mnt/setup-chroot.sh
@ -264,16 +268,30 @@ echo "systemctl enable zfs-import-bpool.service" >> /mnt/setup-chroot.sh
#addgroup --system sambashare
echo "echo \"Checking ZFS root...\"" >> /mnt/setup-chroot.sh
echo "zfscheck=`grub-probe /boot 2\>\&1 1\>/dev/null`" >> /mnt/setup-chroot.sh
echo 'zfscheck=$(grub-probe /boot 2>&1 1>/dev/null`' >> /mnt/setup-chroot.sh
echo "if ! [ \"\$?\" = \"0\" ]; then echo \"grub-probe check failed - \$zfscheck\"; exit 2; fi" >> /mnt/setup-chroot.sh
echo "echo \"Success.\"" >> /mnt/setup-chroot.sh
echo "update-initramfs -u -k all" >> /mnt/setup-chroot.sh
echo 'echo ""' >> /mnt/setup-chroot.sh
echo 'echo "Updating initramfs..."' >> /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 ' echo "Failed to update initramfs - $errors"' >> /mnt/setup-chroot.sh
echo " exit 1">> /mnt/setup-chroot.sh
echo "fi">> /mnt/setup-chroot.sh
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
# you need sed to do this right!
# GRUB_CMDLINE_LINUX="root=ZFS=rpool/ROOT/ubuntu" <--- replace this
echo "update-grub">> /mnt/setup-chroot.sh
echo 'echo ""' >> /mnt/setup-chroot.sh
echo 'echo "Updating grub..."' >> /mnt/setup-chroot.sh
echo 'errors=$(update-grub 2>&1 1>/dev/null)'>> /mnt/setup-chroot.sh
echo 'if ! [ "$?" = "0" ]; then '>> /mnt/setup-chroot.sh
echo ' echo "Failed to update grub - $errors"' >> /mnt/setup-chroot.sh
echo " exit 1">> /mnt/setup-chroot.sh
echo "fi">> /mnt/setup-chroot.sh
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
echo "grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck --no-floppy" >> /mnt/setup-chroot.sh
echo "umount /boot/efi" >> /mnt/setup-chroot.sh

Loading…
Cancel
Save