#!/usr/bin/env bash # Brett Kelly # Josh Boudreau # Dawson Della Valle # Ubuntu 20.04 LTS System Configuration Tweaks interpreter=$(ps -p $$ | awk '$1 != "PID" {print $(NF)}' | tr -d '()') if [ "$interpreter" != "bash" ]; then echo "Please run with bash. (\`./ubuntu-preconfig.sh\` or \`bash ubuntu-preconfig.sh\`)" echo "Current interpreter: $interpreter" exit 1 fi euid=$(id -u) if [[ "$euid" != 0 ]]; then echo "Please run as root or with sudo." exit 1 fi welcome() { local response cat < /etc/ssh/sshd_config.d/45drives.conf <> $HOME/.ssh/known_hosts echo "Enter password to test root login to localhost:" ssh root@localhost exit res=$? if [[ $res != 0 ]]; then echo "Root ssh login failed!" exit $res fi echo "Successfully enabled ssh login." return 0 } update_system() { local res ## Update system # Install 45drives repository echo "UPDATING SYSTEM" echo "Downloading 45Drives Repo Setup Script" curl -sSL https://repo.45drives.com/setup -o setup-repo.sh res=$? if [[ $res != 0 ]]; then echo "Failed to download repo setup script! (https://repo.45drives.com/setup)" exit $res fi echo "Running 45Drives Repo Setup Script" bash setup-repo.sh res=$? if [[ $res != 0 ]]; then echo "Failed to run the setup script! (https://repo.45drives.com/setup)" exit $res fi # apt upgrade echo "Upgrading packages" apt upgrade -y res=$? if [[ $res != 0 ]]; then echo "apt upgrade failed!" exit $res fi echo "Successfully updated system." return 0 } init_network() { local res echo "SETTING UP NETWORK MANAGER" # Install network packages apt update res=$? if [[ $res != 0 ]]; then echo "apt update failed!" exit $res fi apt install -y network-manager firewalld res=$? if [[ $res != 0 ]]; then echo "Installing network manager and/or firewalld failed!" exit $res fi systemctl enable --now network-manager res=$? if [[ $res != 0 ]]; then echo "Enabling network manager failed!" exit $res fi # Disable ufw and enable firewalld systemctl enable --now firewalld res=$? if [[ $res != 0 ]]; then echo "Enabling firewalld failed!" exit $res fi ufw disable res=$? if [[ $res != 0 ]]; then echo "Disabling ufw failed!" exit $res fi echo "Successfully set up network manager." return 0 } remove_garbage() { local res echo "REMOVING CLOUD-INIT AND SNAPD" # Disable cloud-init touch /etc/cloud/cloud-init.disabled # Remove snapd apt autoremove --purge -y snapd res=$? if [[ $res != 0 ]]; then echo "Disabling snapd failed!" exit $res fi echo "Successfully removed cloud-init and snapd." return 0 } add_cockpit() { local res echo "INITIALIZING HOUSTON" # Install cockpit and cockpit related things echo "Installing dependencies" apt update res=$? if [[ $res != 0 ]]; then echo "apt update failed!" exit $res fi apt install -y cockpit cockpit-zfs-manager cockpit-benchmark cockpit-navigator cockpit-file-sharing cockpit-45drives-hardware cockpit-identities cockpit-machines cockpit-sosreport realmd tuned udisks2-lvm2 zfs-dkms samba winbind nfs-kernel-server nfs-client 45drives-tools res=$? if [[ $res != 0 ]]; then echo "Installing Houston dependencies failed!" exit $res fi # Open firewall for cockpit echo "Opening firewall for cockpit" firewall-cmd --permanent --add-service=cockpit res=$? if [[ $res != 0 ]]; then echo "Adding cockpit to firewall failed!" exit $res fi firewall-cmd --reload res=$? if [[ $res != 0 ]]; then echo "Reloading firewall failed!" exit $res fi # Install cockpit override manifests for 45ddrives-hardware and apps cat >> /usr/share/cockpit/45drives-disks/override.json <> /usr/share/cockpit/45drives-motherboard/override.json <> /usr/share/cockpit/45drives-system/override.json <> /usr/share/cockpit/apps/override.json < /etc/netplan/00-networkmanager.yaml < .ubuntu-preconfig.progress ;& 1) echo "################################################################################" enable_root_ssh echo 2 > .ubuntu-preconfig.progress ;& 2) echo "################################################################################" update_system echo 3 > .ubuntu-preconfig.progress ;& 3) echo "################################################################################" init_network echo 4 > .ubuntu-preconfig.progress ;& 4) echo "################################################################################" remove_garbage echo 5 > .ubuntu-preconfig.progress ;& 5) echo "################################################################################" add_cockpit echo 6 > .ubuntu-preconfig.progress ;& 6) echo "################################################################################" use_nm_not_systemd-networkd echo 7 > .ubuntu-preconfig.progress ;& 7) echo "################################################################################" setup_done echo 8 > .ubuntu-preconfig.progress ;; 8) echo "Setup successfully finished the previous time running this script." ;; esac exit 0