2018-09-02 13:01:37 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
pre_reboot_script () {
|
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
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)
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
if [ "$pass_var" == "$pass_var2" ]; then
|
|
|
|
echo "Passwords match!"
|
|
|
|
else
|
|
|
|
echo "Passwords not match!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-12-29 22:52:48 +01:00
|
|
|
|
2019-08-10 17:18:10 +02:00
|
|
|
echo "Install net-tools"
|
|
|
|
apt install net-tools -y
|
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Exec ifconfig"
|
|
|
|
ifconfig
|
|
|
|
read -p "Enter interface for configure bridge:" NET_IF
|
2018-12-29 22:52:48 +01:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Starting lsblk"
|
|
|
|
lsblk
|
|
|
|
read -p "Enter partition to encrypt:" PARTITION
|
2018-11-11 20:43:32 +01:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Installing requirements"
|
|
|
|
apt install cryptsetup ecryptfs-utils zfsutils-linux -y
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Setting timezone to Prague"
|
|
|
|
timedatectl set-timezone Europe/Prague
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Disabling zpool auto-scrub"
|
|
|
|
sed -i 's/^/#/' /etc/cron.d/zfsutils-linux
|
2018-12-29 22:52:48 +01:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Starting ecryptfs-setup-swap"
|
|
|
|
ecryptfs-setup-swap -f
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Starting luksFormat"
|
|
|
|
echo -n "$pass_var" | cryptsetup luksFormat $PARTITION -
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Opening crypted partition"
|
|
|
|
echo "$pass_var" | cryptsetup open $PARTITION crypt -c -
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Creating zpool"
|
|
|
|
zpool create crypt /dev/mapper/crypt -o ashift=12
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Enabling compression on zpool"
|
|
|
|
zfs set compression=on crypt
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Creating datasets crypt/lxd/dir crypt/lxd/storage"
|
|
|
|
zfs create crypt/lxd
|
|
|
|
zfs create crypt/lxd/dir
|
|
|
|
zfs create crypt/lxd/storage
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2019-08-08 23:28:44 +02:00
|
|
|
echo "Disabling lxd snap"
|
|
|
|
snap disable lxd
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2019-04-17 15:14:29 +02:00
|
|
|
echo "Deleting everything in /var/snap/lxd/common/lxd/*"
|
|
|
|
rm /var/snap/lxd/common/lxd/* -r
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2019-04-17 15:14:29 +02:00
|
|
|
echo "Creating mountpoint /var/snap/lxd/common/lxd to crypt/lxd/dir"
|
|
|
|
zfs set mountpoint=/var/snap/lxd/common/lxd crypt/lxd/dir
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Configuring sysctl"
|
|
|
|
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.dirty_background_ratio = 5" >> /etc/sysctl.d/50-usl-mm.conf
|
2019-07-09 21:10:29 +02:00
|
|
|
echo "fs.inotify.max_queued_events = 1048576" >> /etc/sysctl.d/50-usl-mm.conf
|
|
|
|
echo "fs.inotify.max_user_instances = 1048576" >> /etc/sysctl.d/50-usl-mm.conf
|
|
|
|
echo "fs.inotify.max_user_watches = 1048576" >> /etc/sysctl.d/50-usl-mm.conf
|
|
|
|
echo "kernel.dmesg_restrict = 1" >> /etc/sysctl.d/50-usl-mm.conf
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2019-07-18 15:52:53 +02:00
|
|
|
echo "Configuring arc cache for zfs to min 256MB and max 1536MB + txg_timeout to 3"
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "options zfs zfs_arc_min=268435456" > /etc/modprobe.d/zfs.conf
|
|
|
|
echo "options zfs zfs_arc_max=1610612736" >> /etc/modprobe.d/zfs.conf
|
2019-07-18 15:52:53 +02:00
|
|
|
echo "options zfs zfs_txg_timeout=3" >> /etc/modprobe.d/zfs.conf
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Doing update-initramfs -u"
|
|
|
|
update-initramfs -u
|
2018-12-04 10:00:19 +01:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Configuring network to use bridge"
|
2018-09-02 13:01:37 +02:00
|
|
|
echo "auto lo" > /etc/network/interfaces
|
|
|
|
echo "iface lo inet loopback" >> /etc/network/interfaces
|
|
|
|
echo " " >> /etc/network/interfaces
|
|
|
|
echo "iface $NET_IF inet manual" >> /etc/network/interfaces
|
|
|
|
echo "iface $NET_IF inet6 manual" >> /etc/network/interfaces
|
|
|
|
echo "auto br0" >> /etc/network/interfaces
|
|
|
|
echo "iface br0 inet dhcp" >> /etc/network/interfaces
|
|
|
|
echo " bridge_ports $NET_IF" >> /etc/network/interfaces
|
|
|
|
echo " bridge_stp off" >> /etc/network/interfaces
|
|
|
|
echo " bridge_fd 0" >> /etc/network/interfaces
|
|
|
|
echo " " >> /etc/network/interfaces
|
|
|
|
echo "iface br0 inet6 auto" >> /etc/network/interfaces
|
|
|
|
echo " bridge_ports $NET_IF" >> /etc/network/interfaces
|
|
|
|
echo " bridge_stp off" >> /etc/network/interfaces
|
|
|
|
echo " bridge_fd 0" >> /etc/network/interfaces
|
|
|
|
|
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Purging netplan,disabling dhcpcd and install ifupdown"
|
|
|
|
apt purge nplan -y
|
2019-02-19 12:20:15 +01:00
|
|
|
rm /etc/netplan/* -f
|
2018-12-29 23:03:05 +01:00
|
|
|
apt install bridge-utils ifupdown -y
|
|
|
|
|
|
|
|
echo "Doing apt update and apt dist-upgrade"
|
|
|
|
apt update
|
|
|
|
apt dist-upgrade -y
|
|
|
|
|
|
|
|
echo "Creating onstart script in /root"
|
|
|
|
echo "#!/bin/bash" > /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_var2=\$(dialog --passwordbox \"Enter password again:\" 25 25 --output-fd 1)" >> /root/onstart
|
|
|
|
echo "if [ \"\$pass_var\" == \"\$pass_var2\" ]; then" >> /root/onstart
|
|
|
|
echo "echo \"Passwords match!\"" >> /root/onstart
|
|
|
|
echo "else" >> /root/onstart
|
|
|
|
echo "echo \"Passwords not match!\"" >> /root/onstart
|
|
|
|
echo "exit 1" >> /root/onstart
|
|
|
|
echo "fi" >> /root/onstart
|
2019-04-17 15:14:29 +02:00
|
|
|
echo "echo \"Stopping LXD snap daemon and deleting /var/snap/lxd/common/lxd/*\"" >> /root/onstart
|
2019-08-08 23:28:44 +02:00
|
|
|
echo "snap disable lxd" >> /root/onstart
|
2019-04-17 15:14:29 +02:00
|
|
|
echo "rm /var/snap/lxd/common/lxd/* -rf" >> /root/onstart
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "echo \"Opening encrypted partition\"" >> /root/onstart
|
|
|
|
echo "echo \$pass_var | cryptsetup open $PARTITION crypt -c -" >> /root/onstart
|
|
|
|
echo "partprobe" >> /root/onstart
|
|
|
|
echo "zpool import -d /dev/mapper crypt -f -m" >> /root/onstart
|
2019-08-08 23:28:44 +02:00
|
|
|
echo "snap enable lxd" >> /root/onstart
|
2018-12-29 23:03:05 +01:00
|
|
|
|
|
|
|
chmod +x /root/onstart
|
|
|
|
read -p "Press any key for reboot"
|
|
|
|
reboot
|
2018-09-02 13:01:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
post_reboot_script () {
|
2019-04-17 15:14:29 +02:00
|
|
|
echo "Stopping lxd and delete /var/snap/lxd/common/lxd/*"
|
2019-08-08 16:17:27 +02:00
|
|
|
snap stop lxd.daemon
|
|
|
|
snap stop --disable lxd.daemon
|
2019-04-17 15:14:29 +02:00
|
|
|
rm /var/snap/lxd/common/lxd/* -r
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Executing /root/onstart"
|
|
|
|
bash /root/onstart
|
2018-09-02 13:01:37 +02:00
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Configuring LXD"
|
2018-09-02 13:01:37 +02:00
|
|
|
lxd waitready
|
|
|
|
cat <<EOF | lxd init
|
|
|
|
no
|
|
|
|
yes
|
|
|
|
storage
|
|
|
|
zfs
|
|
|
|
no
|
|
|
|
crypt/lxd/storage
|
|
|
|
no
|
|
|
|
yes
|
|
|
|
lxdbr0
|
|
|
|
10.10.10.1/24
|
|
|
|
yes
|
|
|
|
none
|
|
|
|
no
|
|
|
|
no
|
|
|
|
no
|
|
|
|
EOF
|
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
echo "Set screen settings"
|
|
|
|
echo "startup_message off" >> /root/.screenrc
|
|
|
|
echo "screen -t htop htop" >> /root/.screenrc
|
|
|
|
echo "screen -t mc mc" >> /root/.screenrc
|
|
|
|
echo "screen -t bash bash" >> /root/.screenrc
|
|
|
|
echo "altscreen on" >> /root/.screenrc
|
|
|
|
echo "term screen-256color" >> /root/.screenrc
|
|
|
|
echo "bind 'b' prev" >> /root/.screenrc
|
|
|
|
echo "bind 'n' next" >> /root/.screenrc
|
|
|
|
echo "hardstatus alwayslastline" >> /root/.screenrc
|
|
|
|
echo "autodetach on" >> /root/.screenrc
|
|
|
|
echo "mousetrack on" >> /root/.screenrc
|
|
|
|
echo "vbell off" >> /root/.screenrc
|
|
|
|
echo "termcapinfo xterm* ti@:te@" >> /root/.screenrc
|
|
|
|
echo "defscrollback 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 "Install utilities"
|
|
|
|
apt install -y mc htop screen zfsnap smartmontools
|
|
|
|
|
2019-05-03 14:44:58 +02:00
|
|
|
echo "Set max processes to 1500 in default profile in LXD"
|
|
|
|
lxc profile set default limits.processes 1500
|
|
|
|
|
2018-12-29 23:03:05 +01:00
|
|
|
read -p "Done, press any key to return to main menu"
|
|
|
|
main_menu
|
2018-09-02 13:01:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
install_uptrack () {
|
2019-07-07 23:17:09 +02:00
|
|
|
cd /tmp
|
|
|
|
wget https://ksplice.oracle.com/uptrack/dist/disco/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
|
|
|
|
dpkg -i ksplice-uptrack.deb
|
|
|
|
read -p "Done, press any key to return to main menu"
|
2019-04-25 20:51:24 +02:00
|
|
|
echo "NOT WORKING"
|
2018-12-29 23:03:05 +01:00
|
|
|
main_menu
|
2018-09-02 13:01:37 +02:00
|
|
|
}
|
2018-12-29 23:03:05 +01:00
|
|
|
|
2018-09-02 13:01:37 +02:00
|
|
|
main_menu () {
|
|
|
|
cmd=(dialog --nocancel --menu "Welcome in setup-lxd-mm!" 22 76 16)
|
|
|
|
options=(
|
|
|
|
1 "Pre-reboot script"
|
|
|
|
2 "Post-reboot script"
|
2019-07-18 15:48:56 +02:00
|
|
|
3 "Install uptrack-upgrade"
|
2018-09-02 13:01:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
|
|
|
|
|
|
|
|
for choice in $choices
|
|
|
|
do
|
|
|
|
case $choice in
|
|
|
|
|
|
|
|
1)
|
|
|
|
pre_reboot_script
|
|
|
|
;;
|
|
|
|
|
|
|
|
2)
|
|
|
|
post_reboot_script
|
|
|
|
;;
|
|
|
|
|
|
|
|
3)
|
|
|
|
install_uptrack
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
clear
|
|
|
|
}
|
|
|
|
|
|
|
|
main_menu
|