Compare commits
178
Commits
master
..
49dba6f48a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49dba6f48a | ||
|
|
129f6b2970 | ||
|
|
6706bccb92 | ||
|
|
624cfea8a5 | ||
|
|
b08b102551 | ||
|
|
26d691a7b5 | ||
|
|
c228adfa5c | ||
|
|
f6d197b89e | ||
|
|
e7c202fafd | ||
|
|
2e5bba4fef | ||
|
|
ed60d2c4fa | ||
|
|
bf751b3e79 | ||
|
|
bf0f2a8945 | ||
|
|
22320ecd08 | ||
|
|
9ea1f3754b | ||
|
|
547ef2c399 | ||
|
|
64b786598e | ||
|
|
08120c6022 | ||
|
|
3f2810e0c0 | ||
|
|
614c4815d9 | ||
|
|
124dfa2609 | ||
|
|
40009a0e2f | ||
|
|
2e5f5e5be9 | ||
|
|
72a6416048 | ||
|
|
b9739f9fc8 | ||
|
|
5964f78755 | ||
|
|
521d71aabc | ||
|
|
88a5e6779f | ||
|
|
985cdf59fc | ||
|
|
e097ca1003 | ||
|
|
82fe1cea2b | ||
|
|
14aa5291fc | ||
|
|
14d9242f49 | ||
|
|
3b7417de3e | ||
|
|
274ce549af | ||
|
|
10ce137b51 | ||
|
|
49aa016158 | ||
|
|
dac9f123aa | ||
|
|
55afef2ada | ||
|
|
026fab7bfc | ||
|
|
341ff01a46 | ||
|
|
4126eb0d23 | ||
|
|
102f3507d9 | ||
|
|
837fb851c4 | ||
|
|
6d712ebf2d | ||
|
|
8fa6bfcc71 | ||
|
|
26d8e157a2 | ||
|
|
cca57584f9 | ||
|
|
1d26b2113d | ||
|
|
c9aed3491d | ||
|
|
0e2ad7847a | ||
|
|
1eb1a912d3 | ||
|
|
94de536f04 | ||
|
|
a9fdf8d65b | ||
|
|
3d8c48c2dd | ||
|
|
9beb27fce4 | ||
|
|
5b29ab32ca | ||
|
|
89943c4092 | ||
|
|
3362506cd6 | ||
|
|
da4d00c069 | ||
|
|
8d83e8741f | ||
|
|
c530d4c897 | ||
|
|
00cb3c9ac4 | ||
|
|
bcd3cd6192 | ||
|
|
13e896fdb8 | ||
|
|
12c9b1e6ef | ||
|
|
74c23a7cd4 | ||
|
|
9a27129139 | ||
|
|
fe1fa3ca71 | ||
|
|
9b83b389ab | ||
|
|
281eebf280 | ||
|
|
aaa83b5ed0 | ||
|
|
a679eacab8 | ||
|
|
81ed906d7f | ||
|
|
856a40b3f0 | ||
|
|
181806cdd3 | ||
|
|
c266522598 | ||
|
|
86773da268 | ||
|
|
66a138da7d | ||
|
|
a76bb31df6 | ||
|
|
79bb54a0ed | ||
|
|
f1c8182874 | ||
|
|
83b39edceb | ||
|
|
35874960e8 | ||
|
|
3ce1abf59a | ||
|
|
efee43b963 | ||
|
|
ed89525714 | ||
|
|
a5e5808f70 | ||
|
|
b072c25ba8 | ||
|
|
af77235f61 | ||
|
|
f99caea570 | ||
|
|
ae4a906da2 | ||
|
|
2e799692f5 | ||
|
|
8fe7616b38 | ||
|
|
2144e4fc1c | ||
|
|
c0137c0e73 | ||
|
|
4e5b347e84 | ||
|
|
1500c65c38 | ||
|
|
f0135901c9 | ||
|
|
e655a8de82 | ||
|
|
ecf1868cd1 | ||
|
|
c483ef23f2 | ||
|
|
2fca3e6dd4 | ||
|
|
0f14bed2d3 | ||
|
|
9981f01ceb | ||
|
|
1c607bd09a | ||
|
|
cadf53b85c | ||
|
|
7f1fbd3039 | ||
|
|
5c4982b1c7 | ||
|
|
197bbbe770 | ||
|
|
7b7853ecb8 | ||
|
|
c3c45019bc | ||
|
|
9289844c99 | ||
|
|
de7b8b3acd | ||
|
|
9ec289c136 | ||
|
|
6617d2f84d | ||
|
|
2ba9cb07da | ||
|
|
fac4a088ae | ||
|
|
0b33dd6be9 | ||
|
|
a3c89343ac | ||
|
|
def54b1a4f | ||
|
|
b75109612f | ||
|
|
9e4fc3b35c | ||
|
|
f212017cb4 | ||
|
|
71c1d92ed9 | ||
|
|
4d4d715fc1 | ||
|
|
ebd0d89da9 | ||
|
|
394b8999df | ||
|
|
0fc329a922 | ||
|
|
791c10684f | ||
|
|
a3de013ecb | ||
|
|
9ceac41631 | ||
|
|
63656fb07a | ||
|
|
19281f3ee6 | ||
|
|
2a91f9e118 | ||
|
|
1579bf11e8 | ||
|
|
a0bc8b8ed1 | ||
|
|
8f6ae4707d | ||
|
|
a896b8b888 | ||
|
|
7c12d73eec | ||
|
|
19d8d7ce33 | ||
|
|
c8f3c3d62b | ||
|
|
e26290c9e8 | ||
|
|
74a71e86c4 | ||
|
|
474075ff87 | ||
|
|
74054d9634 | ||
|
|
45b20879eb | ||
|
|
74985dfc81 | ||
|
|
dcd2fc35eb | ||
|
|
422e5f71fe | ||
|
|
d95da849f8 | ||
|
|
bf368d0d25 | ||
|
|
5e45529a0d | ||
|
|
c58ae06775 | ||
|
|
386b7a00e4 | ||
|
|
563a7328f4 | ||
|
|
c0ac3d7a12 | ||
|
|
17ebeaa3f7 | ||
|
|
6863e39c9c | ||
|
|
a55e02e1e0 | ||
|
|
27ea4b4411 | ||
|
|
059249eed2 | ||
|
|
c0b5434f44 | ||
|
|
edf841a06e | ||
|
|
dc0f7796b2 | ||
|
|
9438c07e25 | ||
|
|
f08d10d009 | ||
|
|
f369fb70a7 | ||
|
|
a02cf785e5 | ||
|
|
5e83fbf3d2 | ||
|
|
8ca216cae2 | ||
|
|
43bea157fe | ||
|
|
96fa360d27 | ||
|
|
9c3bc33373 | ||
|
|
0d60a61c39 | ||
|
|
5857371570 | ||
|
|
bc0d29539d | ||
|
|
d4d0debe30 |
@@ -1,8 +1,5 @@
|
|||||||
Server Setup Script
|
Server Setup Script
|
||||||
=====================
|
=====================
|
||||||
|
|
||||||
#Setup#
|
#Use#
|
||||||
wget -qO - https://code.totosearch.org/Sean/ServerSetup/raw/branch/master/setup.sh | sudo bash
|
wget -qO - https://code.totosearch.org/Sean/ServerSetup/raw/branch/master/setup.sh | sudo bash
|
||||||
|
|
||||||
#Maintenance#
|
|
||||||
wget -qO - https://code.totosearch.org/Sean/ServerSetup/raw/branch/master/maintenance.sh | sudo bash
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
#! /bin/bash
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Updating local packages..."
|
|
||||||
errors=`apt-add-repository universe >/dev/null 2>/dev/null && apt-get update 2>&1 >/dev/null && apt-get install -y zfs-initramfs`
|
|
||||||
if [ "$?" = "0" ]; then
|
|
||||||
echo "Done."
|
|
||||||
else
|
|
||||||
echo "Failed to add universal repository, update apt repository - $errors"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Importing boot pool and main OS pool..."
|
|
||||||
errors=$(zpool export -a 2>&1 1>/dev/null && zpool import -N -R /mnt rpool 2>&1 1>/dev/null && zpool import -N -R /mnt bpool 2>&1 1>/dev/null && zfs mount rpool/ROOT/ubuntu 2>&1 1>/dev/null)
|
|
||||||
# && zfs mount -a 2>&1 1>/dev/null
|
|
||||||
if [ "$?" = "0" ]; then
|
|
||||||
echo "Done."
|
|
||||||
else
|
|
||||||
echo "Failed to mount bpool or rpool - $errors"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Binding mounts..."
|
|
||||||
errors=`mount --rbind /dev /mnt/dev 2>&1 1>/dev/null && mount --rbind /proc /mnt/proc 2>&1 1>/dev/null && mount --rbind /sys /mnt/sys 2>&1 1>/dev/null`
|
|
||||||
if ! [ "$?" = "0" ]; then
|
|
||||||
echo "Failed to bind mounts - $errors"
|
|
||||||
exit 4
|
|
||||||
fi
|
|
||||||
echo "Done."
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Entering chroot, type \"exit\" to leave..."
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
echo "#!/bin/bash" > /mnt/maintenance.sh
|
|
||||||
chmod +x /mnt/maintenance.sh
|
|
||||||
echo "zfs mount -a && mount /boot" >> /mnt/maintenance.sh
|
|
||||||
echo "/bin/bash" >> /mnt/maintenance.sh
|
|
||||||
echo "umount /boot" >> /mnt/maintenance.sh
|
|
||||||
echo "zfs umount -a" >> /mnt/maintenance.sh
|
|
||||||
|
|
||||||
chroot /mnt /maintenance.sh --login < /dev/tty
|
|
||||||
|
|
||||||
rm /mnt/maintenance.sh
|
|
||||||
|
|
||||||
if ! [ "$?" = "0" ]; then
|
|
||||||
echo "Chroot failed with an error"
|
|
||||||
exit $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Unbinding mounts..."
|
|
||||||
errors=`mount | grep -v zfs | tac | awk '/\\/mnt/ {print \$3}' | xargs -i{} umount -lf \{\} 2>&1 1>/dev/null && zpool export -a 2>&1 1>/dev/null`
|
|
||||||
if ! [ "$?" = "0" ]; then
|
|
||||||
echo "Failed to unbind mounts - $errors"
|
|
||||||
exit 4
|
|
||||||
fi
|
|
||||||
echo "Done."
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Updating local packages..."
|
echo "Updating local packages..."
|
||||||
errors=`apt-add-repository universe >/dev/null 2>&1 1>/dev/null && apt update 2>&1 >/dev/null`
|
errors=`apt-add-repository universe >/dev/null 2>/dev/null && apt update 2>&1 >/dev/null`
|
||||||
if [ "$?" = "0" ]; then
|
if [ "$?" = "0" ]; then
|
||||||
echo "Done."
|
echo "Done."
|
||||||
else
|
else
|
||||||
@@ -25,8 +25,6 @@ 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`
|
||||||
@@ -58,12 +56,7 @@ 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 bridge - select none for no bridge:" $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 br0:" $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
|
||||||
@@ -113,44 +106,16 @@ for disk in `echo "$alldisks"`; do
|
|||||||
echo "Done."
|
echo "Done."
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$efi" = "1" ]; then
|
for disk in `echo "$boots"`; do
|
||||||
|
echo ""
|
||||||
for disk in `echo "$boots"`; do
|
echo "Creating boot partitions for device $disk..."
|
||||||
echo ""
|
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`
|
||||||
echo "Creating boot partitions for device $disk..."
|
if ! [ "$?" = "0" ]; then
|
||||||
errors=`sgdisk -n1:1M:+512M -t1:EF00 /dev/disk/by-id/$disk 2>&1 1>/dev/null`
|
echo "Failed to create boot partition for device $disk - $errors"
|
||||||
if ! [ "$?" = "0" ]; then
|
exit 3
|
||||||
echo "Failed to create boot partition for device $disk - $errors"
|
fi
|
||||||
exit 3
|
echo "Done."
|
||||||
fi
|
done
|
||||||
echo "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 ""
|
||||||
@@ -163,31 +128,18 @@ for disk in `echo "$disks"`; do
|
|||||||
echo "Done."
|
echo "Done."
|
||||||
done
|
done
|
||||||
|
|
||||||
# create boot mirror list and root list
|
# 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
|
||||||
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 pool partition to update on device ${disk}..."; pending="1"; fi
|
if [ "$pending" = "0" ]; then echo "" && echo "Waiting for ${disk} boot partition to update..."; 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
|
||||||
@@ -195,7 +147,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 $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 mirror$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
|
||||||
@@ -278,6 +230,29 @@ 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
|
||||||
@@ -293,6 +268,7 @@ 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`
|
||||||
@@ -340,7 +316,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
|
||||||
@@ -360,6 +336,7 @@ echo " exit 118">> /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
|
||||||
|
|
||||||
|
|
||||||
# configure docker storage to use zfs
|
# configure docker storage to use zfs
|
||||||
mkdir -p /mnt/etc/docker
|
mkdir -p /mnt/etc/docker
|
||||||
echo "{\"storage-driver\":\"zfs\"}" > /mnt/etc/docker/daemon.json
|
echo "{\"storage-driver\":\"zfs\"}" > /mnt/etc/docker/daemon.json
|
||||||
@@ -370,12 +347,19 @@ 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}-part1 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}-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 '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}-part1) /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
|
||||||
@@ -399,6 +383,15 @@ 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
|
||||||
@@ -407,7 +400,6 @@ 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
|
||||||
@@ -418,10 +410,11 @@ 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 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 "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 "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
|
||||||
@@ -438,19 +431,16 @@ 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 "Cloning EFI boot partition to all boot devices..."' >> /mnt/setup-chroot.sh
|
||||||
|
i="2"
|
||||||
|
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 "if ! [ \"\$?\" = \"0\" ]; then echo \"EFI copy failed - \$errors\"; exit 20; fi" >> /mnt/setup-chroot.sh
|
||||||
|
i=$((i + 1))
|
||||||
|
done
|
||||||
|
|
||||||
echo 'echo ""' >> /mnt/setup-chroot.sh
|
echo 'echo "Done."' >> /mnt/setup-chroot.sh
|
||||||
echo 'echo "Cloning EFI boot partition to all boot devices..."' >> /mnt/setup-chroot.sh
|
|
||||||
i="2"
|
|
||||||
for disk in `echo "$boots" | tail -n+2`; do
|
|
||||||
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
|
|
||||||
i=$((i + 1))
|
|
||||||
done
|
|
||||||
|
|
||||||
echo 'echo "Done."' >> /mnt/setup-chroot.sh
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# error check this as one big block
|
# error check this as one big block
|
||||||
@@ -465,12 +455,16 @@ 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
|
||||||
@@ -489,6 +483,14 @@ 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
|
||||||
@@ -498,6 +500,29 @@ 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
|
||||||
|
# --content-filename=\"${hostname}.ssh.key\" --content-name=\"${hostname}.ssh.key\"
|
||||||
|
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 "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"
|
||||||
@@ -536,30 +561,22 @@ 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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
chroot /mnt /setup-chroot.sh
|
chroot /mnt /setup-chroot.sh
|
||||||
if ! [ "$?" = "0" ]; then
|
if ! [ "$?" = "0" ]; then
|
||||||
exit $?
|
exit $?
|
||||||
@@ -575,43 +592,51 @@ 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/')
|
||||||
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 $bridgedevice" > /mnt/etc/network/interfaces.d/$bridgedevice
|
echo "auto lo br0" > /mnt/etc/network/interfaces.d/br0
|
||||||
echo "iface lo inet loopback" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
echo "iface lo inet loopback" >> /mnt/etc/network/interfaces.d/br0
|
||||||
niclist=""
|
niclist=""
|
||||||
for nic in `echo "$nics"`; do
|
for nic in `echo "$nics"`; do
|
||||||
echo "iface ${nic} inet manual" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
echo "iface ${nic} inet manual" >> /mnt/etc/network/interfaces.d/br0
|
||||||
niclist="$niclist $nic"
|
niclist="$niclist $nic"
|
||||||
done
|
done
|
||||||
if [ "$networktype" = "dhcp" ]; then
|
if [ "$networktype" = "dhcp" ]; then
|
||||||
echo "iface $bridgedevice inet dhcp" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
echo "iface br0 inet dhcp" >> /mnt/etc/network/interfaces.d/br0
|
||||||
else
|
else
|
||||||
echo "iface $bridgedevice inet static" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
echo "iface br0 inet static" >> /mnt/etc/network/interfaces.d/br0
|
||||||
echo " address $address" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
echo " address $address" >> /mnt/etc/network/interfaces.d/br0
|
||||||
echo " netmask $subnet" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
echo " netmask $subnet" >> /mnt/etc/network/interfaces.d/br0
|
||||||
echo " gateway $gateway" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
echo " gateway $gateway" >> /mnt/etc/network/interfaces.d/br0
|
||||||
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/$bridgedevice
|
echo " dns-nameservers 127.0.0.53" >> /mnt/etc/network/interfaces.d/br0
|
||||||
if [ "$bridgedevice" = "br0" ]; then
|
echo " bridge_waitport 0" >> /mnt/etc/network/interfaces.d/br0
|
||||||
echo " bridge_waitport 0" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
echo " bridge_fd 0" >> /mnt/etc/network/interfaces.d/br0
|
||||||
echo " bridge_fd 0" >> /mnt/etc/network/interfaces.d/$bridgedevice
|
echo " bridge_ports${niclist}" >> /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/br0
|
||||||
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."
|
||||||
|
|
||||||
|
|
||||||
|
#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 ""
|
||||||
echo "Opening SSH port on firewall..."
|
echo "Opening SSH port on firewall..."
|
||||||
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
|
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
|
||||||
echo "Done."
|
echo "Done."
|
||||||
# commented out for debugging
|
# commented out for debugging
|
||||||
echo ""
|
echo ""
|
||||||
@@ -619,6 +644,7 @@ 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
|
||||||
@@ -657,6 +683,8 @@ 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 {}
|
||||||
@@ -674,4 +702,6 @@ 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"
|
||||||
Reference in New Issue
Block a user