Compare commits

73 Commits
Author SHA1 Message Date
Sean 1c607bd09a tweaks 2019-07-10 18:12:50 -07:00
Sean cadf53b85c tweaks 2019-07-10 16:43:47 -07:00
sean 7f1fbd3039 tweaks 2019-07-10 15:54:27 -07:00
sean 5c4982b1c7 tweaks 2019-07-10 15:29:58 -07:00
sean 197bbbe770 tweaks 2019-07-10 15:17:06 -07:00
sean 7b7853ecb8 tweaks 2019-07-10 15:04:14 -07:00
sean c3c45019bc tweaks 2019-07-10 14:57:16 -07:00
sean 9289844c99 tweaks 2019-07-10 14:50:54 -07:00
sean de7b8b3acd tweaks 2019-07-10 14:38:17 -07:00
sean 9ec289c136 tweaks 2019-07-10 14:25:44 -07:00
sean 6617d2f84d tweaks 2019-07-10 14:24:25 -07:00
sean 2ba9cb07da test tweaks 2019-07-10 14:02:59 -07:00
sean fac4a088ae tweaks 2019-07-10 12:31:44 -07:00
sean 0b33dd6be9 tweaks 2019-07-10 12:12:54 -07:00
sean a3c89343ac bad line endings? 2019-07-10 12:10:16 -07:00
sean def54b1a4f tweaks 2019-07-10 12:08:10 -07:00
sean b75109612f tweaks 2019-07-10 11:54:15 -07:00
sean 9e4fc3b35c tweaks 2019-07-10 01:33:29 -07:00
sean f212017cb4 tweaks 2019-07-10 01:22:10 -07:00
sean 71c1d92ed9 tweaks 2019-07-10 01:19:21 -07:00
sean 4d4d715fc1 tweaks 2019-07-09 21:13:20 -07:00
sean ebd0d89da9 tweaks 2019-07-09 20:42:13 -07:00
sean 394b8999df tweaks 2019-07-09 20:35:43 -07:00
sean 0fc329a922 tweaks 2019-07-09 20:30:26 -07:00
sean 791c10684f tweaks 2019-07-09 19:49:59 -07:00
sean a3de013ecb tweaks 2019-07-09 19:09:59 -07:00
sean 9ceac41631 tweaks 2019-07-09 18:54:12 -07:00
sean 63656fb07a tweaks 2019-07-09 18:45:18 -07:00
sean 19281f3ee6 tweaks 2019-07-09 18:40:44 -07:00
sean 2a91f9e118 tweaks 2019-07-09 18:24:54 -07:00
sean 1579bf11e8 tweaks 2019-07-09 18:17:26 -07:00
sean a0bc8b8ed1 tweaks 2019-07-09 18:02:57 -07:00
sean 8f6ae4707d tweaks 2019-07-09 17:59:06 -07:00
sean a896b8b888 tweaks 2019-07-09 17:47:42 -07:00
sean 7c12d73eec new tweaks 2019-07-09 17:38:33 -07:00
sean 19d8d7ce33 tweaks 2019-07-09 17:19:48 -07:00
sean c8f3c3d62b Tweaks 2019-07-09 17:05:43 -07:00
sean e26290c9e8 testing 2019-07-09 16:27:22 -07:00
sean 74a71e86c4 this was the problem 2019-07-09 16:08:07 -07:00
sean 474075ff87 test tweak 2019-07-09 15:08:13 -07:00
sean 74054d9634 tweaks 2019-07-09 14:57:20 -07:00
sean 45b20879eb tweaks 2019-07-09 14:46:10 -07:00
sean 74985dfc81 tweaks 2019-07-09 14:36:36 -07:00
sean dcd2fc35eb tweaks 2019-07-09 14:26:33 -07:00
sean 422e5f71fe testing another tweak 2019-07-09 14:19:54 -07:00
sean d95da849f8 tweaks 2019-07-09 14:15:33 -07:00
sean bf368d0d25 tweaks but not really 2019-07-09 14:11:20 -07:00
sean 5e45529a0d tweaks 2019-07-09 14:08:44 -07:00
sean c58ae06775 tweaks 2019-07-09 14:05:15 -07:00
sean 386b7a00e4 tweaks 2019-07-09 14:02:04 -07:00
sean 563a7328f4 tweaks 2019-07-09 13:58:40 -07:00
sean c0ac3d7a12 irritating tweaks 2019-07-09 13:54:52 -07:00
sean 17ebeaa3f7 tweaks 2019-07-09 13:51:52 -07:00
sean 6863e39c9c test 2019-07-09 13:51:05 -07:00
sean a55e02e1e0 tweak 2019-07-09 13:49:46 -07:00
sean 27ea4b4411 tweaks 2019-07-09 13:44:40 -07:00
sean 059249eed2 tweaks and tests 2019-07-09 13:42:04 -07:00
sean c0b5434f44 tweaks 2019-07-09 13:37:47 -07:00
sean edf841a06e tweaks 2019-07-09 13:33:36 -07:00
sean dc0f7796b2 tweaks 2019-07-09 13:31:34 -07:00
sean 9438c07e25 tweaks test 2019-07-09 13:29:16 -07:00
sean f08d10d009 test tweak 2019-07-09 13:27:46 -07:00
sean f369fb70a7 tweaks 2019-07-09 13:24:26 -07:00
sean a02cf785e5 tweaks 2019-07-09 13:21:23 -07:00
sean 5e83fbf3d2 tweaks 2019-07-09 13:14:26 -07:00
sean 8ca216cae2 tweaks 2019-07-09 12:57:42 -07:00
sean 43bea157fe tweaks 2019-07-09 12:50:21 -07:00
sean 96fa360d27 tweak 2019-07-09 12:47:45 -07:00
sean 9c3bc33373 tweaks 2019-07-09 12:43:07 -07:00
sean 0d60a61c39 tweaks 2019-07-09 12:40:55 -07:00
sean 5857371570 Fixed line endings, utf8 encoding 2019-07-09 12:32:40 -07:00
sean bc0d29539d Untested - unfinished, just saving state 2019-07-08 19:24:45 -07:00
sean d4d0debe30 mods 2019-07-08 17:48:59 -07:00
3 changed files with 482 additions and 1 deletions
+1 -1
View File
@@ -2,4 +2,4 @@ Server Setup Script
===================== =====================
#Use# #Use#
curl -sSL https://code.totosearch.org/Sean/ServerSetup/setup.sh | sh wget -qO - https://code.totosearch.org/Sean/ServerSetup/raw/branch/master/setup.sh | sudo bash
+86
View File
@@ -0,0 +1,86 @@
#! /bin/bash
echo ""
echo "Mounting /proc/self/mounts..."
ln -s /proc/self/mounts /etc/mtab
echo "Done."
echo ""
echo "Updating apt repositories inside chroot..."
errors=`apt update 2>&1 1>/dev/null`
if ! [ "$?" = "0" ]; then
echo "Failed to update apt repositories inside chroot - $errors"
exit 1
fi
echo "Done."
echo ""
echo "Setting locale..."
echo -e 'LANG="en_US.UTF-8"\nLANGUAGE="en_US:en"\n' > /etc/default/locale
echo "Done."
#dpkg-reconfigure tzdata
#apt install -y --no-install-recommends linux-image-generic
#apt install -y vim bash screen tmux zfs-initramfs dosfstools openssh-server
i="0"
for disk in "$disks"; do
echo "mkdosfs -F 32 -s 1 -n EFI /dev/disk/by-id/${disk}-part2"
echo "mkdir /boot/efi${i}"
echo "echo PARTUUID=$(blkid -s PARTUUID -o value /dev/disk/by-id/${disk}-part2) /boot/efi${i} vfat nofail,x-systemd.device-timeout=0 0 1 >> /etc/fstab"
echo "mount /boot/efi${i}"
i=$((i + 1))
done
#apt install -y grub-efi-amd64-signed shim-signed
#passwd
#echo "[Unit]\n DefaultDependencies=no\n Before=zfs-import-scan.service\n Before=zfs-import-cache.service\n \n [Service]\n Type=oneshot\n RemainAfterExit=yes\n ExecStart=/sbin/zpool import -N -o cachefile=none bpool\n [Install]\n WantedBy=zfs-import.target " > /etc/systemd/system/zfs-import-bpool.Service"
#systemctl enable zfs-import-bpool.Service
#cp /usr/sharesystemd/tmp.mount /etc/systemd/system/
#systemctl enable tmp.mount
#addgroup --system lpadmin
#addgroup --system sambashare
#zfscheck=`grub-probe /boot`
#update-initramfs -u -k all
# you need sed to do this right!
# GRUB_CMDLINE_LINUX="root=ZFS=rpool/ROOT/ubuntu" <--- replace this
#update-grub
#i="0"
#for f in "$disks"; do
#echo "grub-install --target=x86_64-efi --efi-directory=/boot/efi${i} --botloader-id=ubuntu --recheck --no-floppy"
#echo "umount /boot/efi${i}"
#i=$((i + 1))
#done
#zfs set mountpoint=legacy bpool/BOOT/ubuntu
#echo bpool/BOOT/ubuntu /boot zfs nodev,relatime,x-systemd.requires=zfs-import-bpool.service 0 0 >> /etc/fstab
#zfs set mountpoint=legacy rpool/var/log
#echo rpool/var/log /var/log zfs nodev,relatime 0 0 >> /etc/fstab
#zfs set mountpoint=legacy rpool/var/spool
#echo rpool/var/spool /var/spool zfs nodev,relatime 0 0 >> /etc/fstab
#zfs set mountpoint=legacy rpool/var/tmp
#echo rpool/var/tmp /var/tmp zfs nodev,relatime 0 0 >> /etc/fstab
#zfs set mountpoint=legacy rpool/tmp
#echo rpool/tmp /tmp zfs nodev,relatime 0 0 >> /etc/fstab
#systemctl enable openssh-server
# create parker user automated way
#zfs create rpool/home/YOURUSERNAME
# adduser YOURUSERNAME
# cp -a /etc/skel/.[!.]* /home/YOURUSERNAME
# chown -R YOURUSERNAME:YOURUSERNAME /home/YOURUSERNAME
# usermod -a -G adm,cdrom,dip,lpadmin,plugdev,sambashare,sudo YOURUSERNAME
#create swap space, too if necessary
exit 0
+395
View File
@@ -0,0 +1,395 @@
#! /bin/bash
echo ""
echo "Updating local packages..."
errors=`apt-add-repository universe >/dev/null 2>/dev/null && apt update 2>&1 >/dev/null`
if [ "$?" = "0" ]; then
echo "Done."
else
echo "Failed to add universal repository, update apt repository - $errors"
exit 1
fi
echo ""
echo "Installing required setup configuration utilities..."
apt install -y dialog net-tools gdisk zfs-initramfs debootstrap >/dev/null 2>/dev/null
if [ "$?" = "0" ]; then
echo "Done."
else
echo "Failed to install net-tools, gdisk, zfs-initramfs, or debootstrap."
exit 2
fi
#calculate width and height of console
width=`tput cols`
height=`tput lines`
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 "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 "Bridged network devices" --checklist "Select the network devices to be bridged to br0:" $height $width ${window}$nicdevices 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 "Time zone:" 8 40 "America/Los_Angeles" 2>&1 1>/dev/tty`
for disk in `echo "$disks"`; do
echo ""
echo "Partitioning disk $disk..."
errors=`sgdisk --zap-all /dev/disk/by-id/$disk 2>&1 1>/dev/null && 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 && sgdisk -n4:0:0 -t4:BF01 /dev/disk/by-id/$disk 2>&1 1>/dev/null`
if ! [ "$?" = "0" ]; then
echo "Failed to partition disk $disk - $errors"
exit 3
fi
echo "Done."
done
# create boot mirror 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
# refresh drives or there are missing partitions
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
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 ""
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`
if ! [ "$?" = "0" ]; then
echo "Failed to create boot pool - $errors"
exit 4
fi
echo "Done."
# special exception for none raid - this just operates the disks like a stripe, for 1 or more disk - *not* recommended
if [ "$raidtype" = "none" ]; then
raidtype=""
else
raidtype=" $raidtype"
fi
echo ""
echo "Creating main zpool..."
error=`zpool create -f -o ashift=12 -O acltype=posixacl -O canmount=off -O compression=lz4 -O dnodesize=auto -O normalization=formD -O relatime=on -O xattr=sa -O mountpoint=/ -R /mnt rpool${raidtype}${rootraidz} 2>&1 1>/dev/null`
if ! [ "$?" = "0" ]; then
echo "Failed to create main pool - $errors"
exit 5
fi
echo "Done."
echo ""
echo "Setting up main zpool dataset configuration..."
errors=`zfs create -o canmount=off -o mountpoint=none rpool/ROOT 2>&1 1>/dev/null && zfs create -o canmount=off -o mountpoint=none bpool/BOOT 2>&1 1>/dev/null && zfs create -o canmount=noauto -o mountpoint=/ rpool/ROOT/ubuntu 2>&1 1>/dev/null && zfs mount rpool/ROOT/ubuntu 2>&1 1>/dev/null && zfs create -o canmount=noauto -o mountpoint=/boot bpool/BOOT/ubuntu 2>&1 1>/dev/null && zfs mount bpool/BOOT/ubuntu 2>&1 1>/dev/null && zfs create rpool/home 2>&1 1>/dev/null && zfs create -o mountpoint=/root rpool/home/root 2>&1 1>/dev/null && zfs create -o canmount=off rpool/var 2>&1 1>/dev/null && zfs create -o canmount=off rpool/var/lib 2>&1 1>/dev/null && zfs create rpool/var/log 2>&1 1>/dev/null && zfs create rpool/var/spool 2>&1 1>/dev/null && zfs create -o com.sun:auto-snapshot=false rpool/var/cache 2>&1 1>/dev/null && zfs create -o com.sun:auto-snapshot=false rpool/var/tmp 2>&1 1>/dev/null && chmod 1777 /mnt/var/tmp 2>&1 1>/dev/null && zfs create rpool/opt 2>&1 1>/dev/null && zfs create rpool/srv 2>&1 1>/dev/null && zfs create -o canmount=off rpool/usr 2>&1 1>/dev/null && zfs create rpool/usr/local 2>&1 1>/dev/null && zfs create rpool/var/mail 2>&1 1>/dev/null && zfs create -o com.sun:auto-snapshot=false rpool/var/lib/docker 2>&1 1>/dev/null && zfs create -o com.sun:auto-snapshot=false rpool/var/lib/nfs 2>&1 1>/dev/null && zfs create -o com.sun:auto-snapshot=false rpool/tmp 2>&1 1>/dev/null && chmod 1777 /mnt/tmp 2>&1 1>/dev/null`
if ! [ "$?" = "0" ]; then
echo "Error setting up ZFS settings - $errors"
exit 5
fi
echo "Done."
echo ""
echo "Bootstrapping..."
errors=`debootstrap bionic /mnt 2>&1 1>/dev/null`
if ! [ "$?" = "0" ]; then
echo "Failed to bootstrap root - $errors"
exit 6
fi
echo "Done."
echo ""
echo "Disabling ZFS devices..."
errors=`zfs set devices=off rpool 2>&1 1>/dev/null`
if ! [ "$?" = "0" ]; then
echo "Failed to set devices=off for root pool- $errors"
exit 7
fi
echo "Done."
echo ""
echo "Setting hostname..."
echo "$hostname" > /mnt/etc/hostname
echo "127.0.1.1 $hostname" >> /mnt/etc/hosts
echo "Done."
echo ""
echo "Setting default apt repositories"
echo "deb http://archive.ubuntu.com/ubuntu bionic main universe" > /mnt/etc/apt/sources.list
echo "deb-src http://archive.ubuntu.com/ubuntu bionic main universe" >> /mnt/etc/apt/sources.list
echo "deb http://security.ubuntu.com/ubuntu bionic-security main universe" >> /mnt/etc/apt/sources.list
echo "deb-src http://security.ubuntu.com/ubuntu bionic-security main universe" >> /mnt/etc/apt/sources.list
echo "deb 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."
# network configuration should have optional static configuration - not just DHCP, it's very important
echo ""
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
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 " interfaces:" >> /mnt/etc/netplan/bridge.yaml
for nic in `echo "$nics"`; do
echo " - ${nic}" >> /mnt/etc/netplan/bridge.yaml
done
echo "Done."
echo ""
echo "Setting up boot pool import service..."
echo "[Unit]"> /mnt/etc/systemd/system/zfs-import-bpool.service
echo " DefaultDependencies=no" >> /mnt/etc/systemd/system/zfs-import-bpool.service
echo " Before=zfs-import-scan.service" >> /mnt/etc/systemd/system/zfs-import-bpool.service
echo " Before=zfs-import-cache.service" >> /mnt/etc/systemd/system/zfs-import-bpool.service
echo "" >> /mnt/etc/systemd/system/zfs-import-bpool.service
echo "[Service]" >> /mnt/etc/systemd/system/zfs-import-bpool.service
echo " Type=oneshot" >> /mnt/etc/systemd/system/zfs-import-bpool.service
echo " RemainAfterExit=yes" >> /mnt/etc/systemd/system/zfs-import-bpool.service
echo " ExecStart=/sbin/zpool import -N -o cachefile=none bpool" >> /mnt/etc/systemd/system/zfs-import-bpool.service
echo "[Install]" >> /mnt/etc/systemd/system/zfs-import-bpool.service
echo " WantedBy=zfs-import.target " >> /mnt/etc/systemd/system/zfs-import-bpool.service
echo "Done."
echo ""
echo "Creating home directory..."
errors=`zfs create rpool/home/${admin} 2>&1 1>/dev/null`
if ! [ "$?" = "0" ]; then
echo "Unable to create home directory - $errors"
exit 9
fi
echo ""
echo "Mounting chroot mounts..."
mount --rbind /dev /mnt/dev
mount --rbind /proc /mnt/proc
mount --rbind /sys /mnt/sys
echo "Done."
echo ""
echo "Entering chroot..."
echo "#!/bin/bash" > /mnt/setup-chroot.sh
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
echo "echo \"\"" >> /mnt/setup-chroot.sh
echo "echo \"Mounting /proc/self/mounts...\"" >> /mnt/setup-chroot.sh
echo "ln -s /proc/self/mounts /etc/mtab" >> /mnt/setup-chroot.sh
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
echo "echo \"\"" >> /mnt/setup-chroot.sh
echo "echo \"Updating apt repositories on root pool...\"" >> /mnt/setup-chroot.sh
echo 'errors=`apt update 2>&1 1>/dev/null`' >> /mnt/setup-chroot.sh
echo 'if ! [ "$?" = "0" ]; then '>> /mnt/setup-chroot.sh
echo ' echo "Failed to update apt repositories on root pool - $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 "echo \"\"">> /mnt/setup-chroot.sh
echo "echo \"Setting locale...\"" >> /mnt/setup-chroot.sh
echo 'errors=`locale-gen en_US.UTF-8 2>&1 1>/dev/null`' >> /mnt/setup-chroot.sh
echo 'if ! [ "$?" = "0" ]; then '>> /mnt/setup-chroot.sh
echo ' echo "Failed to set the locale to en_US.UTF-8 - $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 "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.\"" >> /mnt/setup-chroot.sh
echo "echo \"\"" >> /mnt/setup-chroot.sh
echo "echo \"Installing linux image, bash, screen, tmux, zfs, vim, dosfstools, openssh, ufw...\"" >> /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 ufw 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
echo " exit 1">> /mnt/setup-chroot.sh
echo "fi">> /mnt/setup-chroot.sh
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
echo 'echo ""' >> /mnt/setup-chroot.sh
echo 'echo "Creating EFI partition..."' >> /mnt/setup-chroot.sh
firstdisk=`echo "$disks" | 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 'if ! [ "$?" = "0" ]; then '>> /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 "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 "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 ' echo "Failed to mount EFI partition or install grub-EFI - $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
if ! [ "$disks" = "" ]; then
echo 'echo ""' >> /mnt/setup-chroot.sh
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 "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 ''" >> /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 'echo ""' >> /mnt/setup-chroot.sh
echo 'echo "Enabling boot pool import service..."'>> /mnt/setup-chroot.sh
echo "errors=\$(systemctl enable zfs-import-bpool.service 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
echo 'if ! [ "$?" = "0" ]; then '>> /mnt/setup-chroot.sh
echo ' echo "Failed to enable boot pool import service - $errors"' >> /mnt/setup-chroot.sh
echo " exit 102">> /mnt/setup-chroot.sh
echo "fi">> /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 \"Checking ZFS root...\"" >> /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 '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!
echo 'echo ""' >> /mnt/setup-chroot.sh
echo 'echo "Modifying grub for ZFS root..."' >> /mnt/setup-chroot.sh
echo "errors=\$(sed -ir 's/GRUB_CMDLINE_LINUX=\".*\"/GRUB_CMDLINE_LINUX=\"root=ZFS=rpool\/ROOT\/ubuntu\"/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 'echo "Done."' >> /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 'echo ""' >> /mnt/setup-chroot.sh
echo 'echo "Installing grub UEFI on plex1..."' >> /mnt/setup-chroot.sh
echo "errors=\$(grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck --no-floppy 2>&1 1>/dev/null && umount /boot/efi 2>&1 1>/dev/null)" >> /mnt/setup-chroot.sh
echo "if ! [ \"\$?\" = \"0\" ]; then echo \"Failed to install grub UEFI on plex1 - \$errors\"; exit 104; fi" >> /mnt/setup-chroot.sh
echo "echo \"Done.\"" >> /mnt/setup-chroot.sh
# error check this as one big block
echo "zfs set mountpoint=legacy bpool/BOOT/ubuntu" >> /mnt/setup-chroot.sh
echo "echo \"bpool/BOOT/ubuntu /boot zfs nodev,relatime,x-systemd.requires=zfs-import-bpool.service 0 0\" >> /etc/fstab" >> /mnt/setup-chroot.sh
echo "zfs set mountpoint=legacy rpool/var/log">> /mnt/setup-chroot.sh
echo "echo \"rpool/var/log /var/log zfs nodev,relatime 0 0\" >> /etc/fstab" >> /mnt/setup-chroot.sh
echo "zfs set mountpoint=legacy rpool/var/spool">> /mnt/setup-chroot.sh
echo "echo \"rpool/var/spool /var/spool zfs nodev,relatime 0 0\" >> /etc/fstab" >> /mnt/setup-chroot.sh
echo "zfs set mountpoint=legacy rpool/var/tmp" >> /mnt/setup-chroot.sh
echo "echo \"rpool/var/tmp /var/tmp zfs nodev,relatime 0 0\" >> /etc/fstab" >> /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 ""' >> /mnt/setup-chroot.sh
echo 'echo "Enabling SSH..."'>> /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
echo 'if ! [ "$?" = "0" ]; then '>> /mnt/setup-chroot.sh
echo ' echo "Failed to enable SSH - $errors"' >> /mnt/setup-chroot.sh
echo " exit 101">> /mnt/setup-chroot.sh
echo "fi">> /mnt/setup-chroot.sh
echo 'echo "Done."'>> /mnt/setup-chroot.sh
echo 'echo ""'>> /mnt/setup-chroot.sh
echo 'echo "Creating admin user..."'>> /mnt/setup-chroot.sh
# error check this
echo "useradd $admin" >> /mnt/setup-chroot.sh
echo "cp -a /etc/skel/.[!.]* \"/home/$admin\"" >> /mnt/setup-chroot.sh
echo "chown -R ${admin}:${admin} \"/home/$admin\"" >> /mnt/setup-chroot.sh
echo "usermod -a -G adm,cdrom,dip,plugdev,sudo \"$admin\"" >> /mnt/setup-chroot.sh
echo "echo '${admin}:${rootpassword}' | chpasswd" >> /mnt/setup-chroot.sh
echo 'echo "Done."'>> /mnt/setup-chroot.sh
#create swap space, too if necessary
echo "exit 0" >> /mnt/setup-chroot.sh
errors=`chmod +x /mnt/setup-chroot.sh 2>&1 1>/dev/null`
if ! [ "$?" = "0" ]; then
echo "Failed to set execution permission on chroot script - $errors"
exit 45
fi
chroot /mnt /setup-chroot.sh
if ! [ "$?" = "0" ]; then
exit $?
fi
# commented out for debugging
echo ""
echo "Clearing chroot configuration script..."
rm /mnt/setup-chroot.sh
echo "Done."
echo ""
echo "Unmounting chroot mounts..."
mount | grep -v zfs | tac | awk '/\/mnt/ {print $3}' | xargs -i{} umount -lf {}
echo "Done."
echo ""
echo "Exporting zpools..."
errors=`zpool export -a 2>&1 1>/dev/null`
if ! [ "$?" = "0" ]; then
echo "Couldn't export mounted zpools - $errors"
exit 8
fi
echo "Done."
echo "Congratulations! The install was successful. Please reboot and set your boot device using UEFI in the BIOS."
exit 0
#sed -i -r "s/(^|[^#y])(compress)/\1#\2/" "$file"