@ -230,29 +230,6 @@ echo "deb http://archive.ubuntu.com/ubuntu bionic-updates main universe" >> /mnt
echo "deb-src http://archive.ubuntu.com/ubuntu bionic-updates main universe" >> /mnt/etc/apt/sources.list
echo "deb-src http://archive.ubuntu.com/ubuntu bionic-updates main universe" >> /mnt/etc/apt/sources.list
echo "Done."
echo "Done."
#echo "network:" > /mnt/etc/netplan/bridge.yaml
#echo " version: 2" >> /mnt/etc/netplan/bridge.yaml
#echo " renderer: networkd" >> /mnt/etc/netplan/bridge.yaml
#echo " ethernets:" >> /mnt/etc/netplan/bridge.yaml
#for nic in "$nics"; do
#echo " ${nic}:" >> /mnt/etc/netplan/bridge.yaml
#echo " dhcp4: no" >> /mnt/etc/netplan/bridge.yaml
#done
#echo " bridges:" >> /mnt/etc/netplan/bridge.yaml
#echo " br0:" >> /mnt/etc/netplan/bridge.yaml
#echo " macaddress: ${macaddr}" >> /mnt/etc/netplan/bridge.yaml
#echo " dhcp4: yes" >> /mnt/etc/netplan/bridge.yaml
#echo " parameters:" >> /mnt/etc/netplan/bridge.yaml
#echo " stp: true" >> /mnt/etc/netplan/bridge.yaml
#echo " forward-delay: 0" >> /mnt/etc/netplan/bridge.yaml
#echo " interfaces:" >> /mnt/etc/netplan/bridge.yaml
#for nic in `echo "$nics"`; do
#echo " - ${nic}" >> /mnt/etc/netplan/bridge.yaml
#done
echo ""
echo ""
echo "Setting up boot pool import service..."
echo "Setting up boot pool import service..."
echo "[Unit]" > /mnt/etc/systemd/system/zfs-import-bpool.service
echo "[Unit]" > /mnt/etc/systemd/system/zfs-import-bpool.service
@ -268,7 +245,6 @@ echo "[Install]" >> /mnt/etc/systemd/system/zfs-import-bpool.service
echo " WantedBy=zfs-import.target " >> /mnt/etc/systemd/system/zfs-import-bpool.service
echo " WantedBy=zfs-import.target " >> /mnt/etc/systemd/system/zfs-import-bpool.service
echo "Done."
echo "Done."
echo ""
echo ""
echo "Creating home directory..."
echo "Creating home directory..."
errors = ` zfs create rpool/home/${ admin } 2>& 1 1>/dev/null`
errors = ` zfs create rpool/home/${ admin } 2>& 1 1>/dev/null`
@ -354,13 +330,6 @@ 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 } -part2) /boot/efi vfat nofail,x-systemd.device-timeout=0 0 1 >> /etc/fstab " >> /mnt/setup-chroot.sh
#echo "echo \"\"" >> /mnt/setup-chroot.sh
#echo "echo \"Mounting /boot/efi...\"" >> /mnt/setup-chroot.sh
#echo "mount /boot/efi 2>&1 1>/dev/null" >> /mnt/setup-chroot.sh
# clear past boots
#echo "for f in \`efibootmgr -v | grep -e '^Boot[0-9]\\+' | sed 's/^Boot\\([0-9]*\\).*/\\1/g'\`; do efibootmgr -b \$f -B; done" >> /mnt/setup-chroot.sh
#echo "echo \"Done.\"" >> /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
echo ' echo "Failed to mount EFI partition or install grub-EFI - $errors"' >> /mnt/setup-chroot.sh
echo ' echo "Failed to mount EFI partition or install grub-EFI - $errors"' >> /mnt/setup-chroot.sh
@ -383,15 +352,6 @@ echo " exit 102">> /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 "Enabling tmp file system mounting..."'>> /mnt/setup-chroot.sh
#echo "errors=\$(cp /usr/sharesystemd/tmp.mount /etc/systemd/system/ 2>&1 1>/dev/null && systemctl enable tmp.mount 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
#echo "if ! [ \"\$?\" = \"0\" ]; then echo \"Failed to enable tmp file system mounting - \$errors\"; exit 103; fi" >> /mnt/setup-chroot.sh
#echo 'echo "Done."'>> /mnt/setup-chroot.sh
#addgroup --system lpadmin
#addgroup --system sambashare
echo 'echo ""' >> /mnt/setup-chroot.sh
echo 'echo ""' >> /mnt/setup-chroot.sh
echo "echo \"Checking ZFS root...\"" >> /mnt/setup-chroot.sh
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
@ -414,7 +374,6 @@ echo "errors=\$(sed -ir 's/quiet splash//g' /etc/default/grub 2>&1 1>/dev/null &
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
echo 'echo ""' >> /mnt/setup-chroot.sh
echo 'echo ""' >> /mnt/setup-chroot.sh
echo 'echo "Updating grub..."' >> /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 'errors=$(update-grub 2>&1 1>/dev/null)' >> /mnt/setup-chroot.sh
@ -455,16 +414,12 @@ echo "echo \"rpool/var/tmp /var/tmp zfs nodev,relatime 0 0\" >> /etc/fstab" >> /
echo "zfs set mountpoint=legacy rpool/tmp" >> /mnt/setup-chroot.sh
echo "zfs set mountpoint=legacy rpool/tmp" >> /mnt/setup-chroot.sh
echo "echo \"rpool/tmp /tmp zfs nodev,relatime 0 0\" >> /etc/fstab" >> /mnt/setup-chroot.sh
echo "echo \"rpool/tmp /tmp zfs nodev,relatime 0 0\" >> /etc/fstab" >> /mnt/setup-chroot.sh
echo 'echo ""' >> /mnt/setup-chroot.sh
echo 'echo ""' >> /mnt/setup-chroot.sh
echo 'echo "Enabling SSH..."' >> /mnt/setup-chroot.sh
echo 'echo "Enabling SSH..."' >> /mnt/setup-chroot.sh
echo "sed -ir 's/^ *#? *ChallengeResponseAuthentication.*/ChallengeResponseAuthentication no/g' /etc/ssh/sshd_config" >> /mnt/setup-chroot.sh
echo "sed -ir 's/^ *#? *ChallengeResponseAuthentication.*/ChallengeResponseAuthentication no/g' /etc/ssh/sshd_config" >> /mnt/setup-chroot.sh
echo "sed -ir 's/^#PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config" >> /mnt/setup-chroot.sh
echo "sed -ir 's/^#PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config" >> /mnt/setup-chroot.sh
echo "sed -ir 's/^UsePAM.*/UsePAM no/g' /etc/ssh/sshd_config" >> /mnt/setup-chroot.sh
echo "sed -ir 's/^UsePAM.*/UsePAM no/g' /etc/ssh/sshd_config" >> /mnt/setup-chroot.sh
echo "sed -ir 's/^#PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config" >> /mnt/setup-chroot.sh
echo "sed -ir 's/^#PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config" >> /mnt/setup-chroot.sh
echo "errors=\$(systemctl enable ssh 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
echo "errors=\$(systemctl enable ssh 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
#&& ufw allow in on any from any to any port 22 proto tcp 2>&1 1>/dev/null
#&& ufw allow in on any from any to any port 22 proto tcp 2>&1 1>/dev/null
echo 'if ! [ \"$?\" = \"0\" ]; then ' >> /mnt/setup-chroot.sh
echo 'if ! [ \"$?\" = \"0\" ]; then ' >> /mnt/setup-chroot.sh
@ -483,14 +438,6 @@ echo "usermod -a -G adm,cdrom,dip,plugdev,sudo -s /bin/bash \"$admin\"" >> /mnt/
echo " echo ' ${ admin } : ${ rootpassword } ' | chpasswd " >> /mnt/setup-chroot.sh
echo " echo ' ${ admin } : ${ rootpassword } ' | chpasswd " >> /mnt/setup-chroot.sh
echo 'echo "Done."' >> /mnt/setup-chroot.sh
echo 'echo "Done."' >> /mnt/setup-chroot.sh
# relax app armor for nfs kernel server
#echo "aa-complain nfsd" >> /mnt/setup-chroot.sh
#create swap space, too if necessary
#sendemail -t to@example.com -m "Here is the file." -a attachmentFile
echo " mkdir \"/home/ ${ admin } /.ssh\" " >> /mnt/setup-chroot.sh
echo " mkdir \"/home/ ${ admin } /.ssh\" " >> /mnt/setup-chroot.sh
echo " ssh-keygen -b 4096 -t rsa -q -f \"/home/ ${ admin } /.ssh/id_rsa\" -N ' $rootpassword ' " >> /mnt/setup-chroot.sh
echo " ssh-keygen -b 4096 -t rsa -q -f \"/home/ ${ admin } /.ssh/id_rsa\" -N ' $rootpassword ' " >> /mnt/setup-chroot.sh
echo " cat /home/ ${ admin } /.ssh/id_rsa.pub > \"/home/ ${ admin } /.ssh/authorized_keys\" " >> /mnt/setup-chroot.sh
echo " cat /home/ ${ admin } /.ssh/id_rsa.pub > \"/home/ ${ admin } /.ssh/authorized_keys\" " >> /mnt/setup-chroot.sh
@ -516,13 +463,11 @@ if [ "$networktype" = "dhcp" ]; then
else
else
connection = " $address "
connection = " $address "
fi
fi
# --content-filename=\"${hostname}.ssh.key\" --content-name=\"${hostname}.ssh.key\"
echo " serverinfo=\`cat \"/home/ ${ admin } /.ssh/id_rsa\"\` " >> /mnt/setup-chroot.sh
echo " serverinfo=\`cat \"/home/ ${ admin } /.ssh/id_rsa\"\` " >> /mnt/setup-chroot.sh
#echo "serverinfo=\"Server available at $connection\\n\$serverinfo\"; echo \"\$serverinfo\" | mail -s \"$hostname SSH key\" -A \"/home/${admin}/.ssh/id_rsa\" -r \"${email}\" \"${admins}\"" >> /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 " 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 "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 "
@ -564,19 +509,6 @@ echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
echo "exit 0" >> /mnt/setup-chroot.sh
echo "exit 0" >> /mnt/setup-chroot.sh
chroot /mnt /setup-chroot.sh
chroot /mnt /setup-chroot.sh
if ! [ " $? " = "0" ] ; then
if ! [ " $? " = "0" ] ; then
exit $?
exit $?
@ -592,8 +524,6 @@ fi
echo "/dev/zvol/rpool/swap none swap discard 0 0" >> /mnt/etc/fstab
echo "/dev/zvol/rpool/swap none swap discard 0 0" >> /mnt/etc/fstab
echo "Done."
echo "Done."
#ececho "RESUME=none" > /mnt/etc/initramfs.tools/conf.d/resume
echo ""
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/' )
@ -624,14 +554,6 @@ echo " bridge_stp on" >> /mnt/etc/network/interfaces.d/br0
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."
#crontab -l > mycron
#echo new cron into cron file
#echo "00 09 * * 1-5 echo hello" >> mycron
#install new cron file
#crontab mycron
#rm mycron
# add the firewall rule for SSH, but there may already be an exception for this, test the network in the live environment
# add the firewall rule for SSH, but there may already be an exception for this, test the network in the live environment
echo ""
echo ""
@ -644,7 +566,6 @@ echo "Clearing chroot configuration script..."
rm /mnt/setup-chroot.sh
rm /mnt/setup-chroot.sh
echo "Done."
echo "Done."
echo "#! /bin/bash" > /mnt/zfshealth.sh
echo "#! /bin/bash" > /mnt/zfshealth.sh
echo "problems=0; emailSubject=\"\`hostname\` - ZFS pool - HEALTH check\"; emailMessage=\"\"" >> /mnt/zfshealth.sh
echo "problems=0; emailSubject=\"\`hostname\` - ZFS pool - HEALTH check\"; emailMessage=\"\"" >> /mnt/zfshealth.sh
echo "condition=\$(/sbin/zpool status | grep -e \"^ *state:\" | egrep -i '(DEGRADED|FAULTED|OFFLINE|UNAVAIL|REMOVED|FAIL|DESTROYED|corrupt|cannot|unrecover)')" >> /mnt/zfshealth.sh
echo "condition=\$(/sbin/zpool status | grep -e \"^ *state:\" | egrep -i '(DEGRADED|FAULTED|OFFLINE|UNAVAIL|REMOVED|FAIL|DESTROYED|corrupt|cannot|unrecover)')" >> /mnt/zfshealth.sh
@ -683,8 +604,6 @@ echo "if [ \"\$problems\" -ne 0 ]; then logger \$emailSubject; fi" >> /mnt/zfshe
chmod +x /mnt/zfshealth.sh
chmod +x /mnt/zfshealth.sh
echo ""
echo ""
echo "Unmounting chroot mounts..."
echo "Unmounting chroot mounts..."
mount | grep -v zfs | tac | awk '/\/mnt/ {print $3}' | xargs -i{ } umount -lf { }
mount | grep -v zfs | tac | awk '/\/mnt/ {print $3}' | xargs -i{ } umount -lf { }
@ -702,6 +621,4 @@ echo "Done."
echo ""
echo ""
echo "Congratulations! The install was successful. Please reboot and set your boot device using UEFI in the BIOS. You should receive an e-mail with the server's SSH private key shortly."
echo "Congratulations! The install was successful. Please reboot and set your boot device using UEFI in the BIOS. You should receive an e-mail with the server's SSH private key shortly."
echo ""
echo ""
exit 0
exit 0
#sed -i -r "s/(^|[^#y])(compress)/\1#\2/" "$file"