diff --git a/README.md b/NOTES.md similarity index 100% rename from README.md rename to NOTES.md diff --git a/custom/disable_swap.sh b/custom/disable_swap.sh new file mode 100755 index 0000000..e5d6608 --- /dev/null +++ b/custom/disable_swap.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +if [ "$(id -u)" -ne 0 ]; then + echo "This script should be run as root. Aborting..." > /dev/stderr + exit 1 +fi + +echo "Disabling swap..." +swapoff -a + +echo "Disabling swap permanently ('/etc/fstab.bak' created)..." +sed -i.bak '/ swap /d' /etc/fstab diff --git a/custom/generate_ssh_cluster.sh b/custom/generate_ssh_cluster.sh new file mode 100755 index 0000000..949dde1 --- /dev/null +++ b/custom/generate_ssh_cluster.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +if [ "$(id -u)" -ne 0 ]; then + echo "This script should be run as root. Aborting..." > /dev/stderr + exit 1 +fi + +echo "Creating SSH key..." +ssh-keygen -t rsa -b 4096 -q -N "" -f ~/.ssh/id_rsa + +echo "Adding SSH key to authorized..." +cat ~/.ssh/rsa.pub >> ~/.ssh/authorized_keys diff --git a/custom/install_base_packages.sh b/custom/install_base_packages.sh index c8c83cc..cc5923f 100755 --- a/custom/install_base_packages.sh +++ b/custom/install_base_packages.sh @@ -1,11 +1,23 @@ #!/bin/sh -if [ $(id -u) -ne 0 ]; then +if [ "$(id -u)" -ne 0 ]; then echo "This script should be run as root. Aborting..." > /dev/stderr exit 1 fi -apt-get update +echo "Updating apt package index..." +apt-get update > /dev/null -apt-get install software-properties-common python3-pip +apt -q -y upgrade +apt-get autoremove --purge + +echo "Installing base packages..." +apt-get -q -y -o Dpkg::Use-Pty=0 install \ + nano \ + htop \ + nload \ + nethogs + +echo "Cleaning apt cache..." +apt-get clean diff --git a/custom/install_docker-compose.sh b/custom/install_docker-compose.sh index f2b7a50..76ca246 100755 --- a/custom/install_docker-compose.sh +++ b/custom/install_docker-compose.sh @@ -2,7 +2,7 @@ set -eu -if [ $(id -u) -ne 0 ]; then +if [ "$(id -u)" -ne 0 ]; then echo "This script should be run as root. Aborting..." > /dev/stderr exit 1 fi diff --git a/custom/install_docker.sh b/custom/install_docker.sh index e40c4a3..322a8f6 100755 --- a/custom/install_docker.sh +++ b/custom/install_docker.sh @@ -2,7 +2,7 @@ set -eu -if [ $(id -u) -ne 0 ]; then +if [ "$(id -u)" -ne 0 ]; then echo "This script should be run as root. Aborting..." > /dev/stderr exit 1 fi @@ -11,7 +11,7 @@ SUPPORTED_ARCH="amd64 armhf arm64" ARCH=$(dpkg --print-architecture) echo "Checking system architecture..." -if echo $SUPPORTED_ARCH | grep -w $ARCH > /dev/null; then +if echo "${SUPPORTED_ARCH}" | grep -w "${ARCH}" > /dev/null; then echo "Architecture ${ARCH} supported." else echo "Architecture ${ARCH} not supported! Aborting..." diff --git a/custom/install_kubectl.sh b/custom/install_kubectl.sh new file mode 100755 index 0000000..f7aef5a --- /dev/null +++ b/custom/install_kubectl.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +if [ "$(id -u)" -ne 0 ]; then + echo "This script should be run as root. Aborting..." > /dev/stderr + exit 1 +fi + +# +# Following this guide: https://kubernetes.io/docs/tasks/tools/install-kubectl/ +# + +echo "Updating apt package index..." +apt-get update > /dev/null + +echo "Installing prerequisites..." +apt-get -q -y -o Dpkg::Use-Pty=0 install apt-transport-https gnupg2 curl + +echo "Adding Kubernetes' repo key..." +curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - + +echo "Adding Kubernetes repo..." +echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | tee -a /etc/apt/sources.list.d/kubernetes.list + +echo "Updating apt package index again..." +apt-get update > /dev/null +echo "Installing 'kubectl'..." +apt-get -q -y -o Dpkg::Use-Pty=0 install kubectl + +# TODO: the command `kubectl cluster-info` gives an error and the script +# provided from the docs gives an error. In the docs they are make +# some sort of assumption that I cannot still figure out. +# Ffs this is an entry level doc and they already start to omit not +# obvious stuff... sorry for not owning a magic crystal ball. >:( + +# THIS, is a quality doc: +# https://www.valent-blog.eu/2019/01/01/installare-kubernetes-in-debian-9/ +# The lines below comes from this doc. + +echo "Installing 'kubelet' and 'kubeadm'..." +apt-get -q -y -o Dpkg::Use-Pty=0 install kubelet kubeadm + +echo "Marking in hold the packages 'kubectl', 'kubelet' and 'kubeadm' in order to prevent them to update in the future..." +apt-mark hold kubelet kubeadm kubectl + +echo "Reloading systemd and restarting 'kubelet' service" +systemctl daemon-reload +systemctl restart kubelet + +# I guess these are the base images of kubernetes (?) +echo "Pulling some base images.." +kubeadm config images pull + +echo "Initializing kuvernetes.." +kubeadm init + +echo "Adding kubernetes config to this user home folder (useful for non-root users)..." +mkdir -p "$HOME/.kube" +cp -i /etc/kubernetes/admin.conf "$HOME/.kube/config" +chown "$(id -u)":"$(id -g)" "$HOME/.kube/config" diff --git a/custom/install_rancher.sh b/custom/install_rancher.sh new file mode 100755 index 0000000..2dc6cec --- /dev/null +++ b/custom/install_rancher.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# Sources: +# https://www.rancher.cn/an-introduction-to-rke +# https://devopsheaven.com/kubernetes/k8s/rke/devops/deploy/2019/10/21/install-kubernetes-locally-rke.html + +if [ "$(id -u)" -ne 0 ]; then + echo "This script should be run as root. Aborting..." > /dev/stderr + exit 1 +fi + +echo "Downloading and installing 'rke' executable..." +wget -O rke https://github.com/rancher/rke/releases/download/v1.2.3/rke_linux-amd64 && \ +chmod +x rke && \ +mv rke /usr/local/bin && \ +rke --version + +echo "Giving access to the docker socket at the SSH user..." +usermod -aG docker "$(id -un)" diff --git a/custom/main.sh b/custom/main.sh index c5bb1b6..49d2457 100755 --- a/custom/main.sh +++ b/custom/main.sh @@ -1,6 +1,6 @@ #!/bin/sh -if [ $(id -u) -ne 0 ]; then +if [ "$(id -u)" -ne 0 ]; then echo "This script should be run as root. Aborting..." > /dev/stderr exit 1 fi @@ -10,5 +10,9 @@ SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" eval "${SCRIPTPATH}/install_packages.sh" eval "${SCRIPTPATH}/install_docker.sh" eval "${SCRIPTPATH}/install_docker-compose.sh" +eval "${SCRIPTPATH}/disable_swap.sh" +eval "${SCRIPTPATH}/install_kubectl.sh" +eval "${SCRIPTPATH}/install_rancher.sh" +eval "${SCRIPTPATH}/generate_ssh_cluster.sh" apt-get clean diff --git a/preseed/kube.cfg b/preseed/kube.cfg new file mode 100644 index 0000000..e2d0677 --- /dev/null +++ b/preseed/kube.cfg @@ -0,0 +1,100 @@ +#_preseed_V1 +#### Contents of the preconfiguration file (for buster) +### Localization +d-i debian-installer/language string it +d-i debian-installer/country string IT +d-i debian-installer/locale string it_IT.UTF-8 + +# Keyboard selection. +# Usare Ctrl+Alt+Backspace per terminare il server X? +d-i keyboard-configuration/ctrl_alt_bksp boolean true + +d-i keyboard-configuration/modelcode string pc105 +d-i keyboard-configuration/toggle select No toggling +d-i keyboard-configuration/altgr select The default for the keyboard layout +d-i keyboard-configuration/layoutcode string it +d-i keyboard-configuration/variant select Italiana +d-i keyboard-configuration/compose select No compose key +d-i keyboard-configuration/switch select No temporary switch +d-i console-setup/variantcode string qwerty +d-i keyboard-configuration/model select Generic 105-key PC (intl.) +d-i keyboard-configuration/xkb-keymap select it + +d-i keyboard-configuration/unsupported_config_options boolean true +d-i keyboard-configuration/unsupported_config_layout boolean true +d-i keyboard-configuration/unsupported_layout boolean true +d-i keyboard-configuration/unsupported_options boolean true + +### Network configuration +d-i netcfg/choose_interface select auto +d-i netcfg/get_hostname string debian-test +d-i netcfg/get_domain string dominio-test +d-i netcfg/wireless_wep string +d-i hw-detect/load_firmware boolean true + +### Mirror settings +d-i mirror/country string manual +d-i mirror/http/hostname string debian.mirror.garr.it +d-i mirror/http/directory string /debian +d-i mirror/http/proxy string + +### Account setup +# Skip creation of a root account (normal user account will be able to +# use sudo). +d-i passwd/root-login boolean false +d-i passwd/user-fullname string Virtualuser +d-i passwd/username string virtualuser +d-i passwd/user-password-crypted password $6$SmihMODnNymjr40/$YAkRABY.qE8tOjXmg0Z6X5e.mdLOUsUseNaPwaLyCjK17LzV/NLE3IfcmkQgwGjBeeQ7peGEfurqe.SBY7JHU1 + +### Clock and time zone setup +d-i clock-setup/utc boolean true +d-i time/zone string Europe/Rome +d-i clock-setup/ntp boolean true + +### Partitioning +d-i partman-auto/disk string /dev/sda +d-i partman-auto/method string regular +d-i partman-lvm/device_remove_lvm boolean true +d-i partman-md/device_remove_md boolean true +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm_nooverwrite boolean true +d-i partman-auto/expert_recipe string \ + root :: \ + 4096 100 -1 ext4 \ + $primary{ } $bootable{ } \ + method{ format } format{ } \ + use_filesystem{ } filesystem{ ext4 } \ + mountpoint{ / } \ + . +d-i partman-partitioning/confirm_write_new_label boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true +d-i partman/mount_style select uuid +d-i partman-basicfilesystems/no_swap boolean false + +### Apt setup +d-i apt-setup/non-free boolean true +d-i apt-setup/contrib boolean true + +### Package selection +tasksel tasksel/first multiselect none + +# Individual additional packages to install +# Note: "console-setup" and "keyboard-configuration" are foundamental for +# keyboard configuration +d-i pkgsel/include string nano wget openssh-server console-setup keyboard-configuration + +popularity-contest popularity-contest/participate boolean false + +### Boot loader installation +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean true +d-i grub-installer/bootdev string /dev/sda + +### Finishing up the installation +d-i finish-install/reboot_in_progress note +d-i debian-installer/exit/poweroff boolean true + +#### Advanced options +d-i preseed/late_command string modprobe usb-storage isofs; mkdir -p /cdrom; mount /dev/cdrom /cdrom; cp -r /cdrom/custom /target/srv/custom diff --git a/preseed/preseed.cfg b/preseed/preseed.cfg index b8dd5cf..326b273 100644 --- a/preseed/preseed.cfg +++ b/preseed/preseed.cfg @@ -146,8 +146,8 @@ d-i passwd/root-login boolean false #d-i passwd/root-password-crypted password [crypt(3) hash] # To create a normal user account. -d-i passwd/user-fullname string Meli -d-i passwd/username string meli +d-i passwd/user-fullname string Virtualuser +d-i passwd/username string virtualuser # Normal user's password, either in clear text #d-i passwd/user-password password insecure #d-i passwd/user-password-again password insecure