Update 2018-2

This commit is contained in:
Milan Meduna 2018-12-29 22:03:05 +00:00
parent 96635f6bab
commit d8a11929e0
1 changed files with 112 additions and 111 deletions

View File

@ -2,77 +2,77 @@
pre_reboot_script () { pre_reboot_script () {
pass_var=$(dialog --passwordbox "Enter password to crypted partition for containers:" 25 25 --output-fd 1) pass_var=$(dialog --passwordbox "Enter password to crypted partition for containers:" 25 25 --output-fd 1)
pass_var2=$(dialog --passwordbox "Enter password to crypted partition for containers again:" 25 25 --output-fd 1) pass_var2=$(dialog --passwordbox "Enter password to crypted partition for containers again:" 25 25 --output-fd 1)
if [ "$pass_var" == "$pass_var2" ]; then if [ "$pass_var" == "$pass_var2" ]; then
echo "Passwords match!" echo "Passwords match!"
else else
echo "Passwords not match!" echo "Passwords not match!"
exit 1 exit 1
fi fi
echo "Exec ifconfig" echo "Exec ifconfig"
ifconfig ifconfig
read -p "Enter interface for configure bridge:" NET_IF read -p "Enter interface for configure bridge:" NET_IF
echo "Starting lsblk" echo "Starting lsblk"
lsblk lsblk
read -p "Enter partition to encrypt:" PARTITION read -p "Enter partition to encrypt:" PARTITION
echo "Installing requirements" echo "Installing requirements"
apt install cryptsetup ecryptfs-utils zfsutils-linux -y apt install cryptsetup ecryptfs-utils zfsutils-linux -y
echo "Setting timezone to Prague" echo "Setting timezone to Prague"
timedatectl set-timezone Europe/Prague timedatectl set-timezone Europe/Prague
echo "Disabling zpool auto-scrub" echo "Disabling zpool auto-scrub"
sed -i 's/^/#/' /etc/cron.d/zfsutils-linux sed -i 's/^/#/' /etc/cron.d/zfsutils-linux
echo "Starting ecryptfs-setup-swap" echo "Starting ecryptfs-setup-swap"
ecryptfs-setup-swap -f ecryptfs-setup-swap -f
echo "Starting luksFormat" echo "Starting luksFormat"
echo -n "$pass_var" | cryptsetup luksFormat $PARTITION - echo -n "$pass_var" | cryptsetup luksFormat $PARTITION -
echo "Opening crypted partition" echo "Opening crypted partition"
echo "$pass_var" | cryptsetup open $PARTITION crypt -c - echo "$pass_var" | cryptsetup open $PARTITION crypt -c -
echo "Creating zpool" echo "Creating zpool"
zpool create crypt /dev/mapper/crypt -o ashift=12 zpool create crypt /dev/mapper/crypt -o ashift=12
echo "Enabling compression on zpool" echo "Enabling compression on zpool"
zfs set compression=on crypt zfs set compression=on crypt
echo "Creating datasets crypt/lxd/dir crypt/lxd/storage" echo "Creating datasets crypt/lxd/dir crypt/lxd/storage"
zfs create crypt/lxd zfs create crypt/lxd
zfs create crypt/lxd/dir zfs create crypt/lxd/dir
zfs create crypt/lxd/storage zfs create crypt/lxd/storage
echo "Stopping and disabling lxd" echo "Stopping and disabling lxd"
systemctl disable lxd systemctl disable lxd
systemctl disable lxd.socket systemctl disable lxd.socket
systemctl stop lxd systemctl stop lxd
echo "Deleting everything in /var/lib/lxd/*" echo "Deleting everything in /var/lib/lxd/*"
rm /var/lib/lxd/* -r rm /var/lib/lxd/* -r
echo "Creating mountpoint /var/lib/lxd to crypt/lxd/dir" echo "Creating mountpoint /var/lib/lxd to crypt/lxd/dir"
zfs set mountpoint=/var/lib/lxd crypt/lxd/dir zfs set mountpoint=/var/lib/lxd crypt/lxd/dir
echo "Configuring sysctl" echo "Configuring sysctl"
echo "vm.swappiness = 1" > /etc/sysctl.d/50-usl-mm.conf echo "vm.swappiness = 1" > /etc/sysctl.d/50-usl-mm.conf
echo "vm.min_free_kbytes = 131072" >> /etc/sysctl.d/50-usl-mm.conf echo "vm.min_free_kbytes = 131072" >> /etc/sysctl.d/50-usl-mm.conf
echo "vm.dirty_background_ratio = 5" >> /etc/sysctl.d/50-usl-mm.conf echo "vm.dirty_background_ratio = 5" >> /etc/sysctl.d/50-usl-mm.conf
echo "Configuring arc cache for zfs to min 256MB and max 1536MB" echo "Configuring arc cache for zfs to min 256MB and max 1536MB"
echo "options zfs zfs_arc_min=268435456" > /etc/modprobe.d/zfs.conf echo "options zfs zfs_arc_min=268435456" > /etc/modprobe.d/zfs.conf
echo "options zfs zfs_arc_max=1610612736" >> /etc/modprobe.d/zfs.conf echo "options zfs zfs_arc_max=1610612736" >> /etc/modprobe.d/zfs.conf
echo "Doing update-initramfs -u" echo "Doing update-initramfs -u"
update-initramfs -u update-initramfs -u
echo "Configuring network to use bridge" echo "Configuring network to use bridge"
echo "auto lo" > /etc/network/interfaces echo "auto lo" > /etc/network/interfaces
echo "iface lo inet loopback" >> /etc/network/interfaces echo "iface lo inet loopback" >> /etc/network/interfaces
echo " " >> /etc/network/interfaces echo " " >> /etc/network/interfaces
@ -90,46 +90,46 @@ echo " bridge_stp off" >> /etc/network/interfaces
echo " bridge_fd 0" >> /etc/network/interfaces echo " bridge_fd 0" >> /etc/network/interfaces
echo "Purging netplan,disabling dhcpcd and install ifupdown" echo "Purging netplan,disabling dhcpcd and install ifupdown"
apt purge nplan -y apt purge nplan -y
rm /etc/netplan/50-cloud-init.yaml rm /etc/netplan/50-cloud-init.yaml
apt install bridge-utils ifupdown -y apt install bridge-utils ifupdown -y
echo "Doing apt update and apt dist-upgrade" echo "Doing apt update and apt dist-upgrade"
apt update apt update
apt dist-upgrade -y apt dist-upgrade -y
echo "Creating onstart script in /root" echo "Creating onstart script in /root"
echo "#!/bin/bash" > /root/onstart echo "#!/bin/bash" > /root/onstart
echo "read -p \"Press any button to start...\"" >> /root/onstart echo "read -p \"Press any button to start...\"" >> /root/onstart
echo "pass_var=\$(dialog --passwordbox \"Enter password:\" 25 25 --output-fd 1)" >> /root/onstart echo "pass_var=\$(dialog --passwordbox \"Enter password:\" 25 25 --output-fd 1)" >> /root/onstart
echo "pass_var2=\$(dialog --passwordbox \"Enter password again:\" 25 25 --output-fd 1)" >> /root/onstart echo "pass_var2=\$(dialog --passwordbox \"Enter password again:\" 25 25 --output-fd 1)" >> /root/onstart
echo "if [ \"\$pass_var\" == \"\$pass_var2\" ]; then" >> /root/onstart echo "if [ \"\$pass_var\" == \"\$pass_var2\" ]; then" >> /root/onstart
echo "echo \"Passwords match!\"" >> /root/onstart echo "echo \"Passwords match!\"" >> /root/onstart
echo "else" >> /root/onstart echo "else" >> /root/onstart
echo "echo \"Passwords not match!\"" >> /root/onstart echo "echo \"Passwords not match!\"" >> /root/onstart
echo "exit 1" >> /root/onstart echo "exit 1" >> /root/onstart
echo "fi" >> /root/onstart echo "fi" >> /root/onstart
echo "echo \"Opening encrypted partition\"" >> /root/onstart echo "echo \"Opening encrypted partition\"" >> /root/onstart
echo "echo \$pass_var | cryptsetup open $PARTITION crypt -c -" >> /root/onstart echo "echo \$pass_var | cryptsetup open $PARTITION crypt -c -" >> /root/onstart
echo "partprobe" >> /root/onstart echo "partprobe" >> /root/onstart
echo "zpool import -d /dev/mapper crypt -f -m" >> /root/onstart echo "zpool import -d /dev/mapper crypt -f -m" >> /root/onstart
echo "systemctl start lxd" >> /root/onstart echo "systemctl start lxd" >> /root/onstart
chmod +x /root/onstart chmod +x /root/onstart
read -p "Press any key for reboot" read -p "Press any key for reboot"
reboot reboot
} }
post_reboot_script () { post_reboot_script () {
echo "Stopping lxd and delete /var/lib/lxd/*" echo "Stopping lxd and delete /var/lib/lxd/*"
systemctl stop lxd systemctl stop lxd
rm /var/lib/lxd/* -r rm /var/lib/lxd/* -r
echo "Executing /root/onstart" echo "Executing /root/onstart"
bash /root/onstart bash /root/onstart
echo "Configuring LXD" echo "Configuring LXD"
lxd waitready lxd waitready
cat <<EOF | lxd init cat <<EOF | lxd init
no no
@ -149,39 +149,40 @@ no
no no
EOF EOF
echo "Set screen settings" echo "Set screen settings"
echo "startup_message off" >> /root/.screenrc echo "startup_message off" >> /root/.screenrc
echo "screen -t htop htop" >> /root/.screenrc echo "screen -t htop htop" >> /root/.screenrc
echo "screen -t mc mc" >> /root/.screenrc echo "screen -t mc mc" >> /root/.screenrc
echo "screen -t bash bash" >> /root/.screenrc echo "screen -t bash bash" >> /root/.screenrc
echo "altscreen on" >> /root/.screenrc echo "altscreen on" >> /root/.screenrc
echo "term screen-256color" >> /root/.screenrc echo "term screen-256color" >> /root/.screenrc
echo "bind 'b' prev" >> /root/.screenrc echo "bind 'b' prev" >> /root/.screenrc
echo "bind 'n' next" >> /root/.screenrc echo "bind 'n' next" >> /root/.screenrc
echo "hardstatus alwayslastline" >> /root/.screenrc echo "hardstatus alwayslastline" >> /root/.screenrc
echo "autodetach on" >> /root/.screenrc echo "autodetach on" >> /root/.screenrc
echo "mousetrack on" >> /root/.screenrc echo "mousetrack on" >> /root/.screenrc
echo "vbell off" >> /root/.screenrc echo "vbell off" >> /root/.screenrc
echo "termcapinfo xterm* ti@:te@" >> /root/.screenrc echo "termcapinfo xterm* ti@:te@" >> /root/.screenrc
echo "defscrollback 5000" >> /root/.screenrc echo "defscrollback 5000" >> /root/.screenrc
echo "scrollback 5000" >> /root/.screenrc echo "scrollback 5000" >> /root/.screenrc
echo "hardstatus string \"%{=b kw} %?%-Lw%?%{=br kw}[%n %t]%{=b kw}%?%+Lw%? %= %c\"" >> /root/.screenrc echo "hardstatus string \"%{=b kw} %?%-Lw%?%{=br kw}[%n %t]%{=b kw}%?%+Lw%? %= %c\"" >> /root/.screenrc
echo "Install utilities" echo "Install utilities"
apt install -y mc htop screen zfsnap smartmontools apt install -y mc htop screen zfsnap smartmontools
read -p "Done, press any key to return to main menu" read -p "Done, press any key to return to main menu"
main_menu main_menu
} }
install_uptrack () { install_uptrack () {
cd /tmp cd /tmp
wget https://ksplice.oracle.com/uptrack/dist/bionic/ksplice-uptrack.deb wget https://ksplice.oracle.com/uptrack/dist/bionic/ksplice-uptrack.deb
apt install libgtk2-perl dbus-x11 libglade2-0 libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python python-cairo python-dbus python-gi python-glade2 python-gobject-2 python-gtk2 python-minimal python-pycurl python-yaml python2.7 python2.7-minimal -y apt install libgtk2-perl dbus-x11 libglade2-0 libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python python-cairo python-dbus python-gi python-glade2 python-gobject-2 python-gtk2 python-minimal python-pycurl python-yaml python2.7 python2.7-minimal -y
dpkg -i ksplice-uptrack.deb dpkg -i ksplice-uptrack.deb
read -p "Done, press any key to return to main menu" read -p "Done, press any key to return to main menu"
main_menu main_menu
} }
main_menu () { main_menu () {
cmd=(dialog --nocancel --menu "Welcome in setup-lxd-mm!" 22 76 16) cmd=(dialog --nocancel --menu "Welcome in setup-lxd-mm!" 22 76 16)
options=( options=(